Skip to content

Commit 350ce1b

Browse files
Merge pull request #36 from arduino/add-check-taskfiles
Add CI workflow to validate Taskfiles
2 parents ba2a726 + fe31341 commit 350ce1b

File tree

7 files changed

+643
-5
lines changed

7 files changed

+643
-5
lines changed

.github/workflows/check-go-dependencies-task.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ jobs:
7979
uses: jonabc/setup-licensed@v1
8080
with:
8181
github_token: ${{ secrets.GITHUB_TOKEN }}
82-
version: 3.x
82+
version: 4.x
8383

8484
- name: Install Go
85-
uses: actions/setup-go@v3
85+
uses: actions/setup-go@v4
8686
with:
8787
go-version: ${{ env.GO_VERSION }}
8888

@@ -135,10 +135,10 @@ jobs:
135135
uses: jonabc/setup-licensed@v1
136136
with:
137137
github_token: ${{ secrets.GITHUB_TOKEN }}
138-
version: 3.x
138+
version: 4.x
139139

140140
- name: Install Go
141-
uses: actions/setup-go@v3
141+
uses: actions/setup-go@v4
142142
with:
143143
go-version: ${{ env.GO_VERSION }}
144144

.github/workflows/check-taskfiles.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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+
outputs:
35+
result: ${{ steps.determination.outputs.result }}
36+
steps:
37+
- name: Determine if the rest of the workflow should run
38+
id: determination
39+
run: |
40+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
41+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
42+
if [[
43+
"${{ github.event_name }}" != "create" ||
44+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
45+
]]; then
46+
# Run the other jobs.
47+
RESULT="true"
48+
else
49+
# There is no need to run the other jobs.
50+
RESULT="false"
51+
fi
52+
53+
echo "result=$RESULT" >> $GITHUB_OUTPUT
54+
55+
validate:
56+
name: Validate ${{ matrix.file }}
57+
needs: run-determination
58+
if: needs.run-determination.outputs.result == 'true'
59+
runs-on: ubuntu-latest
60+
61+
strategy:
62+
fail-fast: false
63+
64+
matrix:
65+
file:
66+
- ./**/Taskfile.yml
67+
- ./**/DistTasks.yml
68+
69+
steps:
70+
- name: Checkout repository
71+
uses: actions/checkout@v3
72+
73+
- name: Setup Node.js
74+
uses: actions/setup-node@v3
75+
with:
76+
node-version: ${{ env.NODE_VERSION }}
77+
78+
- name: Download JSON schema for Taskfiles
79+
id: download-schema
80+
uses: carlosperate/download-file-action@v2
81+
with:
82+
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/taskfile.json
83+
file-url: https://taskfile.dev/schema.json
84+
location: ${{ runner.temp }}/taskfile-schema
85+
86+
- name: Install JSON schema validator
87+
run: npm install
88+
89+
- name: Validate ${{ matrix.file }}
90+
run: |
91+
# See: https://github.com/ajv-validator/ajv-cli#readme
92+
npx \
93+
--package=ajv-cli \
94+
--package=ajv-formats \
95+
ajv validate \
96+
--all-errors \
97+
--strict=false \
98+
-c ajv-formats \
99+
-s "${{ steps.download-schema.outputs.file-path }}" \
100+
-d "${{ matrix.file }}"

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ dfu-discovery
55
*.o
66
dfu-util_*.c
77
dist/
8-
libusb.h
8+
libusb.h
9+
/node_modules/

.licensed.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# See: https://github.com/github/licensed/blob/master/docs/configuration.md
2+
sources:
3+
go: true
24

35
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-dependencies/GPL-3.0/.licensed.yml
46
allowed:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![Check License status](https://github.com/arduino/dfu-discovery/actions/workflows/check-license.yml/badge.svg)](https://github.com/arduino/dfu-discovery/actions/workflows/check-license.yml)
55
[![Check Go status](https://github.com/arduino/dfu-discovery/actions/workflows/check-go-task.yml/badge.svg)](https://github.com/arduino/dfu-discovery/actions/workflows/check-go-task.yml)
66
[![Publish Tester Build status](https://github.com/arduino/dfu-discover/actions/workflows/publish-go-tester-task.yml/badge.svg)](https://github.com/arduino/dfu-discovery/actions/workflows/publish-go-tester-task.yml)
7+
[![Check Taskfiles status](https://github.com/arduino/dfu-discovery/actions/workflows/check-taskfiles.yml/badge.svg)](https://github.com/arduino/dfu-discovery/actions/workflows/check-taskfiles.yml)
78

89
The `dfu-discovery` tool is a command line program that interacts via stdio. It accepts commands as plain ASCII strings terminated with LF `\n` and sends response as JSON.
910

0 commit comments

Comments
 (0)