Skip to content

Commit 15436b2

Browse files
committed
Update taskfile validation process
1 parent fe1020d commit 15436b2

File tree

3 files changed

+587
-14
lines changed

3 files changed

+587
-14
lines changed

.github/workflows/check-taskfiles.yml

+53-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-taskfiles.md
22
name: Check Taskfiles
33

4-
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
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
59
on:
10+
create:
611
push:
712
paths:
813
- ".github/workflows/check-taskfiles.ya?ml"
14+
- "package.json"
15+
- "package-lock.json"
916
- "**/Taskfile.ya?ml"
1017
pull_request:
1118
paths:
1219
- ".github/workflows/check-taskfiles.ya?ml"
20+
- "package.json"
21+
- "package-lock.json"
1322
- "**/Taskfile.ya?ml"
1423
schedule:
1524
# Run every Tuesday at 8 AM UTC to catch breakage resulting from changes to the JSON schema.
@@ -18,8 +27,33 @@ on:
1827
repository_dispatch:
1928

2029
jobs:
30+
run-determination:
31+
runs-on: ubuntu-latest
32+
outputs:
33+
result: ${{ steps.determination.outputs.result }}
34+
steps:
35+
- name: Determine if the rest of the workflow should run
36+
id: determination
37+
run: |
38+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
39+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
40+
if [[
41+
"${{ github.event_name }}" != "create" ||
42+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
43+
]]; then
44+
# Run the other jobs.
45+
RESULT="true"
46+
else
47+
# There is no need to run the other jobs.
48+
RESULT="false"
49+
fi
50+
51+
echo "result=$RESULT" >> $GITHUB_OUTPUT
52+
2153
validate:
2254
name: Validate ${{ matrix.file }}
55+
needs: run-determination
56+
if: needs.run-determination.outputs.result == 'true'
2357
runs-on: ubuntu-latest
2458

2559
strategy:
@@ -34,26 +68,31 @@ jobs:
3468
- name: Checkout repository
3569
uses: actions/checkout@v3
3670

71+
- name: Setup Node.js
72+
uses: actions/setup-node@v3
73+
with:
74+
node-version: ${{ env.NODE_VERSION }}
75+
3776
- name: Download JSON schema for Taskfiles
3877
id: download-schema
3978
uses: carlosperate/download-file-action@v2
4079
with:
41-
# See: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/taskfile.json
42-
file-url: https://json.schemastore.org/taskfile.json
80+
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/taskfile.json
81+
file-url: https://taskfile.dev/schema.json
4382
location: ${{ runner.temp }}/taskfile-schema
4483

4584
- name: Install JSON schema validator
46-
run: |
47-
sudo npm install \
48-
--global \
49-
ajv-cli \
50-
ajv-formats
85+
run: npm install
86+
5187
- name: Validate ${{ matrix.file }}
5288
run: |
5389
# See: https://github.com/ajv-validator/ajv-cli#readme
54-
ajv validate \
55-
--all-errors \
56-
--strict=false \
57-
-c ajv-formats \
58-
-s "${{ steps.download-schema.outputs.file-path }}" \
59-
-d "${{ matrix.file }}"
90+
npx \
91+
--package=ajv-cli \
92+
--package=ajv-formats \
93+
ajv validate \
94+
--all-errors \
95+
--strict=false \
96+
-c ajv-formats \
97+
-s "${{ steps.download-schema.outputs.file-path }}" \
98+
-d "${{ matrix.file }}"

0 commit comments

Comments
 (0)