Skip to content

Commit 9a422b7

Browse files
lucarin91dido18
andauthored
chore: add ci and scripts (#1)
* chore: add ci and scripts * make dprint happy * typo * fix go.sum * add deb notice check * fixup! add deb notice check * remove codeowners for now * Update Taskfile.yml Co-authored-by: Davide <davideneri18@gmail.com> * Update Taskfile.yml Co-authored-by: Davide <davideneri18@gmail.com> * Update Taskfile.yml Co-authored-by: Davide <davideneri18@gmail.com> * apply code review suggestions * update licenses * fixup! update licenses * use task in go.mod --------- Co-authored-by: Davide <davideneri18@gmail.com>
1 parent 51d9efe commit 9a422b7

File tree

35 files changed

+2323
-9
lines changed

35 files changed

+2323
-9
lines changed

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.licenses/
2+
.git/
3+
.github/

.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+

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
### Motivation
2+
3+
<!-- Why this pull request? -->
4+
5+
### Change description
6+
7+
<!-- What does your code do? -->
8+
9+
### Additional Notes
10+
11+
<!-- Link any useful metadata: Jira task, GitHub issue, ... -->
12+
13+
### Reviewer checklist
14+
15+
- [ ] PR addresses a single concern.
16+
- [ ] PR title and description are properly filled.
17+
- [ ] Changes will be merged in `main`.
18+
- [ ] Changes are covered by tests.
19+
- [ ] Logging is meaningful in case of troubleshooting.
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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
# This is required to allow licensee/setup-licensed to install Licensed via Ruby gem.
41+
- name: Install Ruby
42+
uses: ruby/setup-ruby@v1
43+
with:
44+
ruby-version: ruby # Install latest version
45+
- name: Install licensed
46+
uses: licensee/setup-licensed@v1.3.2
47+
with:
48+
github_token: ${{ secrets.GITHUB_TOKEN }}
49+
version: 5.x
50+
51+
- name: Run deb copyright check
52+
run: |
53+
go tool task update-deb-copyright
54+
git diff --color --exit-code

.github/workflows/go-test.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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: Set up Go
20+
uses: actions/setup-go@v5
21+
with:
22+
go-version: ${{ env.GO_VERSION }}
23+
24+
- name: Run tests
25+
run: go tool task test

.github/workflows/release.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Release arduino-app
2+
3+
on:
4+
push:
5+
tags:
6+
- "*" # Trigger on all tags
7+
8+
env:
9+
GO_VERSION: "1.25.1"
10+
PROJECT_NAME: "arduino-router"
11+
GITHUB_TOKEN: ${{ secrets.ARDUINOBOT_TOKEN }}
12+
GITHUB_USERNAME: ArduinoBot
13+
14+
jobs:
15+
build:
16+
strategy:
17+
matrix:
18+
os: [ubuntu-22.04]
19+
arch: [amd64, arm64]
20+
21+
runs-on: ${{ matrix.os }}
22+
23+
steps:
24+
- name: Set env vars
25+
run: |
26+
echo "TAG_VERSION=${GITHUB_REF##*/}" >> $GITHUB_ENV
27+
echo "creating tag ${TAG_VERSION}"
28+
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0
33+
34+
- name: Set up Go
35+
uses: actions/setup-go@v5
36+
with:
37+
go-version: ${{ env.GO_VERSION }}
38+
39+
- name: Build deb
40+
run: |
41+
go tool task build-deb VERSION=${TAG_VERSION} ARCH=${{ matrix.arch }} RELEASE="true"
42+
43+
- name: Create Github Release and upload artifacts
44+
uses: ncipollo/release-action@v1
45+
with:
46+
token: ${{ secrets.GITHUB_TOKEN }}
47+
draft: false
48+
prerelease: true
49+
artifacts: build/*.tar.gz,build/*.deb
50+
allowUpdates: true

.gitignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# If you prefer the allow list template instead of the deny list, see community template:
2+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3+
#
4+
# Binaries for programs and plugins
5+
*.exe
6+
*.exe~
7+
*.dll
8+
*.so
9+
*.dylib
10+
11+
# Test binary, built with `go test -c`
12+
*.test
13+
14+
# Output of the go coverage tool, specifically when used with LiteIDE
15+
*.out
16+
.vscode
17+
18+
# Dependency directories (remove the comment below to include it)
19+
# vendor/
20+
21+
# Go workspace file
22+
go.work
23+
go.work.sum
24+
25+
# local tools directory
26+
.bin/
27+
28+
build/
29+
30+
**/.cache
31+

0 commit comments

Comments
 (0)