Skip to content

Commit 492b9b5

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 27e0b6a commit 492b9b5

File tree

7 files changed

+207
-1
lines changed

7 files changed

+207
-1
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[![Check Markdown status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-markdown-task.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-markdown-task.yml)
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)
12-
12+
[![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)
1313

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

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
@@ -77,6 +78,33 @@ tasks:
7778
-regex '.*\.ya?ml' \
7879
-exec cp '{}' "{{.WORKFLOW_TEMPLATE_COPIES_PATH}}" \;
7980
81+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-workflows-task/Taskfile.yml
82+
ci:validate:
83+
desc: Validate GitHub Actions workflows against their JSON schema
84+
vars:
85+
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/github-workflow.json
86+
WORKFLOW_SCHEMA_URL: https://json.schemastore.org/github-workflow
87+
WORKFLOW_SCHEMA_PATH:
88+
sh: mktemp -t workflow-schema-XXXXXXXXXX.json
89+
WORKFLOWS_DATA_PATH: "./.github/workflows/*.{yml,yaml}"
90+
TEMPLATE_WORKFLOWS_DATA_PATH: "./workflow-templates/*.{yml,yaml}"
91+
cmds:
92+
- |
93+
wget \
94+
--quiet \
95+
--output-document="{{.WORKFLOW_SCHEMA_PATH}}" \
96+
{{.WORKFLOW_SCHEMA_URL}}
97+
- |
98+
npx ajv-cli validate \
99+
--strict=false \
100+
-s "{{.WORKFLOW_SCHEMA_PATH}}" \
101+
-d "{{.WORKFLOWS_DATA_PATH}}"
102+
- |
103+
npx ajv-cli validate \
104+
--strict=false \
105+
-s "{{.WORKFLOW_SCHEMA_PATH}}" \
106+
-d "{{.TEMPLATE_WORKFLOWS_DATA_PATH}}"
107+
80108
config:validate:
81109
desc: Validate configuration files against their JSON schema
82110
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)