Skip to content

Commit 1c1267e

Browse files
committed
Add infrastructure to validate GitHub Actions workflows
A task and GitHub Actions workflow are provided here for validating the project's GitHub Actions workflows. On every push or pull request that affects the repository's GitHub Actions workflows, and periodically, the workflow will validate them against the JSON schema.
1 parent 1c249bf commit 1c1267e

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-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
@@ -10,6 +10,7 @@
1010
[![Check Python status](https://github.com/arduino/compile-sketches/actions/workflows/check-python-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-python-task.yml)
1111
[![Check Taskfiles status](https://github.com/arduino/compile-sketches/actions/workflows/check-taskfiles.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-taskfiles.yml)
1212
[![Check ToC status](https://github.com/arduino/compile-sketches/actions/workflows/check-toc-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-toc-task.yml)
13+
[![Check Workflows status](https://github.com/arduino/compile-sketches/actions/workflows/check-workflows-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-workflows-task.yml)
1314
[![Spell Check status](https://github.com/arduino/compile-sketches/actions/workflows/spell-check-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/spell-check-task.yml)
1415
[![Sync Labels status](https://github.com/arduino/compile-sketches/actions/workflows/sync-labels-npm.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/sync-labels-npm.yml)
1516
[![Test Python status](https://github.com/arduino/compile-sketches/actions/workflows/test-python-poetry-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/test-python-poetry-task.yml)

Taskfile.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ tasks:
1111
desc: Check for problems with the project
1212
deps:
1313
- task: action:validate
14+
- task: ci:validate
1415
- task: general:check-formatting
1516
- task: general:check-spelling
1617
- task: markdown:check-links
@@ -53,6 +54,34 @@ tasks:
5354
-s "{{.ACTION_METADATA_SCHEMA_PATH}}" \
5455
-d "action.yml"
5556
57+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-workflows-task/Taskfile.yml
58+
ci:validate:
59+
desc: Validate GitHub Actions workflows against their JSON schema
60+
vars:
61+
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/github-workflow.json
62+
WORKFLOW_SCHEMA_URL: https://json.schemastore.org/github-workflow
63+
WORKFLOW_SCHEMA_PATH:
64+
sh: task utility:mktemp-file TEMPLATE="workflow-schema-XXXXXXXXXX.json"
65+
WORKFLOWS_DATA_PATH: "./.github/workflows/*.{yml,yaml}"
66+
deps:
67+
- task: npm:install-deps
68+
cmds:
69+
- |
70+
wget \
71+
--quiet \
72+
--output-document="{{.WORKFLOW_SCHEMA_PATH}}" \
73+
{{.WORKFLOW_SCHEMA_URL}}
74+
- |
75+
npx \
76+
--package=ajv-cli \
77+
--package=ajv-formats \
78+
ajv validate \
79+
--all-errors \
80+
--strict=false \
81+
-c ajv-formats \
82+
-s "{{.WORKFLOW_SCHEMA_PATH}}" \
83+
-d "{{.WORKFLOWS_DATA_PATH}}"
84+
5685
docs:generate:
5786
desc: Create all generated documentation content
5887
# This is an "umbrella" task used to call any documentation generation processes the project has.

0 commit comments

Comments
 (0)