|
1 | 1 | name: 📊 Static Checks |
2 | 2 | on: |
3 | 3 | workflow_call: |
| 4 | + outputs: |
| 5 | + changed-files: |
| 6 | + description: A list of changed files. |
| 7 | + value: ${{ jobs.static-checks.outputs.changed-files }} |
4 | 8 | workflow_dispatch: |
5 | 9 |
|
6 | 10 | jobs: |
7 | 11 | static-checks: |
8 | 12 | name: Code style, file formatting, and docs |
9 | 13 | runs-on: ubuntu-24.04 |
10 | 14 | timeout-minutes: 30 |
| 15 | + outputs: |
| 16 | + changed-files: '"${{ steps.changed-files.outputs.all_changed_files }}"' # Wrap with quotes to bookend internal quote separators. |
11 | 17 | steps: |
12 | 18 | - name: Checkout |
13 | 19 | uses: actions/checkout@v6 |
14 | 20 | 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/ |
16 | 23 |
|
17 | 24 | # This needs to happen before Python and npm execution; it must happen before any extra files are written. |
18 | 25 | - name: .gitignore checks (gitignore_check.sh) |
19 | 26 | run: | |
20 | 27 | bash ./misc/scripts/gitignore_check.sh |
21 | 28 |
|
22 | | - # Keep in sync with linux_builds.yml |
23 | 29 | - 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 |
34 | 36 |
|
35 | 37 | - name: Style checks via pre-commit |
36 | 38 | 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. |
37 | 41 | with: |
38 | 42 | extra_args: --files ${{ env.CHANGED_FILES }} |
0 commit comments