-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
41 lines (34 loc) · 1.43 KB
/
cargo-check.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
name: Build and Validate Cargo.toml and cargo.lock
on:
pull_request:
branches:
- "main"
- "develop"
- "release/*"
jobs:
check_cargo_lock:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Fetch all branches and tags
run: git fetch --prune --unshallow
- name: Get commit IDs and changed files
run: |
# Get the latest commit hash of the current branch
current_commit=$(git rev-parse HEAD)
# Get the latest commit hash of the target branch (base branch)
target_commit=$(git rev-parse ${{ github.event.pull_request.base.sha }})
# List all changed files between the current branch's latest commit and the target branch's latest commit
changed_files=$(git diff --name-only $target_commit $current_commit)
# Use grep to filter for Cargo.toml files, and if none are found, set changed_files to an empty string
if echo "$changed_files" | grep -q Cargo.toml; then
if ! echo "$changed_files" | grep -q Cargo.lock; then
echo "Cargo.toml files were changed, but Cargo.lock files were not changed."
exit 1
fi
changed_files=$(echo "$changed_files" | grep Cargo.toml)
else
echo "No changed Cargo.toml files detected in the pull request."
exit 0
fi