1
1
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-taskfiles.md
2
2
name : Check Taskfiles
3
3
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
5
9
on :
10
+ create :
6
11
push :
7
12
paths :
8
13
- " .github/workflows/check-taskfiles.ya?ml"
14
+ - " package.json"
15
+ - " package-lock.json"
9
16
- " **/Taskfile.ya?ml"
10
17
pull_request :
11
18
paths :
12
19
- " .github/workflows/check-taskfiles.ya?ml"
20
+ - " package.json"
21
+ - " package-lock.json"
13
22
- " **/Taskfile.ya?ml"
14
23
schedule :
15
24
# Run every Tuesday at 8 AM UTC to catch breakage resulting from changes to the JSON schema.
18
27
repository_dispatch :
19
28
20
29
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
+
21
53
validate :
22
54
name : Validate ${{ matrix.file }}
55
+ needs : run-determination
56
+ if : needs.run-determination.outputs.result == 'true'
23
57
runs-on : ubuntu-latest
24
58
25
59
strategy :
@@ -34,26 +68,31 @@ jobs:
34
68
- name : Checkout repository
35
69
uses : actions/checkout@v3
36
70
71
+ - name : Setup Node.js
72
+ uses : actions/setup-node@v3
73
+ with :
74
+ node-version : ${{ env.NODE_VERSION }}
75
+
37
76
- name : Download JSON schema for Taskfiles
38
77
id : download-schema
39
78
uses : carlosperate/download-file-action@v2
40
79
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
43
82
location : ${{ runner.temp }}/taskfile-schema
44
83
45
84
- name : Install JSON schema validator
46
- run : |
47
- sudo npm install \
48
- --global \
49
- ajv-cli \
50
- ajv-formats
85
+ run : npm install
86
+
51
87
- name : Validate ${{ matrix.file }}
52
88
run : |
53
89
# 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