Skip to content

Commit 992898d

Browse files
committed
CI: Add changed-files GitHub Action
1 parent 4a1c1c4 commit 992898d

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

.github/workflows/runner.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ jobs:
1212
if: ${{ !vars.DISABLE_GODOT_CI || github.run_attempt > 1 }}
1313
name: 📊 Static checks
1414
uses: ./.github/workflows/static_checks.yml
15+
with:
16+
event-name: ${{ github.event_name }}
1517

1618
# Second stage: Run all the builds and some of the tests.
1719

.github/workflows/static_checks.yml

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
name: 📊 Static Checks
22
on:
33
workflow_call:
4+
inputs:
5+
event-name:
6+
description: The caller's `github.event_name` value.
7+
type: string
8+
required: true
49

510
jobs:
611
static-checks:
@@ -18,20 +23,28 @@ jobs:
1823
run: |
1924
bash ./misc/scripts/gitignore_check.sh
2025
26+
- name: Get branch name
27+
id: branch-name
28+
uses: tj-actions/branch-names@v9
29+
30+
- name: Get last successful commit
31+
id: last-successful-commit
32+
uses: nrwl/nx-set-shas@v4
33+
with:
34+
main-branch-name: ${{ inputs.event-name == "pull" && steps.branch-name.outputs.current_branch || steps.branch-name.outputs.base_ref_branch }}
35+
2136
- name: Get changed files
22-
env:
23-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24-
run: |
25-
if [ "${{ github.event_name }}" == "pull_request" ]; then
26-
files=$(git diff-tree --no-commit-id --name-only -r HEAD^1..HEAD 2> /dev/null || true)
27-
elif [ "${{ github.event_name }}" == "push" -a "${{ github.event.forced }}" == "false" -a "${{ github.event.created }}" == "false" ]; then
28-
files=$(git diff-tree --no-commit-id --name-only -r ${{ github.event.before }}..${{ github.event.after }} 2> /dev/null || true)
29-
fi
30-
files=$(echo "$files" | xargs -I {} sh -c 'echo "\"./{}\""' | tr '\n' ' ')
31-
echo "CHANGED_FILES=$files" >> $GITHUB_ENV
37+
id: changed-files
38+
uses: tj-actions/changed-files@v47
39+
with:
40+
base_sha: ${{ steps.last-successful-commit.outputs.base }} # Compare against last successful commit.
41+
separator: '" "' # To account for paths with spaces, ensure our items are split by quotes internally.
42+
safe_output: false # Output passed to environment variable to avoid command injection.
3243

3344
- name: Style checks via pre-commit
3445
uses: pre-commit/action@v3.0.1
46+
env:
47+
CHANGED_FILES: '"${{ steps.changed-files.outputs.all_changed_files }}"' # Wrap with quotes to bookend internal quote separators.
3548
with:
3649
extra_args: --files ${{ env.CHANGED_FILES }}
3750

0 commit comments

Comments
 (0)