Skip to content

Commit df06c8e

Browse files
authored
[skip-changelog] Updating workflows from upstream (#3167)
* Update test-go-task GH workflow * Updated check-license workflow * Updated check-prettier-formatting-task workflow
1 parent 5af5768 commit df06c8e

3 files changed

Lines changed: 153 additions & 27 deletions

File tree

.github/workflows/check-license.yml

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-license.md
22
name: Check License
33

4-
env:
5-
EXPECTED_LICENSE_FILENAME: LICENSE.txt
6-
# SPDX identifier: https://spdx.org/licenses/
7-
EXPECTED_LICENSE_TYPE: GPL-3.0
8-
9-
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
4+
# See: https://docs.github.com/actions/reference/workflows-and-actions/events-that-trigger-workflows
105
on:
6+
create:
117
push:
128
paths:
139
- ".github/workflows/check-license.ya?ml"
@@ -25,12 +21,54 @@ on:
2521
- "[lL][iI][cC][eE][nN][cCsS][eE]*"
2622
- "[oO][fF][lL]*"
2723
- "[pP][aA][tT][eE][nN][tT][sS]*"
24+
schedule:
25+
# Run periodically to catch breakage caused by external changes.
26+
- cron: "0 6 * * WED"
2827
workflow_dispatch:
2928
repository_dispatch:
3029

3130
jobs:
31+
run-determination:
32+
runs-on: ubuntu-latest
33+
permissions: {}
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+
3255
check-license:
56+
name: ${{ matrix.check-license.path }}
57+
needs: run-determination
58+
if: needs.run-determination.outputs.result == 'true'
3359
runs-on: ubuntu-latest
60+
permissions:
61+
contents: read
62+
63+
strategy:
64+
fail-fast: false
65+
66+
matrix:
67+
check-license:
68+
- path: .
69+
expected-filename: LICENSE.txt
70+
# SPDX identifier: https://spdx.org/licenses/
71+
expected-type: GPL-3.0
3472

3573
steps:
3674
- name: Checkout repository
@@ -42,25 +80,43 @@ jobs:
4280
ruby-version: ruby # Install latest version
4381

4482
- name: Install licensee
45-
run: gem install licensee
83+
run: |
84+
gem install \
85+
licensee
4686
47-
- name: Check license file
87+
- name: Check license file for ${{ matrix.check-license.path }}
4888
run: |
4989
EXIT_STATUS=0
90+
91+
# Go into folder path
92+
cd ./${{ matrix.check-license.path }}
93+
5094
# See: https://github.com/licensee/licensee
5195
LICENSEE_OUTPUT="$(licensee detect --json --confidence=100)"
5296
53-
DETECTED_LICENSE_FILE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].filename | tr --delete '\r')"
97+
DETECTED_LICENSE_FILE="$(
98+
echo "$LICENSEE_OUTPUT" \
99+
| \
100+
jq .matched_files[0].filename \
101+
| \
102+
tr --delete '\r'
103+
)"
54104
echo "Detected license file: $DETECTED_LICENSE_FILE"
55-
if [ "$DETECTED_LICENSE_FILE" != "\"${EXPECTED_LICENSE_FILENAME}\"" ]; then
56-
echo "::error file=${DETECTED_LICENSE_FILE}::detected license file $DETECTED_LICENSE_FILE doesn't match expected: $EXPECTED_LICENSE_FILENAME"
105+
if [ "$DETECTED_LICENSE_FILE" != "\"${{ matrix.check-license.expected-filename }}\"" ]; then
106+
echo "::error file=${DETECTED_LICENSE_FILE}::detected license file $DETECTED_LICENSE_FILE doesn't match expected: ${{ matrix.check-license.expected-filename }}"
57107
EXIT_STATUS=1
58108
fi
59109
60-
DETECTED_LICENSE_TYPE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].matched_license | tr --delete '\r')"
110+
DETECTED_LICENSE_TYPE="$(
111+
echo "$LICENSEE_OUTPUT" \
112+
| \
113+
jq .matched_files[0].matched_license \
114+
| \
115+
tr --delete '\r'
116+
)"
61117
echo "Detected license type: $DETECTED_LICENSE_TYPE"
62-
if [ "$DETECTED_LICENSE_TYPE" != "\"${EXPECTED_LICENSE_TYPE}\"" ]; then
63-
echo "::error file=${DETECTED_LICENSE_FILE}::detected license type $DETECTED_LICENSE_TYPE doesn't match expected \"${EXPECTED_LICENSE_TYPE}\""
118+
if [ "$DETECTED_LICENSE_TYPE" != "\"${{ matrix.check-license.expected-type }}\"" ]; then
119+
echo "::error file=${DETECTED_LICENSE_FILE}::detected license type $DETECTED_LICENSE_TYPE doesn't match expected \"${{ matrix.check-license.expected-type }}\""
64120
EXIT_STATUS=1
65121
fi
66122

.github/workflows/check-prettier-formatting-task.yml

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-prettier-formatting-task.md
22
name: Check Prettier Formatting
33

4-
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
4+
# See: https://docs.github.com/actions/reference/workflows-and-actions/events-that-trigger-workflows
55
on:
6+
create:
67
push:
78
paths:
89
- ".github/workflows/check-prettier-formatting-task.ya?ml"
10+
- ".npmrc"
11+
- "go.mod"
12+
- "go.sum"
913
- "Taskfile.ya?ml"
1014
- "**/.prettierignore"
1115
- "**/.prettierrc*"
16+
# Prettier-covered file patterns are defined by:
17+
# https://github.com/github-linguist/linguist/blob/main/lib/linguist/languages.yml
18+
#
1219
# CSS
1320
- "**.css"
1421
- "**.wxss"
@@ -88,6 +95,13 @@ on:
8895
- "**.mkdn?"
8996
- "**.ronn"
9097
- "**.workbook"
98+
# TOML
99+
- "**/Cargo.lock"
100+
- "**/Cargo.toml.orig"
101+
- "**/Gopkg.lock"
102+
- "**/Pipfile"
103+
- "**/pdm.lock"
104+
- "**.toml"
91105
# YAML
92106
- "**/.clang-format"
93107
- "**/.clang-tidy"
@@ -102,6 +116,9 @@ on:
102116
pull_request:
103117
paths:
104118
- ".github/workflows/check-prettier-formatting-task.ya?ml"
119+
- ".npmrc"
120+
- "go.mod"
121+
- "go.sum"
105122
- "Taskfile.ya?ml"
106123
- "**/.prettierignore"
107124
- "**/.prettierrc*"
@@ -184,6 +201,13 @@ on:
184201
- "**.mkdn?"
185202
- "**.ronn"
186203
- "**.workbook"
204+
# TOML
205+
- "**/Cargo.lock"
206+
- "**/Cargo.toml.orig"
207+
- "**/Gopkg.lock"
208+
- "**/Pipfile"
209+
- "**/pdm.lock"
210+
- "**.toml"
187211
# YAML
188212
- "**/.clang-format"
189213
- "**/.clang-tidy"
@@ -195,25 +219,65 @@ on:
195219
- "**.rviz"
196220
- "**.sublime-syntax"
197221
- "**.syntax"
222+
schedule:
223+
# Run periodically to catch breakage caused by external changes.
224+
- cron: "0 4 * * WED"
198225
workflow_dispatch:
199226
repository_dispatch:
200227

201228
jobs:
229+
run-determination:
230+
runs-on: ubuntu-latest
231+
permissions: {}
232+
outputs:
233+
result: ${{ steps.determination.outputs.result }}
234+
steps:
235+
- name: Determine if the rest of the workflow should run
236+
id: determination
237+
run: |
238+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
239+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
240+
if [[
241+
"${{ github.event_name }}" != "create" ||
242+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
243+
]]; then
244+
# Run the other jobs.
245+
RESULT="true"
246+
else
247+
# There is no need to run the other jobs.
248+
RESULT="false"
249+
fi
250+
251+
echo "result=$RESULT" >>$GITHUB_OUTPUT
252+
202253
check:
254+
needs: run-determination
255+
if: needs.run-determination.outputs.result == 'true'
203256
runs-on: ubuntu-latest
257+
permissions:
258+
contents: read
204259

205260
steps:
206261
- name: Checkout repository
207262
uses: actions/checkout@v6
208263

209-
- name: Install Task
210-
uses: arduino/setup-task@v2
264+
- name: Install Go
265+
uses: actions/setup-go@v6
266+
with:
267+
go-version-file: go.mod
268+
269+
- name: Setup Node.js
270+
uses: actions/setup-node@v6
211271
with:
212-
repo-token: ${{ secrets.GITHUB_TOKEN }}
213-
version: 3.x
272+
node-version-file: package.json
214273

215274
- name: Format with Prettier
216-
run: task general:format-prettier
275+
run: |
276+
go tool \
277+
github.com/go-task/task/v3/cmd/task general:format-prettier
217278
218279
- name: Check formatting
219-
run: git diff --color --exit-code
280+
run: |
281+
git diff \
282+
--color \
283+
--exit-code

.github/workflows/test-go-task.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/test-go-task.md
22
name: Test Go
33

4-
env:
5-
COVERAGE_ARTIFACT: coverage-data
6-
74
# See: https://docs.github.com/actions/reference/workflows-and-actions/events-that-trigger-workflows
85
on:
96
create:
@@ -63,6 +60,8 @@ jobs:
6360
tests-collector:
6461
runs-on: ubuntu-latest
6562
needs: run-determination
63+
permissions:
64+
contents: read
6665
if: needs.run-determination.outputs.result == 'true'
6766
outputs:
6867
tests-data: ${{ steps.collection.outputs.tests-data }}
@@ -78,8 +77,11 @@ jobs:
7877
7978
test-integration:
8079
needs: tests-collector
80+
permissions:
81+
contents: read
8182
strategy:
8283
fail-fast: false
84+
8385
matrix:
8486
operating-system:
8587
- windows-latest
@@ -114,12 +116,14 @@ jobs:
114116
uses: actions/upload-artifact@v6
115117
with:
116118
if-no-files-found: error
117-
name: ${{ env.COVERAGE_ARTIFACT }}-test-integration-${{ matrix.operating-system }}-${{ matrix.tests }}
119+
name: coverage-data-test-integration-${{ matrix.operating-system }}-${{ matrix.tests }}
118120
path: |
119121
./coverage_integration_*.txt
120122
121123
test:
122124
needs: run-determination
125+
permissions:
126+
contents: read
123127
strategy:
124128
fail-fast: false
125129
matrix:
@@ -154,7 +158,7 @@ jobs:
154158
uses: actions/upload-artifact@v6
155159
with:
156160
if-no-files-found: error
157-
name: ${{ env.COVERAGE_ARTIFACT }}-test-${{ matrix.operating-system }}
161+
name: coverage-data-test-${{ matrix.operating-system }}
158162
path: |
159163
./coverage_unit.txt
160164
@@ -163,6 +167,8 @@ jobs:
163167
needs:
164168
- test
165169
- test-integration
170+
permissions:
171+
contents: read
166172
steps:
167173
- name: Checkout repository
168174
uses: actions/checkout@v6
@@ -178,7 +184,7 @@ jobs:
178184
- name: Download coverage data artifact
179185
uses: actions/download-artifact@v7
180186
with:
181-
pattern: ${{ env.COVERAGE_ARTIFACT }}-*
187+
pattern: coverage-data-*
182188
merge-multiple: true
183189

184190
- name: Merge all code coverage artifacts

0 commit comments

Comments
 (0)