Skip to content

Commit 1e57aa9

Browse files
committed
Remove home-made gha shellcheck, use actionlint
Actionlint understands the interpolation syntax, so there won't be any more false-positives for `${{ ... }}` in shell scripts embedded in GitHub Actions workflow files.
1 parent b9bbe7e commit 1e57aa9

5 files changed

Lines changed: 42 additions & 23 deletions

File tree

.github/actionlint-matcher.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"problemMatcher": [
3+
{
4+
"owner": "actionlint",
5+
"pattern": [
6+
{
7+
"regexp": "^(?:\\x1b\\[\\d+m)?(.+?)(?:\\x1b\\[\\d+m)*:(?:\\x1b\\[\\d+m)*(\\d+)(?:\\x1b\\[\\d+m)*:(?:\\x1b\\[\\d+m)*(\\d+)(?:\\x1b\\[\\d+m)*: (?:\\x1b\\[\\d+m)*(.+?)(?:\\x1b\\[\\d+m)* \\[(.+?)\\]$",
8+
"file": 1,
9+
"line": 2,
10+
"column": 3,
11+
"message": 4,
12+
"code": 5
13+
}
14+
]
15+
}
16+
]
17+
}

.github/actionlint.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
self-hosted-runner:
2+
# Labels of self-hosted runner in array of strings.
3+
labels:
4+
- ubuntu-24.04-arm-alphagov

.github/workflows/actionlint.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Actionlint
2+
on:
3+
pull_request:
4+
branches: [main]
5+
paths:
6+
- ".github/workflows/**"
7+
8+
jobs:
9+
actionlint:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
13+
- name: Check workflow files
14+
run: |
15+
echo "::add-matcher::.github/actionlint-matcher.json"
16+
bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
17+
./actionlint -color
18+
shell: bash

.github/workflows/shell-ci.yml

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,6 @@ jobs:
2222
-path "*/.terraform/*" \
2323
| xargs -L1 shellcheck
2424
25-
- name: Lint shell scripts in GitHub actions
26-
run: |
27-
# This is not the usual/best way to get the script directory.
28-
# We need to do this here because GitHub Actions writes the
29-
# content of script blocks like these to a temp directory,
30-
# which means the source code directory and the directory
31-
# in which the script reside are different
32-
script_dir="$(readlink -f "$(dirname .github)")"
33-
34-
while IFS= read -r -d '' workflow
35-
do
36-
for path in $(yq '.jobs[] | .steps[] | select(.|has("run")) | .run | "."+(path | join("."))' "${script_dir}/${workflow}");
37-
do
38-
pushd "$(mktemp -d)" >/dev/null || exit
39-
workflow_name="$(basename "${script_dir}/${workflow}")"
40-
file="${workflow_name}__${path}"
41-
touch "${file}"
42-
yq "${path}" "${script_dir}/${workflow}" > "${file}"
43-
shellcheck -s bash "${file}"
44-
popd >/dev/null || exit
45-
done
46-
done < <(find ".github/workflows" -type f \( -name "*.yml" -or -name "*.yaml" \) -print0)
47-
4825
- name: Lint shell scripts in CodeBuild build specs
4926
run: |
5027
./support/shellcheck_codebuild.sh

.github/workflows/update-provider-locks.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ jobs:
126126
EOF
127127
128128
# Remove any existing comments from this workflow
129+
#shellcheck disable=SC2016
129130
old_comment_ids=$(gh api "repos/{owner}/{repo}/issues/${{github.event.pull_request.number}}/comments" --jq 'map(select((.user.login == "github-actions[bot]") and (.body | endswith($ENV.COMMENT_MARKER + "\n")))) | .[].id')
130131
for comment_id in $old_comment_ids; do
131132
gh api -X DELETE "repos/{owner}/{repo}/issues/comments/${comment_id}"
@@ -155,6 +156,7 @@ jobs:
155156
EOF
156157
157158
# Remove any existing comments from this workflow
159+
#shellcheck disable=SC2016
158160
old_comment_ids=$(gh api "repos/{owner}/{repo}/issues/${{github.event.pull_request.number}}/comments" --jq 'map(select((.user.login == "github-actions[bot]") and (.body | endswith($ENV.COMMENT_MARKER + "\n")))) | .[].id')
159161
for comment_id in $old_comment_ids; do
160162
gh api -X DELETE "repos/{owner}/{repo}/issues/comments/${comment_id}"
@@ -170,6 +172,7 @@ jobs:
170172
GH_TOKEN: ${{ github.token }}
171173
run: |
172174
# Remove any existing comments from this workflow since no changes are needed
175+
#shellcheck disable=SC2016
173176
old_comment_ids=$(gh api "repos/{owner}/{repo}/issues/${{github.event.pull_request.number}}/comments" --jq 'map(select((.user.login == "github-actions[bot]") and ((.body | endswith($ENV.COMMENT_MARKER_MISSING + "\n")) or (.body | endswith($ENV.COMMENT_MARKER_DEPENDABOT + "\n"))))) | .[].id')
174177
for comment_id in $old_comment_ids; do
175178
echo "Removing stale comment: $comment_id"

0 commit comments

Comments
 (0)