Skip to content

Commit 9f14e5a

Browse files
committed
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 744868a commit 9f14e5a

File tree

7 files changed

+207
-0
lines changed

7 files changed

+207
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/master/workflow-templates/check-workflows-task.md
2+
name: Check Workflows
3+
4+
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
5+
on:
6+
push:
7+
paths:
8+
- ".github/workflows/*.ya?ml"
9+
- "Taskfile.ya?ml"
10+
- "workflow-templates/*.ya?ml"
11+
pull_request:
12+
paths:
13+
- ".github/workflows/*.ya?ml"
14+
- "Taskfile.ya?ml"
15+
- "workflow-templates/*.ya?ml"
16+
schedule:
17+
# Run every Tuesday at 8 AM UTC to catch breakage resulting from changes to the JSON schema.
18+
- cron: "0 8 * * TUE"
19+
workflow_dispatch:
20+
repository_dispatch:
21+
22+
jobs:
23+
validate:
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v2
29+
30+
- name: Install Task
31+
uses: arduino/setup-task@v1
32+
with:
33+
repo-token: ${{ secrets.GITHUB_TOKEN }}
34+
version: 3.x
35+
36+
- name: Validate workflows
37+
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 Prettier Formatting status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-prettier-formatting-task.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-prettier-formatting-task.yml)
1111
[![Check Taskfiles status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-taskfiles.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-taskfiles.yml)
1212
[![Check YAML status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-yaml-task.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-yaml-task.yml)
13+
[![Check Workflows status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-workflows-task.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-workflows-task.yml)
1314

1415
The [Arduino](https://www.arduino.cc/) Tooling Team's collection of reusable project infrastructure assets.
1516

Taskfile.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ tasks:
1414
desc: Check for problems with the project
1515
deps:
1616
- task: general:check-formatting
17+
- task: ci:validate
1718
- task: config:validate
1819
- task: markdown:lint
1920
- task: markdown:check-links
@@ -81,6 +82,33 @@ tasks:
8182
-regex '.*\.ya?ml' \
8283
-exec cp '{}' "{{.WORKFLOW_TEMPLATE_COPIES_PATH}}" \;
8384
85+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-workflows-task/Taskfile.yml
86+
ci:validate:
87+
desc: Validate GitHub Actions workflows against their JSON schema
88+
vars:
89+
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/github-workflow.json
90+
WORKFLOW_SCHEMA_URL: https://json.schemastore.org/github-workflow
91+
WORKFLOW_SCHEMA_PATH:
92+
sh: mktemp -t workflow-schema-XXXXXXXXXX.json
93+
WORKFLOWS_DATA_PATH: "./.github/workflows/*.{yml,yaml}"
94+
TEMPLATE_WORKFLOWS_DATA_PATH: "./workflow-templates/*.{yml,yaml}"
95+
cmds:
96+
- |
97+
wget \
98+
--quiet \
99+
--output-document="{{.WORKFLOW_SCHEMA_PATH}}" \
100+
{{.WORKFLOW_SCHEMA_URL}}
101+
- |
102+
npx ajv-cli validate \
103+
--strict=false \
104+
-s "{{.WORKFLOW_SCHEMA_PATH}}" \
105+
-d "{{.WORKFLOWS_DATA_PATH}}"
106+
- |
107+
npx ajv-cli validate \
108+
--strict=false \
109+
-s "{{.WORKFLOW_SCHEMA_PATH}}" \
110+
-d "{{.TEMPLATE_WORKFLOWS_DATA_PATH}}"
111+
84112
config:validate:
85113
desc: Validate configuration files against their JSON schema
86114
vars:
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# See: https://taskfile.dev/#/usage
2+
version: "3"
3+
4+
tasks:
5+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-workflows-task/Taskfile.yml
6+
ci:validate:
7+
desc: Validate GitHub Actions workflows against their JSON schema
8+
vars:
9+
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/github-workflow.json
10+
WORKFLOW_SCHEMA_URL: https://json.schemastore.org/github-workflow
11+
WORKFLOW_SCHEMA_PATH:
12+
sh: mktemp -t workflow-schema-XXXXXXXXXX.json
13+
WORKFLOWS_DATA_PATH: "./.github/workflows/*.{yml,yaml}"
14+
cmds:
15+
- |
16+
wget \
17+
--quiet \
18+
--output-document="{{.WORKFLOW_SCHEMA_PATH}}" \
19+
{{.WORKFLOW_SCHEMA_URL}}
20+
- |
21+
npx ajv-cli validate \
22+
--strict=false \
23+
-s "{{.WORKFLOW_SCHEMA_PATH}}" \
24+
-d "{{.WORKFLOWS_DATA_PATH}}"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# "Check Workflows" workflow (Task)
2+
3+
Workflow file: [check-workflows-task.yml](check-workflows-task.yml)
4+
5+
Validate the repository's GitHub Actions workflows against the JSON schema.
6+
7+
This is the version of the workflow for projects using the [Task](https://taskfile.dev/#/) task runner tool.
8+
9+
## Assets
10+
11+
- [`Taskfile.yml`](assets/check-workflows-task/Taskfile.yml] - workflow validation task.
12+
- Install to: repository root (or add the `ci:validate` task into the existing `Taskfile.yml`)
13+
14+
## Readme badge
15+
16+
Markdown badge:
17+
18+
```markdown
19+
[![Check Workflows status](https://github.com/REPO_OWNER/REPO_NAME/actions/workflows/check-workflows-task.yml/badge.svg)](https://github.com/REPO_OWNER/REPO_NAME/actions/workflows/check-workflows-task.yml)
20+
```
21+
22+
Replace the `REPO_OWNER` and `REPO_NAME` placeholders in the URLs with the final repository owner and name ([example](https://raw.githubusercontent.com/arduino-libraries/ArduinoIoTCloud/master/README.md)).
23+
24+
---
25+
26+
Asciidoc badge:
27+
28+
```adoc
29+
image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-workflows-task.yml/badge.svg["Check Workflows status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-workflows-task.yml"]
30+
```
31+
32+
Define the `{repository-owner}` and `{repository-name}` attributes and use them throughout the readme ([example](https://raw.githubusercontent.com/arduino-libraries/WiFiNINA/master/README.adoc)).
33+
34+
## Commit message
35+
36+
```
37+
Add CI workflow to validate GitHub Actions workflows
38+
39+
On every push or pull request that affects the repository's GitHub Actions workflows, and periodically, validate them
40+
against the JSON schema.
41+
```
42+
43+
## PR message
44+
45+
```markdown
46+
On every push or pull request that affects the repository's GitHub Actions workflows, and periodically, validate them against the JSON schema.
47+
```
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/master/workflow-templates/check-workflows-task.md
2+
name: Check Workflows
3+
4+
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
5+
on:
6+
push:
7+
paths:
8+
- ".github/workflows/*.ya?ml"
9+
- "Taskfile.ya?ml"
10+
pull_request:
11+
paths:
12+
- ".github/workflows/*.ya?ml"
13+
- "Taskfile.ya?ml"
14+
schedule:
15+
# Run every Tuesday at 8 AM UTC to catch breakage resulting from changes to the JSON schema.
16+
- cron: "0 8 * * TUE"
17+
workflow_dispatch:
18+
repository_dispatch:
19+
20+
jobs:
21+
validate:
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v2
27+
28+
- name: Install Task
29+
uses: arduino/setup-task@v1
30+
with:
31+
repo-token: ${{ secrets.GITHUB_TOKEN }}
32+
version: 3.x
33+
34+
- name: Validate workflows
35+
run: task --silent ci:validate
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/master/workflow-templates/check-workflows-task.md
2+
name: Check Workflows
3+
4+
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
5+
on:
6+
push:
7+
paths:
8+
- ".github/workflows/*.ya?ml"
9+
- "Taskfile.ya?ml"
10+
pull_request:
11+
paths:
12+
- ".github/workflows/*.ya?ml"
13+
- "Taskfile.ya?ml"
14+
schedule:
15+
# Run every Tuesday at 8 AM UTC to catch breakage resulting from changes to the JSON schema.
16+
- cron: "0 8 * * TUE"
17+
workflow_dispatch:
18+
repository_dispatch:
19+
20+
jobs:
21+
validate:
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v2
27+
28+
- name: Install Task
29+
uses: arduino/setup-task@v1
30+
with:
31+
repo-token: ${{ secrets.GITHUB_TOKEN }}
32+
version: 3.x
33+
34+
- name: Validate workflows
35+
run: task --silent ci:validate

0 commit comments

Comments
 (0)