Skip to content

Commit 02a83de

Browse files
committed
Move shell script-related workflow jobs to "Check Shell" workflow
GitHub Actions provides a paths filter feature that allows you to restrict workflow run triggers to changes to specific paths within the repository. This can greatly improve the efficiency of the CI system by avoiding running irrelevant checks. The effective use of this feature requires that the purpose of a workflow be focused on a specific type of file or project component. Since collecting related jobs into a single workflow can be the best approach both from a maintainer and contributor viewpoint, it makes sense to do this grouping based on component type rather than on category of operation, as was previously done by the "Check formatting" workflow. The "Check Shell" workflow is collects the linting and formatting checks specific to the project's Shell script files.
1 parent 31189df commit 02a83de

File tree

4 files changed

+132
-34
lines changed

4 files changed

+132
-34
lines changed

Diff for: .github/workflows/check-formatting.yml

-6
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ jobs:
3434
repo-token: ${{ secrets.GITHUB_TOKEN }}
3535
version: 3.x
3636

37-
- name: Check shell script formatting
38-
# https://github.com/mvdan/sh
39-
run: |
40-
docker run --volume "$GITHUB_WORKSPACE/libraries/spell-check":/mnt --workdir /mnt mvdan/shfmt:latest -w .
41-
git diff --color --exit-code
42-
4337
- name: Check documentation formatting
4438
run: task docs:check-formatting
4539

Diff for: .github/workflows/check-shell-task.yml

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-shell-task.md
2+
name: Check Shell Scripts
3+
4+
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
5+
on:
6+
push:
7+
paths:
8+
- ".github/workflows/check-shell-task.ya?ml"
9+
- "Taskfile.ya?ml"
10+
- "**/.editorconfig"
11+
- "**.bash"
12+
- "**.sh"
13+
pull_request:
14+
paths:
15+
- ".github/workflows/check-shell-task.ya?ml"
16+
- "Taskfile.ya?ml"
17+
- "**/.editorconfig"
18+
- "**.bash"
19+
- "**.sh"
20+
schedule:
21+
# Run every Tuesday at 8 AM UTC to catch breakage caused by tool changes.
22+
- cron: "0 8 * * TUE"
23+
workflow_dispatch:
24+
repository_dispatch:
25+
26+
jobs:
27+
lint:
28+
name: ${{ matrix.configuration.name }}
29+
runs-on: ubuntu-latest
30+
31+
env:
32+
# See: https://github.com/koalaman/shellcheck/releases/latest
33+
SHELLCHECK_RELEASE_ASSET_SUFFIX: .linux.x86_64.tar.xz
34+
35+
strategy:
36+
fail-fast: false
37+
38+
matrix:
39+
configuration:
40+
- name: Generate problem matcher output
41+
# ShellCheck's "gcc" output format is required for annotated diffs, but inferior for humans reading the log.
42+
format: gcc
43+
# The other matrix job is used to set the result, so this job is configured to always pass.
44+
continue-on-error: true
45+
- name: ShellCheck
46+
# ShellCheck's "tty" output format is most suitable for humans reading the log.
47+
format: tty
48+
continue-on-error: false
49+
50+
steps:
51+
- name: Set environment variables
52+
run: |
53+
# See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
54+
echo "INSTALL_PATH=${{ runner.temp }}/shellcheck" >> "$GITHUB_ENV"
55+
56+
- name: Checkout repository
57+
uses: actions/checkout@v2
58+
59+
- name: Install Task
60+
uses: arduino/setup-task@v1
61+
with:
62+
repo-token: ${{ secrets.GITHUB_TOKEN }}
63+
version: 3.x
64+
65+
- name: Download latest ShellCheck release binary package
66+
id: download
67+
uses: MrOctopus/[email protected]
68+
with:
69+
repository: koalaman/shellcheck
70+
excludes: prerelease, draft
71+
asset: ${{ env.SHELLCHECK_RELEASE_ASSET_SUFFIX }}
72+
target: ${{ env.INSTALL_PATH }}
73+
74+
- name: Install ShellCheck
75+
run: |
76+
cd "${{ env.INSTALL_PATH }}"
77+
tar --extract --file="${{ steps.download.outputs.name }}"
78+
EXTRACTION_FOLDER="$(basename "${{ steps.download.outputs.name }}" "${{ env.SHELLCHECK_RELEASE_ASSET_SUFFIX }}")"
79+
# Add installation to PATH:
80+
# See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#adding-a-system-path
81+
echo "${{ env.INSTALL_PATH }}/$EXTRACTION_FOLDER" >> "$GITHUB_PATH"
82+
83+
- name: Run ShellCheck
84+
uses: liskin/gh-problem-matcher-wrap@v1
85+
continue-on-error: ${{ matrix.configuration.continue-on-error }}
86+
with:
87+
linters: gcc
88+
run: task --silent shell:check SHELLCHECK_FORMAT=${{ matrix.configuration.format }}
89+
90+
formatting:
91+
runs-on: ubuntu-latest
92+
93+
steps:
94+
- name: Set environment variables
95+
run: |
96+
# See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
97+
echo "SHFMT_INSTALL_PATH=${{ runner.temp }}/shfmt" >> "$GITHUB_ENV"
98+
99+
- name: Checkout repository
100+
uses: actions/checkout@v2
101+
102+
- name: Install Task
103+
uses: arduino/setup-task@v1
104+
with:
105+
repo-token: ${{ secrets.GITHUB_TOKEN }}
106+
version: 3.x
107+
108+
- name: Download shfmt
109+
id: download
110+
uses: MrOctopus/[email protected]
111+
with:
112+
repository: mvdan/sh
113+
excludes: prerelease, draft
114+
asset: _linux_amd64
115+
target: ${{ env.SHFMT_INSTALL_PATH }}
116+
117+
- name: Install shfmt
118+
run: |
119+
# Executable permissions of release assets are lost
120+
chmod +x "${{ env.SHFMT_INSTALL_PATH }}/${{ steps.download.outputs.name }}"
121+
# Standardize binary name
122+
mv "${{ env.SHFMT_INSTALL_PATH }}/${{ steps.download.outputs.name }}" "${{ env.SHFMT_INSTALL_PATH }}/shfmt"
123+
# Add installation to PATH:
124+
# See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#adding-a-system-path
125+
echo "${{ env.SHFMT_INSTALL_PATH }}" >> "$GITHUB_PATH"
126+
127+
- name: Format shell scripts
128+
run: task --silent shell:format
129+
130+
- name: Check formatting
131+
run: git diff --color --exit-code

Diff for: .github/workflows/lint-shell.yml

-28
This file was deleted.

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
[![Docs Status](https://github.com/arduino/arduino-lint/workflows/Publish%20documentation/badge.svg)](https://github.com/arduino/arduino-lint/actions?workflow=Publish+documentation)
88
[![Codecov](https://codecov.io/gh/arduino/arduino-lint/branch/main/graph/badge.svg?token=nprqPQMbdh)](https://codecov.io/gh/arduino/arduino-lint)
99
[![Check General Formatting status](https://github.com/arduino/arduino-lint/actions/workflows/check-general-formatting-task.yml/badge.svg)](https://github.com/arduino/arduino-lint/actions/workflows/check-general-formatting-task.yml)
10+
[![Check Shell Scripts status](https://github.com/arduino/arduino-lint/actions/workflows/check-shell-task.yml/badge.svg)](https://github.com/arduino/arduino-lint/actions/workflows/check-shell-task.yml)
1011
[![Check Certificates status](https://github.com/arduino/arduino-lint/actions/workflows/check-certificates.yml/badge.svg)](https://github.com/arduino/arduino-lint/actions/workflows/check-certificates.yml)
1112

1213
**Arduino Lint** is a command line tool that checks for common problems in [Arduino](https://www.arduino.cc/) projects:

0 commit comments

Comments
 (0)