Skip to content

Commit 90a3d1a

Browse files
committed
Merge pull request #111046 from Repiteo/ci/changed-files-action
CI: Add `changed-files` GitHub Action
2 parents 634220e + 4e5ded7 commit 90a3d1a

File tree

3 files changed

+24
-28
lines changed

3 files changed

+24
-28
lines changed

.github/workflows/linux_builds.yml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
name: 🐧 Linux Builds
22
on:
33
workflow_call:
4+
inputs:
5+
changed-files:
6+
description: A list of changed files.
7+
required: true
8+
type: string
49
workflow_dispatch:
510

611
# Global Settings
@@ -115,21 +120,6 @@ jobs:
115120
uses: actions/checkout@v6
116121
with:
117122
submodules: recursive
118-
fetch-depth: 2 # 2 needed for Get changed files; no trivial way to conditionally use 1
119-
120-
# Keep in sync with static_checks.yml
121-
- name: Get changed files
122-
if: matrix.clang-tidy
123-
env:
124-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
125-
run: |
126-
if [ "${{ github.event_name }}" == "pull_request" ]; then
127-
files=$(git diff-tree --no-commit-id --name-only -r HEAD^1..HEAD 2> /dev/null || true)
128-
elif [ "${{ github.event_name }}" == "push" -a "${{ github.event.forced }}" == "false" -a "${{ github.event.created }}" == "false" ]; then
129-
files=$(git diff-tree --no-commit-id --name-only -r ${{ github.event.before }}..${{ github.event.after }} 2> /dev/null || true)
130-
fi
131-
files=$(echo "$files" | xargs -I {} sh -c 'echo "\"./{}\""' | tr '\n' ' ')
132-
echo "CHANGED_FILES=$files" >> $GITHUB_ENV
133123

134124
- name: Setup dependencies
135125
run: |
@@ -201,7 +191,7 @@ jobs:
201191
if: matrix.clang-tidy
202192
uses: pre-commit/action@v3.0.1
203193
with:
204-
extra_args: --files ${{ env.CHANGED_FILES }} --hook-stage manual clang-tidy
194+
extra_args: --files ${{ inputs.changed-files }} --hook-stage manual clang-tidy
205195

206196
- name: Compilation (godot-cpp)
207197
uses: ./.github/actions/godot-cpp-build

.github/workflows/runner.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ jobs:
2929
name: 🐧 Linux
3030
needs: static-checks
3131
uses: ./.github/workflows/linux_builds.yml
32+
with:
33+
changed-files: ${{ needs.static-checks.outputs.changed-files }}
3234

3335
macos-build:
3436
name: 🍎 macOS
Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
11
name: 📊 Static Checks
22
on:
33
workflow_call:
4+
outputs:
5+
changed-files:
6+
description: A list of changed files.
7+
value: ${{ jobs.static-checks.outputs.changed-files }}
48
workflow_dispatch:
59

610
jobs:
711
static-checks:
812
name: Code style, file formatting, and docs
913
runs-on: ubuntu-24.04
1014
timeout-minutes: 30
15+
outputs:
16+
changed-files: '"${{ steps.changed-files.outputs.all_changed_files }}"' # Wrap with quotes to bookend internal quote separators.
1117
steps:
1218
- name: Checkout
1319
uses: actions/checkout@v6
1420
with:
15-
fetch-depth: 2
21+
fetch-depth: 0 # Treeless clone. Slightly less performant than a shallow clone, but makes finding diffs instantaneous.
22+
filter: tree:0 # See: https://github.blog/open-source/git/get-up-to-speed-with-partial-clone-and-shallow-clone/
1623

1724
# This needs to happen before Python and npm execution; it must happen before any extra files are written.
1825
- name: .gitignore checks (gitignore_check.sh)
1926
run: |
2027
bash ./misc/scripts/gitignore_check.sh
2128
22-
# Keep in sync with linux_builds.yml
2329
- name: Get changed files
24-
env:
25-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26-
run: |
27-
if [ "${{ github.event_name }}" == "pull_request" ]; then
28-
files=$(git diff-tree --no-commit-id --name-only -r HEAD^1..HEAD 2> /dev/null || true)
29-
elif [ "${{ github.event_name }}" == "push" -a "${{ github.event.forced }}" == "false" -a "${{ github.event.created }}" == "false" ]; then
30-
files=$(git diff-tree --no-commit-id --name-only -r ${{ github.event.before }}..${{ github.event.after }} 2> /dev/null || true)
31-
fi
32-
files=$(echo "$files" | xargs -I {} sh -c 'echo "\"./{}\""' | tr '\n' ' ')
33-
echo "CHANGED_FILES=$files" >> $GITHUB_ENV
30+
id: changed-files
31+
uses: tj-actions/changed-files@v47
32+
with:
33+
safe_output: false # Output passed to environment variable to avoid command injection.
34+
separator: '" "' # To account for paths with spaces, ensure our items are split by quotes internally.
35+
skip_initial_fetch: true
3436

3537
- name: Style checks via pre-commit
3638
uses: pre-commit/action@v3.0.1
39+
env:
40+
CHANGED_FILES: '"${{ steps.changed-files.outputs.all_changed_files }}"' # Wrap with quotes to bookend internal quote separators.
3741
with:
3842
extra_args: --files ${{ env.CHANGED_FILES }}

0 commit comments

Comments
 (0)