Skip to content

Commit 85d23af

Browse files
Merge pull request #8 from arduino/check-workflows
Add CI workflow to validate GitHub Actions workflows
2 parents 13fe018 + da15e39 commit 85d23af

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed
+50
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

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
[![Sync Labels status](https://github.com/arduino/fwuploader-plugin-helper/actions/workflows/sync-labels.yml/badge.svg)](https://github.com/arduino/fwuploader-plugin-helper/actions/workflows/sync-labels.yml)
88
[![Check Go Dependencies status](https://github.com/arduino/fwuploader-plugin-helper/actions/workflows/check-go-dependencies-task.yml/badge.svg)](https://github.com/arduino/fwuploader-plugin-helper/actions/workflows/check-go-dependencies-task.yml)
99
[![Check Taskfiles status](https://github.com/arduino/fwuploader-plugin-helper/actions/workflows/check-taskfiles.yml/badge.svg)](https://github.com/arduino/fwuploader-plugin-helper/actions/workflows/check-taskfiles.yml)
10+
[![Check Workflows status](https://github.com/arduino/fwuploader-plugin-helper/actions/workflows/check-workflows-task.yml/badge.svg)](https://github.com/arduino/fwuploader-plugin-helper/actions/workflows/check-workflows-task.yml)
1011

1112
<!--[![Test Go status](https://github.com/arduino/fwuploader-plugin-helper/actions/workflows/test-go-task.yml/badge.svg)](https://github.com/arduino/fwuploader-plugin-helper/actions/workflows/test-go-task.yml)-->
1213
<!--[![Codecov](https://codecov.io/gh/arduino/fwuploader-plugin-helper/branch/main/graph/badge.svg)](https://codecov.io/gh/arduino/fwuploader-plugin-helper)-->

Taskfile.yml

+69
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,34 @@ vars:
1515
LDFLAGS:
1616

1717
tasks:
18+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-workflows-task/Taskfile.yml
19+
ci:validate:
20+
desc: Validate GitHub Actions workflows against their JSON schema
21+
vars:
22+
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/github-workflow.json
23+
WORKFLOW_SCHEMA_URL: https://json.schemastore.org/github-workflow
24+
WORKFLOW_SCHEMA_PATH:
25+
sh: task utility:mktemp-file TEMPLATE="workflow-schema-XXXXXXXXXX.json"
26+
WORKFLOWS_DATA_PATH: "./.github/workflows/*.{yml,yaml}"
27+
deps:
28+
- task: npm:install-deps
29+
cmds:
30+
- |
31+
wget \
32+
--quiet \
33+
--output-document="{{.WORKFLOW_SCHEMA_PATH}}" \
34+
{{.WORKFLOW_SCHEMA_URL}}
35+
- |
36+
npx \
37+
--package=ajv-cli \
38+
--package=ajv-formats \
39+
ajv validate \
40+
--all-errors \
41+
--strict=false \
42+
-c ajv-formats \
43+
-s "{{.WORKFLOW_SCHEMA_PATH}}" \
44+
-d "{{.WORKFLOWS_DATA_PATH}}"
45+
1846
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-dependencies-task/Taskfile.yml
1947
general:cache-dep-licenses:
2048
desc: Cache dependency license metadata
@@ -89,3 +117,44 @@ tasks:
89117
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
90118
cmds:
91119
- go vet {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
120+
121+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/npm-task/Taskfile.yml
122+
npm:install-deps:
123+
desc: Install dependencies managed by npm
124+
cmds:
125+
- npm install
126+
127+
# Make a temporary file named according to the passed TEMPLATE variable and print the path passed to stdout
128+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
129+
utility:mktemp-file:
130+
vars:
131+
RAW_PATH:
132+
sh: mktemp --tmpdir "{{.TEMPLATE}}"
133+
cmds:
134+
- task: utility:normalize-path
135+
vars:
136+
RAW_PATH: "{{.RAW_PATH}}"
137+
138+
# Make a temporary folder named according to the passed TEMPLATE variable and print the path passed to stdout
139+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
140+
utility:mktemp-folder:
141+
vars:
142+
RAW_PATH:
143+
sh: mktemp --directory --tmpdir "{{.TEMPLATE}}"
144+
cmds:
145+
- task: utility:normalize-path
146+
vars:
147+
RAW_PATH: "{{.RAW_PATH}}"
148+
149+
# Print a normalized version of the path passed via the RAW_PATH variable to stdout
150+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
151+
utility:normalize-path:
152+
cmds:
153+
- |
154+
if [[ "{{.OS}}" == "Windows_NT" ]] && which cygpath &>/dev/null; then
155+
# Even though the shell handles POSIX format absolute paths as expected, external applications do not.
156+
# So paths passed to such applications must first be converted to Windows format.
157+
cygpath -w "{{.RAW_PATH}}"
158+
else
159+
echo "{{.RAW_PATH}}"
160+
fi

0 commit comments

Comments
 (0)