Skip to content

Commit 1600801

Browse files
Merge pull request #37 from arduino/add-check-workflows
Add CI workflow to validate GitHub Actions workflows
2 parents 350ce1b + abf1fcf commit 1600801

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-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/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+
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
@@ -5,6 +5,7 @@
55
[![Check Go status](https://github.com/arduino/dfu-discovery/actions/workflows/check-go-task.yml/badge.svg)](https://github.com/arduino/dfu-discovery/actions/workflows/check-go-task.yml)
66
[![Publish Tester Build status](https://github.com/arduino/dfu-discover/actions/workflows/publish-go-tester-task.yml/badge.svg)](https://github.com/arduino/dfu-discovery/actions/workflows/publish-go-tester-task.yml)
77
[![Check Taskfiles status](https://github.com/arduino/dfu-discovery/actions/workflows/check-taskfiles.yml/badge.svg)](https://github.com/arduino/dfu-discovery/actions/workflows/check-taskfiles.yml)
8+
[![Check Workflows status](https://github.com/arduino/dfu-discovery/actions/workflows/check-workflows-task.yml/badge.svg)](https://github.com/arduino/dfu-discovery/actions/workflows/check-workflows-task.yml)
89

910
The `dfu-discovery` tool is a command line program that interacts via stdio. It accepts commands as plain ASCII strings terminated with LF `\n` and sends response as JSON.
1011

Taskfile.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,72 @@ tasks:
137137
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
138138
cmds:
139139
- go vet {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
140+
141+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-workflows-task/Taskfile.yml
142+
ci:validate:
143+
desc: Validate GitHub Actions workflows against their JSON schema
144+
vars:
145+
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/github-workflow.json
146+
WORKFLOW_SCHEMA_URL: https://json.schemastore.org/github-workflow
147+
WORKFLOW_SCHEMA_PATH:
148+
sh: task utility:mktemp-file TEMPLATE="workflow-schema-XXXXXXXXXX.json"
149+
WORKFLOWS_DATA_PATH: "./.github/workflows/*.{yml,yaml}"
150+
deps:
151+
- task: npm:install-deps
152+
cmds:
153+
- |
154+
wget \
155+
--quiet \
156+
--output-document="{{.WORKFLOW_SCHEMA_PATH}}" \
157+
{{.WORKFLOW_SCHEMA_URL}}
158+
- |
159+
npx \
160+
--package=ajv-cli \
161+
--package=ajv-formats \
162+
ajv validate \
163+
--all-errors \
164+
--strict=false \
165+
-c ajv-formats \
166+
-s "{{.WORKFLOW_SCHEMA_PATH}}" \
167+
-d "{{.WORKFLOWS_DATA_PATH}}"
168+
169+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/npm-task/Taskfile.yml
170+
npm:install-deps:
171+
desc: Install dependencies managed by npm
172+
cmds:
173+
- npm install
174+
175+
# Make a temporary file named according to the passed TEMPLATE variable and print the path passed to stdout
176+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
177+
utility:mktemp-file:
178+
vars:
179+
RAW_PATH:
180+
sh: mktemp --tmpdir "{{.TEMPLATE}}"
181+
cmds:
182+
- task: utility:normalize-path
183+
vars:
184+
RAW_PATH: "{{.RAW_PATH}}"
185+
186+
# Make a temporary folder named according to the passed TEMPLATE variable and print the path passed to stdout
187+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
188+
utility:mktemp-folder:
189+
vars:
190+
RAW_PATH:
191+
sh: mktemp --directory --tmpdir "{{.TEMPLATE}}"
192+
cmds:
193+
- task: utility:normalize-path
194+
vars:
195+
RAW_PATH: "{{.RAW_PATH}}"
196+
197+
# Print a normalized version of the path passed via the RAW_PATH variable to stdout
198+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
199+
utility:normalize-path:
200+
cmds:
201+
- |
202+
if [[ "{{.OS}}" == "Windows_NT" ]] && which cygpath &>/dev/null; then
203+
# Even though the shell handles POSIX format absolute paths as expected, external applications do not.
204+
# So paths passed to such applications must first be converted to Windows format.
205+
cygpath -w "{{.RAW_PATH}}"
206+
else
207+
echo "{{.RAW_PATH}}"
208+
fi

0 commit comments

Comments
 (0)