Skip to content

Commit fe31f7e

Browse files
committed
chore: add ci checks and scripts
1 parent 97aa2fd commit fe31f7e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+5006
-12
lines changed

.editorconfig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Default configuration for all files
7+
[*]
8+
end_of_line = lf
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
indent_style = space
12+
indent_size = 2
13+
14+
# Use utf-8 charset for modern languages
15+
[*.{go}]
16+
charset = utf-8
17+
18+
# Use tab indentation for Go and Makefiles
19+
[{*.go,go.*}]
20+
indent_style = tab
21+
indent_size = 4
22+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Block Merge if "do-not-merge" Label Exists
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- labeled
8+
- unlabeled
9+
- synchronize # important for when new commits are pushed
10+
11+
jobs:
12+
check-do-not-merge-label:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Check for "do-not-merge" label
16+
if: contains(github.event.pull_request.labels.*.name, 'do-not-merge')
17+
run: |
18+
echo "This Pull Request has the 'do-not-merge' label. Merging is blocked."
19+
echo "Please remove the 'do-not-merge' label to enable merging."
20+
exit 1 # This will cause the workflow to fail
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-go-dependencies-task.md
2+
name: Check Go Dependencies
3+
4+
# See: https://docs.github.com/actions/reference/workflows-and-actions/events-that-trigger-workflows
5+
on:
6+
create:
7+
push:
8+
paths:
9+
- ".github/workflows/check-go-dependencies-task.ya?ml"
10+
- ".licenses/**"
11+
- ".licensed.json"
12+
- ".licensed.ya?ml"
13+
- "Taskfile.ya?ml"
14+
- "**/.gitmodules"
15+
- "**/go.mod"
16+
- "**/go.sum"
17+
pull_request:
18+
paths:
19+
- ".github/workflows/check-go-dependencies-task.ya?ml"
20+
- ".licenses/**"
21+
- ".licensed.json"
22+
- ".licensed.ya?ml"
23+
- "Taskfile.ya?ml"
24+
- "**/.gitmodules"
25+
- "**/go.mod"
26+
- "**/go.sum"
27+
schedule:
28+
# Run periodically to catch breakage caused by external changes.
29+
- cron: "0 8 * * WED"
30+
workflow_dispatch:
31+
repository_dispatch:
32+
33+
jobs:
34+
run-determination:
35+
runs-on: ubuntu-latest
36+
permissions: {}
37+
outputs:
38+
result: ${{ steps.determination.outputs.result }}
39+
steps:
40+
- name: Determine if the rest of the workflow should run
41+
id: determination
42+
run: |
43+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
44+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
45+
if [[
46+
"${{ github.event_name }}" != "create" ||
47+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
48+
]]; then
49+
# Run the other jobs.
50+
RESULT="true"
51+
else
52+
# There is no need to run the other jobs.
53+
RESULT="false"
54+
fi
55+
56+
echo "result=$RESULT" >>$GITHUB_OUTPUT
57+
58+
check-cache:
59+
needs: run-determination
60+
if: needs.run-determination.outputs.result == 'true'
61+
runs-on: ubuntu-latest
62+
permissions:
63+
contents: read
64+
65+
steps:
66+
- name: Checkout repository
67+
uses: actions/checkout@v5
68+
with:
69+
submodules: recursive
70+
71+
# This is required to allow licensee/setup-licensed to install Licensed via Ruby gem.
72+
- name: Install Ruby
73+
uses: ruby/setup-ruby@v1
74+
with:
75+
ruby-version: ruby # Install latest version
76+
77+
- name: Install licensed
78+
uses: licensee/setup-licensed@v1.3.2
79+
with:
80+
github_token: ${{ secrets.GITHUB_TOKEN }}
81+
version: 5.x
82+
83+
- name: Install Go
84+
uses: actions/setup-go@v6
85+
with:
86+
go-version-file: go.mod
87+
88+
- name: Update dependencies license metadata cache
89+
run: |
90+
go tool \
91+
github.com/go-task/task/v3/cmd/task \
92+
--silent \
93+
general:cache-dep-licenses
94+
95+
- name: Check for outdated cache
96+
id: diff
97+
run: |
98+
git add .
99+
if
100+
! git diff \
101+
--cached \
102+
--color \
103+
--exit-code
104+
then
105+
echo
106+
echo "::error::Dependency license metadata out of sync. See: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-go-dependencies-task.md#metadata-cache"
107+
exit 1
108+
fi
109+
110+
# Some might find it convenient to have CI generate the cache rather than setting up for it locally
111+
- name: Upload cache to workflow artifact
112+
if: failure() && steps.diff.outcome == 'failure'
113+
uses: actions/upload-artifact@v4
114+
with:
115+
if-no-files-found: error
116+
include-hidden-files: true
117+
name: dep-licenses-cache
118+
path: .licenses/
119+
120+
check-deps:
121+
needs: run-determination
122+
if: needs.run-determination.outputs.result == 'true'
123+
runs-on: ubuntu-latest
124+
permissions:
125+
contents: read
126+
127+
steps:
128+
- name: Checkout repository
129+
uses: actions/checkout@v5
130+
with:
131+
submodules: recursive
132+
133+
# This is required to allow licensee/setup-licensed to install Licensed via Ruby gem.
134+
- name: Install Ruby
135+
uses: ruby/setup-ruby@v1
136+
with:
137+
ruby-version: ruby # Install latest version
138+
139+
- name: Install licensed
140+
uses: licensee/setup-licensed@v1.3.2
141+
with:
142+
github_token: ${{ secrets.GITHUB_TOKEN }}
143+
version: 5.x
144+
145+
- name: Install Go
146+
uses: actions/setup-go@v6
147+
with:
148+
go-version-file: go.mod
149+
150+
- name: Check for dependencies with unapproved licenses
151+
run: |
152+
go tool \
153+
github.com/go-task/task/v3/cmd/task \
154+
--silent \
155+
general:check-dep-licenses

.github/workflows/checks.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Run Checks
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
# In the same branch only 1 workflow per time can run. In case we're not in the
10+
# main branch we cancel previous running workflow
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
14+
15+
permissions:
16+
contents: read
17+
# Used by the buf to create a comment with a brief summary of failing tets
18+
pull-requests: write
19+
20+
jobs:
21+
run-checks:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- uses: dprint/check@v2.2
27+
with:
28+
dprint-version: 0.48.0
29+
30+
- uses: golangci/golangci-lint-action@v8
31+
with:
32+
version: v2.4.0
33+
args: --timeout 300s
34+
35+
- name: Check go mod
36+
run: |
37+
go mod tidy
38+
git diff --color --exit-code
39+
40+
- name: Install Task
41+
uses: arduino/setup-task@v2
42+
with:
43+
version: 3.x
44+
repo-token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/go-test.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Run Go Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
env:
10+
GO_VERSION: "1.25.1"
11+
12+
jobs:
13+
go-test:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v3
18+
19+
- name: Install Task
20+
uses: arduino/setup-task@v2
21+
with:
22+
version: 3.x
23+
repo-token: ${{ secrets.GITHUB_TOKEN }}
24+
25+
- name: Set up Go
26+
uses: actions/setup-go@v5
27+
with:
28+
go-version: ${{ env.GO_VERSION }}
29+
30+
- name: Run tests
31+
run: task test

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
*.exe~
44

55
build/
6+
7+
.bin/

.golangci.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
version: "2"
2+
linters:
3+
enable:
4+
- bodyclose
5+
- dogsled
6+
- goconst
7+
- gocritic
8+
- goprintffuncname
9+
- gosec
10+
- importas
11+
- misspell
12+
- nakedret
13+
- prealloc
14+
- revive
15+
- staticcheck
16+
- unconvert
17+
- unparam
18+
- gochecknoinits
19+
settings:
20+
misspell:
21+
locale: US
22+
revive:
23+
rules:
24+
- name: indent-error-flow
25+
disabled: true
26+
goconst:
27+
ignore-string-values:
28+
- ".exe"
29+
- "windows"
30+
- "linux"
31+
- "darwin"
32+
33+
exclusions:
34+
generated: lax
35+
presets:
36+
- comments
37+
- common-false-positives
38+
- legacy
39+
- std-error-handling
40+
paths:
41+
- third_party$
42+
- builtin$
43+
- examples$
44+
formatters:
45+
enable:
46+
- gofmt
47+
- goimports
48+
settings:
49+
goimports:
50+
local-prefixes:
51+
- github.com/arduino/arduino-flasher-cli
52+
exclusions:
53+
generated: lax
54+
paths:
55+
- third_party$
56+
- builtin$
57+
- examples$

0 commit comments

Comments
 (0)