Skip to content

Commit 776361a

Browse files
committed
add github stuff
1 parent 71c7fea commit 776361a

File tree

6 files changed

+346
-0
lines changed

6 files changed

+346
-0
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.github/CODEOWNERS @bcmi-labs/team_tooling
2+
* @bcmi-labs/team_tooling

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

.github/workflows/go-checks.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Go Checks
2+
3+
env:
4+
GITHUB_TOKEN: ${{ secrets.ARDUINOBOT_TOKEN }}
5+
GITHUB_USERNAME: ArduinoBot
6+
7+
on:
8+
push:
9+
branches: [main]
10+
pull_request:
11+
branches: [main]
12+
13+
# In the same branch only 1 workflow per time can run. In case we're not in the
14+
# main branch we cancel previous running workflow
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref }}
17+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
18+
19+
permissions:
20+
contents: read
21+
# Used by the buf to create a comment with a brief summary of failing tets
22+
pull-requests: write
23+
24+
jobs:
25+
run-checks:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v4
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+

.github/workflows/go-test.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: 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+
# In the same branch only 1 workflow per time can run. In case we're not in the
13+
# main branch we cancel previous running workflow
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
17+
18+
jobs:
19+
run-tests:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v3
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: go test -v --race ./...
32+

.github/workflows/release.yml

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
name: Release remoteocd
2+
3+
on:
4+
push:
5+
tags:
6+
- "*" # Trigger on all tags
7+
8+
env:
9+
GO_VERSION: "1.25.1"
10+
PROJECT_NAME: "remoteocd"
11+
GITHUB_TOKEN: ${{ secrets.ARDUINOBOT_TOKEN }}
12+
GITHUB_USERNAME: ArduinoBot
13+
14+
jobs:
15+
build:
16+
strategy:
17+
matrix:
18+
os: [linux, darwin]
19+
arch: [amd64, arm64]
20+
ext: [""]
21+
include:
22+
- os: windows
23+
arch: amd64
24+
ext: .exe
25+
- os: windows
26+
arch: arm64
27+
ext: .exe
28+
29+
runs-on: ubuntu-22.04
30+
steps:
31+
- name: Extract version
32+
shell: bash
33+
run: |
34+
TAG_NAME="${GITHUB_REF##*/}"
35+
VERSION="${TAG_NAME#remoteocd-}" # Remove 'remoteocd-' prefix
36+
echo "VERSION=${VERSION}" >> $GITHUB_ENV
37+
echo "PACKAGE_NAME=${{ env.PROJECT_NAME }}-${VERSION}-${{ matrix.os }}-${{ matrix.arch }}" >> $GITHUB_ENV
38+
echo "BINARY_NAME=${{ env.PROJECT_NAME }}${{ matrix.ext }}" >> $GITHUB_ENV
39+
env:
40+
GITHUB_REF: ${{ github.ref }}
41+
42+
- name: Checkout
43+
uses: actions/checkout@v4
44+
with:
45+
fetch-depth: 0
46+
47+
- name: Set up Go
48+
uses: actions/setup-go@v5
49+
with:
50+
go-version: ${{ env.GO_VERSION }}
51+
52+
- name: Build Binary
53+
env:
54+
GOARCH: ${{ matrix.arch }}
55+
GOOS: ${{ matrix.os }}
56+
run: |
57+
mkdir -p ./build/${{ env.PACKAGE_NAME }}
58+
go build -v -ldflags "-X 'main.Version=${{ env.VERSION }}'" \
59+
-o ../build/${{ env.PACKAGE_NAME }}/${{ env.BINARY_NAME}}\
60+
.
61+
62+
- name: Prepare Build Artifacts [windows]
63+
if: ${{ matrix.os == 'windows' }}
64+
run: |
65+
cd build \
66+
&& zip -r ./${{ env.PACKAGE_NAME }}.zip ${{ env.PACKAGE_NAME }} \
67+
&& rm -r ./${{ env.PACKAGE_NAME }}
68+
- name: Prepare Build Artifacts [!windows]
69+
if: ${{ matrix.os != 'windows' }}
70+
run: |
71+
tar -czf ./build/${{ env.PACKAGE_NAME}}.tar.gz -C ./build ${{ env.PACKAGE_NAME }}
72+
rm -r ./build/${{ env.PACKAGE_NAME }}
73+
74+
- name: Upload Artifact
75+
uses: actions/upload-artifact@v4
76+
with:
77+
name: binaries-${{ matrix.os }}-${{ matrix.arch }}
78+
path: build/
79+
80+
generate-index:
81+
needs: build
82+
runs-on: ubuntu-22.04
83+
environment: staging
84+
permissions:
85+
id-token: write
86+
contents: write
87+
steps:
88+
- name: Download Artifacts
89+
uses: actions/download-artifact@v4
90+
with:
91+
pattern: binaries-*
92+
merge-multiple: true
93+
path: dist/
94+
95+
- name: Extract version
96+
shell: bash
97+
run: |
98+
TAG_NAME="${GITHUB_REF##*/}"
99+
VERSION="${TAG_NAME#remoteocd-}" # Remove 'remoteocd-' prefix
100+
echo "VERSION=${VERSION}" >> $GITHUB_ENV
101+
env:
102+
GITHUB_REF: ${{ github.ref }}
103+
104+
- name: Generate JSON index
105+
shell: bash
106+
env:
107+
VERSION: ${{ env.VERSION }}
108+
TOOL_NAME: remoteocd
109+
BASE_URL: https://downloads.arduino.cc/tools
110+
run: |
111+
set -e
112+
113+
map_os_arch() {
114+
case "$1" in
115+
linux-amd64)
116+
echo "x86_64-linux-gnu"
117+
;;
118+
linux-arm64)
119+
echo "aarch64-linux-gnu"
120+
;;
121+
windows-amd64)
122+
echo "x86_64-mingw32"
123+
;;
124+
windows-arm64)
125+
echo "arm64-mingw32"
126+
;;
127+
darwin-amd64)
128+
echo "x86_64-apple-darwin"
129+
;;
130+
darwin-arm64)
131+
echo "arm64-apple-darwin"
132+
;;
133+
*)
134+
echo "Unknown os-arch: $os_arch"
135+
;;
136+
esac
137+
}
138+
139+
systems="[]"
140+
141+
for file in dist/*; do
142+
filename=$(basename "$file")
143+
144+
# Remove prefix and suffix to get host
145+
basename_no_prefix=${filename#"${TOOL_NAME}-${VERSION}-"}
146+
os_arch=${basename_no_prefix%.tar.gz}
147+
os_arch=${os_arch%.zip}
148+
host=$(map_os_arch "$os_arch")
149+
150+
checksum=$(sha256sum "$file" | awk '{print $1}')
151+
size=$(stat --format="%s" "$file")
152+
url="${BASE_URL}/${filename}"
153+
154+
system_entry=$(jq -n \
155+
--arg host "$host" \
156+
--arg url "$url" \
157+
--arg archiveFileName "$filename" \
158+
--arg checksum "SHA-256:$checksum" \
159+
--argjson size "$size" \
160+
'{
161+
host: $host,
162+
url: $url,
163+
archiveFileName: $archiveFileName,
164+
checksum: $checksum,
165+
size: $size
166+
}')
167+
168+
systems=$(echo "$systems" | jq --argjson entry "$system_entry" '. + [$entry]')
169+
done
170+
171+
jq -n \
172+
--arg name "$TOOL_NAME" \
173+
--arg version "$VERSION" \
174+
--argjson systems "$systems" \
175+
'{
176+
name: $name,
177+
version: $version,
178+
systems: $systems
179+
}' > tool_index.json
180+
181+
- name: Upload artifacts index
182+
uses: ncipollo/release-action@v1
183+
with:
184+
token: ${{ secrets.GITHUB_TOKEN }}
185+
draft: false
186+
prerelease: true
187+
artifacts: tool_index.json,dist/*
188+
189+
- name: Configure AWS credentials
190+
uses: aws-actions/configure-aws-credentials@v4
191+
with:
192+
aws-region: "us-east-1"
193+
role-to-assume: ${{ secrets.AWS_ROLE }}
194+
role-session-name: "GHA_to_AWS_via_OIDC_for_orchestrator"
195+
- name: Upload to S3
196+
run: |
197+
aws s3 sync dist/ s3://${{ secrets.AWS_BUCKET }}/tools/

.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/remoteocd
52+
exclusions:
53+
generated: lax
54+
paths:
55+
- third_party$
56+
- builtin$
57+
- examples$

0 commit comments

Comments
 (0)