Skip to content

Commit 712c886

Browse files
authored
Add actionlint as a pre-commit hook (with shellcheck integration) (#15021)
1 parent 50739f9 commit 712c886

File tree

9 files changed

+61
-28
lines changed

9 files changed

+61
-28
lines changed

.github/actionlint.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Configuration for the actionlint tool, which we run via pre-commit
2+
# to verify the correctness of the syntax in our GitHub Actions workflows.
3+
4+
self-hosted-runner:
5+
# Various runners we use that aren't recognized out-of-the-box by actionlint:
6+
labels:
7+
- depot-ubuntu-latest-8
8+
- depot-ubuntu-22.04-16
9+
- windows-latest-xlarge

.github/workflows/build-binaries.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
args: --out dist
5454
- name: "Test sdist"
5555
run: |
56-
pip install dist/${PACKAGE_NAME}-*.tar.gz --force-reinstall
56+
pip install dist/"${PACKAGE_NAME}"-*.tar.gz --force-reinstall
5757
"${MODULE_NAME}" --help
5858
python -m "${MODULE_NAME}" --help
5959
- name: "Upload sdist"
@@ -125,7 +125,7 @@ jobs:
125125
args: --release --locked --out dist
126126
- name: "Test wheel - aarch64"
127127
run: |
128-
pip install dist/${PACKAGE_NAME}-*.whl --force-reinstall
128+
pip install dist/"${PACKAGE_NAME}"-*.whl --force-reinstall
129129
ruff --help
130130
python -m ruff --help
131131
- name: "Upload wheels"
@@ -186,7 +186,7 @@ jobs:
186186
if: ${{ !startsWith(matrix.platform.target, 'aarch64') }}
187187
shell: bash
188188
run: |
189-
python -m pip install dist/${PACKAGE_NAME}-*.whl --force-reinstall
189+
python -m pip install dist/"${PACKAGE_NAME}"-*.whl --force-reinstall
190190
"${MODULE_NAME}" --help
191191
python -m "${MODULE_NAME}" --help
192192
- name: "Upload wheels"
@@ -236,7 +236,7 @@ jobs:
236236
- name: "Test wheel"
237237
if: ${{ startsWith(matrix.target, 'x86_64') }}
238238
run: |
239-
pip install dist/${PACKAGE_NAME}-*.whl --force-reinstall
239+
pip install dist/"${PACKAGE_NAME}"-*.whl --force-reinstall
240240
"${MODULE_NAME}" --help
241241
python -m "${MODULE_NAME}" --help
242242
- name: "Upload wheels"

.github/workflows/build-docker.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ jobs:
142142
# The printf will expand the base image with the `<RUFF_BASE_IMG>@sha256:<sha256> ...` for each sha256 in the directory
143143
# The final command becomes `docker buildx imagetools create -t tag1 -t tag2 ... <RUFF_BASE_IMG>@sha256:<sha256_1> <RUFF_BASE_IMG>@sha256:<sha256_2> ...`
144144
run: |
145+
# shellcheck disable=SC2046
145146
docker buildx imagetools create \
146147
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
147148
$(printf "${RUFF_BASE_IMG}@sha256:%s " *)
@@ -286,6 +287,8 @@ jobs:
286287
# The final command becomes `docker buildx imagetools create -t tag1 -t tag2 ... <RUFF_BASE_IMG>@sha256:<sha256_1> <RUFF_BASE_IMG>@sha256:<sha256_2> ...`
287288
run: |
288289
readarray -t lines <<< "$DOCKER_METADATA_OUTPUT_ANNOTATIONS"; annotations=(); for line in "${lines[@]}"; do annotations+=(--annotation "$line"); done
290+
291+
# shellcheck disable=SC2046
289292
docker buildx imagetools create \
290293
"${annotations[@]}" \
291294
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \

.github/workflows/ci.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ jobs:
438438
439439
ruff-ecosystem check ./ruff ${{ steps.ruff-target.outputs.download-path }}/ruff --cache ./checkouts --output-format markdown | tee ecosystem-result-check-stable
440440
441-
cat ecosystem-result-check-stable > $GITHUB_STEP_SUMMARY
441+
cat ecosystem-result-check-stable > "$GITHUB_STEP_SUMMARY"
442442
echo "### Linter (stable)" > ecosystem-result
443443
cat ecosystem-result-check-stable >> ecosystem-result
444444
echo "" >> ecosystem-result
@@ -454,7 +454,7 @@ jobs:
454454
455455
ruff-ecosystem check ./ruff ${{ steps.ruff-target.outputs.download-path }}/ruff --cache ./checkouts --output-format markdown --force-preview | tee ecosystem-result-check-preview
456456
457-
cat ecosystem-result-check-preview > $GITHUB_STEP_SUMMARY
457+
cat ecosystem-result-check-preview > "$GITHUB_STEP_SUMMARY"
458458
echo "### Linter (preview)" >> ecosystem-result
459459
cat ecosystem-result-check-preview >> ecosystem-result
460460
echo "" >> ecosystem-result
@@ -470,7 +470,7 @@ jobs:
470470
471471
ruff-ecosystem format ./ruff ${{ steps.ruff-target.outputs.download-path }}/ruff --cache ./checkouts --output-format markdown | tee ecosystem-result-format-stable
472472
473-
cat ecosystem-result-format-stable > $GITHUB_STEP_SUMMARY
473+
cat ecosystem-result-format-stable > "$GITHUB_STEP_SUMMARY"
474474
echo "### Formatter (stable)" >> ecosystem-result
475475
cat ecosystem-result-format-stable >> ecosystem-result
476476
echo "" >> ecosystem-result
@@ -486,7 +486,7 @@ jobs:
486486
487487
ruff-ecosystem format ./ruff ${{ steps.ruff-target.outputs.download-path }}/ruff --cache ./checkouts --output-format markdown --force-preview | tee ecosystem-result-format-preview
488488
489-
cat ecosystem-result-format-preview > $GITHUB_STEP_SUMMARY
489+
cat ecosystem-result-format-preview > "$GITHUB_STEP_SUMMARY"
490490
echo "### Formatter (preview)" >> ecosystem-result
491491
cat ecosystem-result-format-preview >> ecosystem-result
492492
echo "" >> ecosystem-result
@@ -570,13 +570,13 @@ jobs:
570570
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
571571
- name: "Run pre-commit"
572572
run: |
573-
echo '```console' > $GITHUB_STEP_SUMMARY
573+
echo '```console' > "$GITHUB_STEP_SUMMARY"
574574
# Enable color output for pre-commit and remove it for the summary
575575
SKIP=cargo-fmt,clippy,dev-generate-all pre-commit run --all-files --show-diff-on-failure --color=always | \
576-
tee >(sed -E 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})*)?[mGK]//g' >> $GITHUB_STEP_SUMMARY) >&1
577-
exit_code=${PIPESTATUS[0]}
578-
echo '```' >> $GITHUB_STEP_SUMMARY
579-
exit $exit_code
576+
tee >(sed -E 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})*)?[mGK]//g' >> "$GITHUB_STEP_SUMMARY") >&1
577+
exit_code="${PIPESTATUS[0]}"
578+
echo '```' >> "$GITHUB_STEP_SUMMARY"
579+
exit "$exit_code"
580580
581581
docs:
582582
name: "mkdocs"
@@ -637,7 +637,7 @@ jobs:
637637
- name: "Run checks"
638638
run: scripts/formatter_ecosystem_checks.sh
639639
- name: "Github step summary"
640-
run: cat target/formatter-ecosystem/stats.txt > $GITHUB_STEP_SUMMARY
640+
run: cat target/formatter-ecosystem/stats.txt > "$GITHUB_STEP_SUMMARY"
641641
- name: "Remove checkouts from cache"
642642
run: rm -r target/formatter-ecosystem
643643

.github/workflows/daily_fuzz.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ jobs:
4646
run: cargo build --locked
4747
- name: Fuzz
4848
run: |
49+
# shellcheck disable=SC2046
4950
(
5051
uvx \
5152
--python=3.12 \

.github/workflows/pr-comment.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
run: |
3131
if [[ -f pr-number ]]
3232
then
33-
echo "pr-number=$(<pr-number)" >> $GITHUB_OUTPUT
33+
echo "pr-number=$(<pr-number)" >> "$GITHUB_OUTPUT"
3434
fi
3535
3636
- uses: dawidd6/action-download-artifact@v7
@@ -66,9 +66,9 @@ jobs:
6666
cat pr/ecosystem/ecosystem-result >> comment.txt
6767
echo "" >> comment.txt
6868
69-
echo 'comment<<EOF' >> $GITHUB_OUTPUT
70-
cat comment.txt >> $GITHUB_OUTPUT
71-
echo 'EOF' >> $GITHUB_OUTPUT
69+
echo 'comment<<EOF' >> "$GITHUB_OUTPUT"
70+
cat comment.txt >> "$GITHUB_OUTPUT"
71+
echo 'EOF' >> "$GITHUB_OUTPUT"
7272
7373
- name: Find existing comment
7474
uses: peter-evans/find-comment@v3

.github/workflows/publish-docs.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ jobs:
4444
# Use version as display name for now
4545
display_name="$version"
4646
47-
echo "version=$version" >> $GITHUB_ENV
48-
echo "display_name=$display_name" >> $GITHUB_ENV
47+
echo "version=$version" >> "$GITHUB_ENV"
48+
echo "display_name=$display_name" >> "$GITHUB_ENV"
4949
5050
- name: "Set branch name"
5151
run: |
@@ -55,8 +55,8 @@ jobs:
5555
# characters disallowed in git branch names with hyphens
5656
branch_display_name="$(echo "${display_name}" | tr -c '[:alnum:]._' '-' | tr -s '-')"
5757
58-
echo "branch_name=update-docs-$branch_display_name-$timestamp" >> $GITHUB_ENV
59-
echo "timestamp=$timestamp" >> $GITHUB_ENV
58+
echo "branch_name=update-docs-$branch_display_name-$timestamp" >> "$GITHUB_ENV"
59+
echo "timestamp=$timestamp" >> "$GITHUB_ENV"
6060
6161
- name: "Add SSH key"
6262
if: ${{ env.MKDOCS_INSIDERS_SSH_KEY_EXISTS == 'true' }}
@@ -112,7 +112,7 @@ jobs:
112112
GITHUB_TOKEN: ${{ secrets.ASTRAL_DOCS_PAT }}
113113
run: |
114114
# set the PR title
115-
pull_request_title="Update ruff documentation for "${display_name}""
115+
pull_request_title="Update ruff documentation for ${display_name}"
116116
117117
# Delete any existing pull requests that are open for this version
118118
# by checking against pull_request_title because the new PR will
@@ -124,10 +124,12 @@ jobs:
124124
git push origin "${branch_name}"
125125
126126
# create the PR
127-
gh pr create --base main --head "${branch_name}" \
128-
--title "$pull_request_title" \
129-
--body "Automated documentation update for "${display_name}"" \
130-
--label "documentation"
127+
gh pr create \
128+
--base=main \
129+
--head="${branch_name}" \
130+
--title="${pull_request_title}" \
131+
--body="Automated documentation update for ${display_name}" \
132+
--label="documentation"
131133
132134
- name: "Merge Pull Request"
133135
if: ${{ inputs.plan != '' && !fromJson(inputs.plan).announcement_tag_is_implicit }}

.github/workflows/sync_typeshed.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
run: |
6060
cd ruff
6161
git push --force origin typeshedbot/sync-typeshed
62-
gh pr list --repo $GITHUB_REPOSITORY --head typeshedbot/sync-typeshed --json id --jq length | grep 1 && exit 0 # exit if there is existing pr
62+
gh pr list --repo "$GITHUB_REPOSITORY" --head typeshedbot/sync-typeshed --json id --jq length | grep 1 && exit 0 # exit if there is existing pr
6363
gh pr create --title "Sync vendored typeshed stubs" --body "Close and reopen this PR to trigger CI" --label "internal"
6464
6565
create-issue-on-failure:

.pre-commit-config.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,23 @@ repos:
100100
hooks:
101101
- id: check-github-workflows
102102

103+
# `actionlint` hook, for verifying correct syntax in GitHub Actions workflows.
104+
# Some additional configuration for `actionlint` can be found in `.github/actionlint.yaml`.
105+
- repo: https://github.com/rhysd/actionlint
106+
rev: v1.7.4
107+
hooks:
108+
- id: actionlint
109+
# `release.yml` is autogenerated by `dist`; issues need to be fixed there
110+
# (https://opensource.axo.dev/cargo-dist/)
111+
exclude: .github/workflows/release.yml
112+
args:
113+
- "-ignore=SC2129" # ignorable stylistic lint from shellcheck
114+
- "-ignore=SC2016" # another shellcheck lint: seems to have false positives?
115+
additional_dependencies:
116+
# actionlint has a shellcheck integration which extracts shell scripts in `run:` steps from GitHub Actions
117+
# and checks these with shellcheck. This is arguably its most useful feature,
118+
# but the integration only works if shellcheck is installed
119+
- "github.com/wasilibs/go-shellcheck/cmd/[email protected]"
120+
103121
ci:
104122
skip: [cargo-fmt, dev-generate-all]

0 commit comments

Comments
 (0)