Skip to content

Commit 834af54

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 841af8f commit 834af54

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

.github/workflows/check-workflows.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Check Workflows
2+
3+
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
4+
on:
5+
push:
6+
paths:
7+
- ".github/workflows/*.yaml"
8+
- ".github/workflows/*.yml"
9+
pull_request:
10+
paths:
11+
- ".github/workflows/*.yaml"
12+
- ".github/workflows/*.yml"
13+
schedule:
14+
# Run every Tuesday at 8 AM UTC to catch breakage resulting from changes to the JSON schema.
15+
- cron: "0 8 * * TUE"
16+
workflow_dispatch:
17+
repository_dispatch:
18+
19+
jobs:
20+
validate:
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v2
26+
27+
- name: Download JSON schema for GitHub Actions workflows
28+
id: download-schema
29+
uses: carlosperate/[email protected]
30+
with:
31+
# See: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/github-workflow.json
32+
file-url: https://json.schemastore.org/github-workflow
33+
location: ${{ runner.temp }}/github-workflow-schema
34+
file-name: github-workflow.json
35+
36+
- name: Get week number for use in cache key
37+
id: get-date
38+
run: |
39+
echo "::set-output name=week-number::$(date --utc '+%V')"
40+
41+
- name: Load dependencies cache
42+
uses: actions/cache@v2
43+
with:
44+
path: ~/.npm
45+
key: ${{ runner.os }}-node-ajv-cli-${{ steps.get-date.outputs.week-number }}
46+
restore-keys: |
47+
${{ runner.os }}-node-ajv-cli-
48+
49+
- name: Install JSON schema validator
50+
run: sudo npm install --global ajv-cli
51+
52+
- name: Validate GitHub Actions workflows
53+
run: |
54+
# See: https://github.com/ajv-validator/ajv-cli#readme
55+
ajv validate \
56+
--strict=false \
57+
-s "${{ steps.download-schema.outputs.file-path }}" \
58+
-d "./.github/workflows/*.{yml,yaml}"

0 commit comments

Comments
 (0)