Skip to content

Commit ae992c5

Browse files
Add CI workflow to validate GitHub Actions workflows (#12)
On every push or pull request that affects the repository's GitHub Actions workflows, and periodically, validate them against the JSON schema.
1 parent 0c004a9 commit ae992c5

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-workflows-task.md
2+
name: Check Workflows
3+
4+
env:
5+
# See: https://github.com/actions/setup-node/#readme
6+
NODE_VERSION: 16.x
7+
8+
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
9+
on:
10+
push:
11+
paths:
12+
- ".github/workflows/*.ya?ml"
13+
- "package.json"
14+
- "package-lock.json"
15+
- "Taskfile.ya?ml"
16+
pull_request:
17+
paths:
18+
- ".github/workflows/*.ya?ml"
19+
- "package.json"
20+
- "package-lock.json"
21+
- "Taskfile.ya?ml"
22+
schedule:
23+
# Run every Tuesday at 8 AM UTC to catch breakage resulting from changes to the JSON schema.
24+
- cron: "0 8 * * TUE"
25+
workflow_dispatch:
26+
repository_dispatch:
27+
28+
jobs:
29+
validate:
30+
runs-on: ubuntu-latest
31+
permissions:
32+
contents: read
33+
34+
steps:
35+
- name: Checkout repository
36+
uses: actions/checkout@v3
37+
38+
- name: Setup Node.js
39+
uses: actions/setup-node@v3
40+
with:
41+
node-version: ${{ env.NODE_VERSION }}
42+
43+
- name: Install Task
44+
uses: arduino/setup-task@v1
45+
with:
46+
repo-token: ${{ secrets.GITHUB_TOKEN }}
47+
version: 3.x
48+
49+
- name: Validate workflows
50+
run: task --silent ci:validate

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
[![Check Markdown status](https://github.com/arduino/uno-r4-wifi-fwuploader-plugin/actions/workflows/check-markdown-task.yml/badge.svg)](https://github.com/arduino/uno-r4-wifi-fwuploader-plugin/actions/workflows/check-markdown-task.yml)
1010
[![Check License status](https://github.com/arduino/uno-r4-wifi-fwuploader-plugin/actions/workflows/check-license.yml/badge.svg)](https://github.com/arduino/uno-r4-wifi-fwuploader-plugin/actions/workflows/check-license.yml)
1111
[![Check Taskfiles status](https://github.com/arduino/uno-r4-wifi-fwuploader-plugin/actions/workflows/check-taskfiles.yml/badge.svg)](https://github.com/arduino/uno-r4-wifi-fwuploader-plugin/actions/workflows/check-taskfiles.yml)
12+
[![Check Workflows status](https://github.com/arduino/uno-r4-wifi-fwuploader-plugin/actions/workflows/check-workflows-task.yml/badge.svg)](https://github.com/arduino/uno-r4-wifi-fwuploader-plugin/actions/workflows/check-workflows-task.yml)
1213
[![Codecov](https://codecov.io/gh/arduino/uno-r4-wifi-fwuploader-plugin/branch/main/graph/badge.svg)](https://codecov.io/gh/arduino/uno-r4-wifi-fwuploader-plugin)
1314

1415
Be sure to have `libudev-dev` installed

Taskfile.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,34 @@ tasks:
1818
- task: config:check
1919
- task: general:check-formatting
2020

21+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-workflows-task/Taskfile.yml
22+
ci:validate:
23+
desc: Validate GitHub Actions workflows against their JSON schema
24+
vars:
25+
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/github-workflow.json
26+
WORKFLOW_SCHEMA_URL: https://json.schemastore.org/github-workflow
27+
WORKFLOW_SCHEMA_PATH:
28+
sh: task utility:mktemp-file TEMPLATE="workflow-schema-XXXXXXXXXX.json"
29+
WORKFLOWS_DATA_PATH: "./.github/workflows/*.{yml,yaml}"
30+
deps:
31+
- task: npm:install-deps
32+
cmds:
33+
- |
34+
wget \
35+
--quiet \
36+
--output-document="{{.WORKFLOW_SCHEMA_PATH}}" \
37+
{{.WORKFLOW_SCHEMA_URL}}
38+
- |
39+
npx \
40+
--package=ajv-cli \
41+
--package=ajv-formats \
42+
ajv validate \
43+
--all-errors \
44+
--strict=false \
45+
-c ajv-formats \
46+
-s "{{.WORKFLOW_SCHEMA_PATH}}" \
47+
-d "{{.WORKFLOWS_DATA_PATH}}"
48+
2149
docs:generate:
2250
desc: Create all generated documentation content
2351
# This is an "umbrella" task used to call any documentation generation processes the project has.
@@ -206,6 +234,41 @@ tasks:
206234
- task: test-unit
207235
- task: go:test-integration
208236

237+
# Make a temporary file named according to the passed TEMPLATE variable and print the path passed to stdout
238+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
239+
utility:mktemp-file:
240+
vars:
241+
RAW_PATH:
242+
sh: mktemp --tmpdir "{{.TEMPLATE}}"
243+
cmds:
244+
- task: utility:normalize-path
245+
vars:
246+
RAW_PATH: "{{.RAW_PATH}}"
247+
248+
# Make a temporary folder named according to the passed TEMPLATE variable and print the path passed to stdout
249+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
250+
utility:mktemp-folder:
251+
vars:
252+
RAW_PATH:
253+
sh: mktemp --directory --tmpdir "{{.TEMPLATE}}"
254+
cmds:
255+
- task: utility:normalize-path
256+
vars:
257+
RAW_PATH: "{{.RAW_PATH}}"
258+
259+
# Print a normalized version of the path passed via the RAW_PATH variable to stdout
260+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
261+
utility:normalize-path:
262+
cmds:
263+
- |
264+
if [[ "{{.OS}}" == "Windows_NT" ]] && which cygpath &>/dev/null; then
265+
# Even though the shell handles POSIX format absolute paths as expected, external applications do not.
266+
# So paths passed to such applications must first be converted to Windows format.
267+
cygpath -w "{{.RAW_PATH}}"
268+
else
269+
echo "{{.RAW_PATH}}"
270+
fi
271+
209272
vars:
210273
PROJECT_NAME: "uno-r4-wifi-fwuploader-plugin"
211274
DIST_DIR: "dist"

0 commit comments

Comments
 (0)