Skip to content

Commit a408f2c

Browse files
Add CI workflow to validate GitHub Actions workflows
On every push or pull request that affects the repository's GitHub Actions workflows, and periodically, validate them against the JSON schema.
1 parent e4b69b8 commit a408f2c

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/master/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+
32+
steps:
33+
- name: Checkout repository
34+
uses: actions/checkout@v3
35+
36+
- name: Setup Node.js
37+
uses: actions/setup-node@v3
38+
with:
39+
node-version: ${{ env.NODE_VERSION }}
40+
41+
- name: Install Task
42+
uses: arduino/setup-task@v1
43+
with:
44+
repo-token: ${{ secrets.GITHUB_TOKEN }}
45+
version: 3.x
46+
47+
- name: Validate workflows
48+
run: task --silent ci:validate

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![Check Markdown status](https://github.com/arduino/imgtool-packing/actions/workflows/check-markdown-task.yml/badge.svg)](https://github.com/arduino/imgtool-packing/actions/workflows/check-markdown-task.yml)
55
[![Check License status](https://github.com/arduino/imgtool-packing/actions/workflows/check-license.yml/badge.svg)](https://github.com/arduino/imgtool-packing/actions/workflows/check-license.yml)
66
[![Check Taskfiles status](https://github.com/arduino/imgtool-packing/actions/workflows/check-taskfiles.yml/badge.svg)](https://github.com/arduino/imgtool-packing/actions/workflows/check-taskfiles.yml)
7+
[![Check Workflows status](https://github.com/arduino/imgtool-packing/actions/workflows/check-workflows-task.yml/badge.svg)](https://github.com/arduino/imgtool-packing/actions/workflows/check-workflows-task.yml)
78

89
This repo does not contain the source code, but only the patches, and the release workflow
910

Taskfile.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,66 @@ tasks:
8686
desc: Install dependencies managed by npm
8787
cmds:
8888
- npm install
89+
90+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-workflows-task/Taskfile.yml
91+
ci:validate:
92+
desc: Validate GitHub Actions workflows against their JSON schema
93+
vars:
94+
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/github-workflow.json
95+
WORKFLOW_SCHEMA_URL: https://json.schemastore.org/github-workflow
96+
WORKFLOW_SCHEMA_PATH:
97+
sh: task utility:mktemp-file TEMPLATE="workflow-schema-XXXXXXXXXX.json"
98+
WORKFLOWS_DATA_PATH: "./.github/workflows/*.{yml,yaml}"
99+
deps:
100+
- task: npm:install-deps
101+
cmds:
102+
- |
103+
wget \
104+
--quiet \
105+
--output-document="{{.WORKFLOW_SCHEMA_PATH}}" \
106+
{{.WORKFLOW_SCHEMA_URL}}
107+
- |
108+
npx \
109+
--package=ajv-cli \
110+
--package=ajv-formats \
111+
ajv validate \
112+
--all-errors \
113+
--strict=false \
114+
-c ajv-formats \
115+
-s "{{.WORKFLOW_SCHEMA_PATH}}" \
116+
-d "{{.WORKFLOWS_DATA_PATH}}"
117+
118+
# Make a temporary file named according to the passed TEMPLATE variable and print the path passed to stdout
119+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
120+
utility:mktemp-file:
121+
vars:
122+
RAW_PATH:
123+
sh: mktemp --tmpdir "{{.TEMPLATE}}"
124+
cmds:
125+
- task: utility:normalize-path
126+
vars:
127+
RAW_PATH: "{{.RAW_PATH}}"
128+
129+
# Make a temporary folder named according to the passed TEMPLATE variable and print the path passed to stdout
130+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
131+
utility:mktemp-folder:
132+
vars:
133+
RAW_PATH:
134+
sh: mktemp --directory --tmpdir "{{.TEMPLATE}}"
135+
cmds:
136+
- task: utility:normalize-path
137+
vars:
138+
RAW_PATH: "{{.RAW_PATH}}"
139+
140+
# Print a normalized version of the path passed via the RAW_PATH variable to stdout
141+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
142+
utility:normalize-path:
143+
cmds:
144+
- |
145+
if [[ "{{.OS}}" == "Windows_NT" ]] && which cygpath &>/dev/null; then
146+
# Even though the shell handles POSIX format absolute paths as expected, external applications do not.
147+
# So paths passed to such applications must first be converted to Windows format.
148+
cygpath -w "{{.RAW_PATH}}"
149+
else
150+
echo "{{.RAW_PATH}}"
151+
fi

0 commit comments

Comments
 (0)