Skip to content

Commit cc5ef2a

Browse files
authored
Merge pull request #14 from per1234/check-workflows
Add CI workflow to validate GitHub Actions workflows
2 parents fb49847 + be0e877 commit cc5ef2a

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
@@ -11,6 +11,7 @@
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)
1313
[![Sync Labels status](https://github.com/arduino/tooling-project-assets/actions/workflows/sync-labels.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/sync-labels.yml)
14+
[![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)
1415

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

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