Skip to content

Commit 0c004a9

Browse files
Add CI workflow to validate Taskfiles (#11)
* Move check-markdown-task workflow into the correct directory * Add CI workflow to validate Taskfiles On every push or pull request that affects the repository's Taskfiles, and periodically, validate them against the JSON schema.
1 parent 8c08fa9 commit 0c004a9

File tree

5 files changed

+371
-0
lines changed

5 files changed

+371
-0
lines changed

.github/workflows/check-taskfiles.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-taskfiles.md
2+
name: Check Taskfiles
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+
create:
11+
push:
12+
paths:
13+
- ".github/workflows/check-taskfiles.ya?ml"
14+
- "package.json"
15+
- "package-lock.json"
16+
- "**/Taskfile.ya?ml"
17+
- "**/DistTasks.ya?ml"
18+
pull_request:
19+
paths:
20+
- ".github/workflows/check-taskfiles.ya?ml"
21+
- "package.json"
22+
- "package-lock.json"
23+
- "**/Taskfile.ya?ml"
24+
- "**/DistTasks.ya?ml"
25+
schedule:
26+
# Run every Tuesday at 8 AM UTC to catch breakage resulting from changes to the JSON schema.
27+
- cron: "0 8 * * TUE"
28+
workflow_dispatch:
29+
repository_dispatch:
30+
31+
jobs:
32+
run-determination:
33+
runs-on: ubuntu-latest
34+
permissions: {}
35+
outputs:
36+
result: ${{ steps.determination.outputs.result }}
37+
steps:
38+
- name: Determine if the rest of the workflow should run
39+
id: determination
40+
run: |
41+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
42+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
43+
if [[
44+
"${{ github.event_name }}" != "create" ||
45+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
46+
]]; then
47+
# Run the other jobs.
48+
RESULT="true"
49+
else
50+
# There is no need to run the other jobs.
51+
RESULT="false"
52+
fi
53+
54+
echo "result=$RESULT" >> $GITHUB_OUTPUT
55+
56+
validate:
57+
name: Validate ${{ matrix.file }}
58+
needs: run-determination
59+
if: needs.run-determination.outputs.result == 'true'
60+
runs-on: ubuntu-latest
61+
permissions:
62+
contents: read
63+
64+
strategy:
65+
fail-fast: false
66+
67+
matrix:
68+
file:
69+
- ./**/Taskfile.yml
70+
- ./**/DistTasks.yml
71+
72+
steps:
73+
- name: Checkout repository
74+
uses: actions/checkout@v3
75+
76+
- name: Setup Node.js
77+
uses: actions/setup-node@v3
78+
with:
79+
node-version: ${{ env.NODE_VERSION }}
80+
81+
- name: Download JSON schema for Taskfiles
82+
id: download-schema
83+
uses: carlosperate/download-file-action@v2
84+
with:
85+
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/taskfile.json
86+
file-url: https://taskfile.dev/schema.json
87+
location: ${{ runner.temp }}/taskfile-schema
88+
89+
- name: Install JSON schema validator
90+
run: npm install
91+
92+
- name: Validate ${{ matrix.file }}
93+
run: |
94+
# See: https://github.com/ajv-validator/ajv-cli#readme
95+
npx \
96+
--package=ajv-cli \
97+
--package=ajv-formats \
98+
ajv validate \
99+
--all-errors \
100+
--strict=false \
101+
-c ajv-formats \
102+
-s "${{ steps.download-schema.outputs.file-path }}" \
103+
-d "${{ matrix.file }}"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
[![Test Go status](https://github.com/arduino/uno-r4-wifi-fwuploader-plugin/actions/workflows/test-go-task.yml/badge.svg)](https://github.com/arduino/uno-r4-wifi-fwuploader-plugin/actions/workflows/test-go-task.yml)
99
[![Check Markdown status](https://github.com/arduino/uno-r4-wifi-fwuploader-plugin/actions/workflows/check-markdown-task.yml/badge.svg)](https://github.com/arduino/uno-r4-wifi-fwuploader-plugin/actions/workflows/check-markdown-task.yml)
1010
[![Check License status](https://github.com/arduino/uno-r4-wifi-fwuploader-plugin/actions/workflows/check-license.yml/badge.svg)](https://github.com/arduino/uno-r4-wifi-fwuploader-plugin/actions/workflows/check-license.yml)
11+
[![Check Taskfiles status](https://github.com/arduino/uno-r4-wifi-fwuploader-plugin/actions/workflows/check-taskfiles.yml/badge.svg)](https://github.com/arduino/uno-r4-wifi-fwuploader-plugin/actions/workflows/check-taskfiles.yml)
1112
[![Codecov](https://codecov.io/gh/arduino/uno-r4-wifi-fwuploader-plugin/branch/main/graph/badge.svg)](https://codecov.io/gh/arduino/uno-r4-wifi-fwuploader-plugin)
1213

1314
Be sure to have `libudev-dev` installed

0 commit comments

Comments
 (0)