-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Github unfortunately doesn't deal well with multiple workflows using a similar name (in this case "lint"). It is currently required in order to do fine-grained event triggers, since there's no need to run an action linter if the actions werern't changed. We now instead look at what files have changed and skip running a job if it doesn't apply.
- Loading branch information
1 parent
2727a0d
commit bf9705d
Showing
5 changed files
with
96 additions
and
85 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
name: lint | ||
on: | ||
pull_request: | ||
paths: | ||
# actionlint | ||
- ".github/workflows/*.yml" | ||
# prettier | ||
- "**.md" | ||
- "**.yml" | ||
# shellcheck & shfmt | ||
- "**.sh" | ||
|
||
jobs: | ||
# This job fetches changed files that others will use to see if they should be run or not. | ||
# If this file changes, any script should also fire. | ||
changed: | ||
runs-on: ubuntu-22.04 | ||
outputs: | ||
files: ${{ steps.all.outputs.all_changed_files }} | ||
self_changed: ${{ steps.lint.outputs.any_changed }} | ||
steps: | ||
- uses: actions/checkout@v3.0.2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Get a list of changed files | ||
id: all | ||
uses: tj-actions/changed-files@v29.0.9 | ||
- name: Check if this file is changed | ||
id: lint | ||
uses: tj-actions/changed-files@v29.0.9 | ||
with: | ||
files: ".github/workflows/lint.yml" | ||
|
||
actionlint: | ||
name: actionlint | ||
runs-on: ubuntu-22.04 | ||
needs: changed | ||
if: ${{ contains(needs.changed.outputs.files, '.github/workflows') }} | ||
steps: | ||
- uses: actions/checkout@v3.0.2 | ||
- name: Install Actionlint | ||
env: | ||
ACTIONLINT_VERSION: 1.6.18 | ||
run: | | ||
wget -q -O- "https://github.com/rhysd/actionlint/releases/download/v${ACTIONLINT_VERSION}/actionlint_${ACTIONLINT_VERSION}_linux_amd64.tar.gz" | tar -x -z -C . actionlint && \ | ||
mv actionlint /usr/local/bin | ||
- name: Run Actionlint | ||
run: | | ||
actionlint -format '{{range $err := .}}::error file={{$err.Filepath}},line={{$err.Line}},col={{$err.Column}}::{{$err.Message}}{{end}}' -ignore 'SC2016:' .github/workflows/*.yml | ||
prettier: | ||
name: prettier | ||
runs-on: ubuntu-22.04 | ||
needs: changed | ||
if: ${{ contains(needs.changed.outputs.files, '.md') || contains(needs.changed.outputs.files, '.yml') || needs.changed.outputs.self_changed }} | ||
steps: | ||
- uses: actions/checkout@v3.0.2 | ||
- uses: actions/setup-node@v3.4.1 | ||
with: | ||
node-version: 18 | ||
- name: install prettier | ||
run: npm install -g prettier | ||
- name: run prettier | ||
run: prettier -c . | ||
shellcheck: | ||
name: shellcheck | ||
runs-on: ubuntu-22.04 | ||
needs: changed | ||
if: ${{ contains(needs.changed.outputs.files, '.sh') || needs.changed.outputs.self_changed }} | ||
env: | ||
SHELLCHECK_VERSION: 0.8.0 | ||
steps: | ||
- uses: actions/checkout@v3.0.2 | ||
- name: install shellcheck | ||
run: | | ||
wget -q -O - "https://github.com/koalaman/shellcheck/releases/download/v${{ env.SHELLCHECK_VERSION }}/shellcheck-v${{ env.SHELLCHECK_VERSION }}.linux.x86_64.tar.xz" | tar -x -J --strip-components=1 -C . shellcheck-v${{ env.SHELLCHECK_VERSION }}/shellcheck && \ | ||
sudo mv shellcheck /usr/local/bin/ | ||
- name: verify shell scripts | ||
# shellcheck source path is assumed to be the "root" git directory | ||
run: shellcheck hadolint.sh lib/*.sh test/*.sh | ||
shfmt: | ||
name: shfmt | ||
runs-on: ubuntu-22.04 | ||
needs: changed | ||
if: ${{ contains(needs.changed.outputs.files, '.sh') || needs.changed.outputs.self_changed }} | ||
env: | ||
SHFMT_VERSION: 3.5.1 | ||
steps: | ||
- uses: actions/checkout@v3.0.2 | ||
- name: install shfmt | ||
run: | | ||
wget -q -O shfmt "https://github.com/mvdan/sh/releases/download/v${{ env.SHFMT_VERSION }}/shfmt_v${{ env.SHFMT_VERSION }}_linux_amd64" && \ | ||
chmod +x shfmt && \ | ||
sudo mv shfmt /usr/local/bin/ | ||
- name: lint shell scripts | ||
run: shfmt -i 2 -d hadolint.sh lib/*.sh test/*.sh |