Skip to content

Commit d04f85a

Browse files
add CI checks and task command
1 parent 4ac03c3 commit d04f85a

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

Diff for: .github/workflows/check-go-task.yml

+49
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,55 @@ jobs:
219219
- name: Check whether any tidying was needed
220220
run: git diff --color --exit-code
221221

222+
check-license-headers:
223+
name: check-license-headers (${{ matrix.module.path }})
224+
needs: run-determination
225+
if: needs.run-determination.outputs.result == 'true'
226+
runs-on: ubuntu-latest
227+
228+
strategy:
229+
fail-fast: false
230+
231+
matrix:
232+
module:
233+
- path: ./
234+
235+
steps:
236+
- name: Checkout repository
237+
uses: actions/checkout@v3
238+
239+
- name: Install Go
240+
uses: actions/setup-go@v4
241+
with:
242+
go-version: ${{ env.GO_VERSION }}
243+
244+
- name: Check license headers
245+
env:
246+
GO_MODULE_PATH: ${{ matrix.module.path }}
247+
run: |
248+
# We read the template content and we modify the variadic date to be always 2000
249+
LICENSE=$(cat ./license_header.tpl | sed "3s|.*|Copyright 2000 ARDUINO SA (http://www.arduino.cc/)|")
250+
N_LINES=$(wc -l < ./license_header.tpl)
251+
STATUS=0
252+
for file in $(
253+
find . \
254+
-type d -name 'testdata' -prune -o \
255+
-type d -name 'legacy' -prune -o \
256+
-type f ! -name '*_grpc.pb.go' \
257+
-type f ! -name 'json_easyjson.go' \
258+
-type f ! -name 'index_easyjson.go' \
259+
-regex ".*\.go$" -print
260+
); do
261+
# We read only the license header, removing all the comments symbols and changing the date to be 2000. This will
262+
# help us understand if the other part of the license are exactly the same as the template.
263+
HEADER=$(head -n$N_LINES $file | sed -r 's| [0-9]{4} | 2000 |' | sed 's|// ||; s|^//||' )
264+
if [ "$LICENSE" != "$HEADER" ]; then
265+
STATUS=1
266+
echo "$file"
267+
fi
268+
done
269+
exit $STATUS
270+
222271
# Do a simple "smoke test" build for the modules with no other form of validation
223272
build:
224273
name: build (${{ matrix.module.path }})

Diff for: Taskfile.yml

+6
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ tasks:
142142
- easyjson arduino/cores/packageindex/index.go
143143
- easyjson arduino/libraries/librariesindex/json.go
144144

145+
go:add-license-headers:
146+
desc: Check go license headers
147+
cmds:
148+
- go install github.com/google/[email protected]
149+
- addlicense -c "ARDUINO SA (http://www.arduino.cc/)" -f ./license_header.tpl *.go
150+
145151
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
146152
markdown:check-links:
147153
desc: Check for broken links

0 commit comments

Comments
 (0)