Skip to content

Commit 7d0259a

Browse files
lucarin91dido18per1234
authored
chore: add ci, scripts, and config files (#2)
* add ci and scripts * add task to go.mod * remove codeowner * update licenses config * Update .editorconfig Co-authored-by: Davide <[email protected]> * Update .editorconfig Co-authored-by: Davide <[email protected]> * Update dprint.json Co-authored-by: Davide <[email protected]> * Update dprint.json Co-authored-by: Davide <[email protected]> * Update dprint.json Co-authored-by: Davide <[email protected]> * Update Taskfile.yml Co-authored-by: Davide <[email protected]> * Update Taskfile.yml Co-authored-by: Davide <[email protected]> * Update Taskfile.yml Co-authored-by: Davide <[email protected]> * remove license version * add review license * Update .github/workflows/release.yml Co-authored-by: Davide <[email protected]> * update dprint * add license * update linter version on ci * make fmt happy * Update .github/workflows/release.yml Co-authored-by: Davide <[email protected]> * Update .licensed.yml Co-authored-by: Per Tillisch <[email protected]> * Remove reviewed dependencies from .licensed.yml * Remove obsolete dependency license files for updater * Remove hardcoded Go version and use go.mod for versioning in workflows * fixup! Remove hardcoded Go version and use go.mod for versioning in workflows * fixup! fixup! Remove hardcoded Go version and use go.mod for versioning in workflows --------- Co-authored-by: lucarin91 <[email protected]> Co-authored-by: Davide <[email protected]> Co-authored-by: Per Tillisch <[email protected]>
1 parent 394b51c commit 7d0259a

15 files changed

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

.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/[email protected]
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/[email protected]
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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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/[email protected]
27+
with:
28+
dprint-version: 0.50.2
29+
30+
- uses: golangci/golangci-lint-action@v8
31+
with:
32+
version: v2.5.0
33+
args: --timeout 300s
34+
35+
- name: Check go mod
36+
run: |
37+
go mod tidy
38+
git diff --color --exit-code

.github/workflows/go-test.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Run Go Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
go-test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v3
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v5
18+
with:
19+
go-version-file: go.mod
20+
21+
- name: Run tests
22+
run: go tool task test

.github/workflows/release.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Release releaser
2+
3+
on:
4+
push:
5+
tags:
6+
- "v[0-9]+.[0-9]+.[0-9]+*"
7+
8+
env:
9+
PROJECT_NAME: "releaser"
10+
GITHUB_TOKEN: ${{ secrets.ARDUINOBOT_TOKEN }}
11+
GITHUB_USERNAME: ArduinoBot
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Extract version
18+
shell: bash
19+
run: |
20+
VERSION="${GITHUB_REF##*/}"
21+
echo "VERSION=${VERSION}" >> $GITHUB_ENV
22+
echo "RELEASE_NAME=${{ env.PROJECT_NAME }}-${VERSION}-linux-amd64" >> $GITHUB_ENV
23+
env:
24+
GITHUB_REF: ${{ github.ref }}
25+
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0
30+
31+
- name: Set up Go
32+
uses: actions/setup-go@v5
33+
with:
34+
go-version-file: go.mod
35+
36+
- name: Build Binary
37+
env:
38+
GOARCH: ${{ matrix.arch }}
39+
GOOS: ${{ matrix.os }}
40+
run: |
41+
mkdir -p build/
42+
go build -v -ldflags "-X 'main.version=${{ env.VERSION }}'" \
43+
-o ./build/ \
44+
./cmd/${{ env.PROJECT_NAME }}
45+
46+
- name: Prepare Build Artifacts
47+
run: |
48+
tar -czf ./build/${{ env.RELEASE_NAME }}.tar.gz -C ./build ${{ env.PROJECT_NAME }}
49+
50+
- name: Upload artifacts index
51+
uses: ncipollo/release-action@v1
52+
with:
53+
token: ${{ secrets.GITHUB_TOKEN }}
54+
draft: false
55+
prerelease: true
56+
artifacts: build/${{ env.RELEASE_NAME }}.tar.gz

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.bin/
2+
3+
build/
4+
5+
# ignore macOS system files
6+
.DS_Store
7+

0 commit comments

Comments
 (0)