Skip to content

Commit def5b72

Browse files
committed
add github stuff
1 parent 1aebd6f commit def5b72

File tree

6 files changed

+378
-0
lines changed

6 files changed

+378
-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.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-license.md
2+
name: Check License
3+
4+
env:
5+
EXPECTED_LICENSE_FILENAME: LICENSE
6+
# SPDX identifier: https://spdx.org/licenses/
7+
EXPECTED_LICENSE_TYPE: GPL-3.0
8+
9+
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
10+
on:
11+
push:
12+
paths:
13+
- ".github/workflows/check-license.ya?ml"
14+
- ".licenses/**"
15+
- ".licensed.json"
16+
- ".licensed.ya?ml"
17+
- "Taskfile.ya?ml"
18+
- "**/.gitmodules"
19+
- "**/go.mod"
20+
- "**/go.sum"
21+
pull_request:
22+
paths:
23+
- ".github/workflows/check-license.ya?ml"
24+
- ".licenses/**"
25+
- ".licensed.json"
26+
- ".licensed.ya?ml"
27+
- "Taskfile.ya?ml"
28+
- "**/.gitmodules"
29+
- "**/go.mod"
30+
- "**/go.sum"
31+
workflow_dispatch:
32+
repository_dispatch:
33+
34+
jobs:
35+
check-license:
36+
runs-on: ubuntu-latest
37+
38+
steps:
39+
- name: Checkout repository
40+
uses: actions/checkout@v4
41+
42+
- name: Install Ruby
43+
uses: ruby/setup-ruby@v1
44+
with:
45+
ruby-version: ruby # Install latest version
46+
47+
- name: Install Task
48+
uses: arduino/setup-task@v2
49+
with:
50+
repo-token: ${{ secrets.GITHUB_TOKEN }}
51+
version: 3.x
52+
53+
- name: Install licensee
54+
run: gem install licensee
55+
56+
- name: Check license file
57+
run: |
58+
EXIT_STATUS=0
59+
# See: https://github.com/licensee/licensee
60+
LICENSEE_OUTPUT="$(licensee detect --json --confidence=100)"
61+
62+
DETECTED_LICENSE_FILE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].filename | tr --delete '\r')"
63+
echo "Detected license file: $DETECTED_LICENSE_FILE"
64+
if [ "$DETECTED_LICENSE_FILE" != "\"${EXPECTED_LICENSE_FILENAME}\"" ]; then
65+
echo "::error file=${DETECTED_LICENSE_FILE}::detected license file $DETECTED_LICENSE_FILE doesn't match expected: $EXPECTED_LICENSE_FILENAME"
66+
EXIT_STATUS=1
67+
fi
68+
69+
DETECTED_LICENSE_TYPE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].matched_license | tr --delete '\r')"
70+
echo "Detected license type: $DETECTED_LICENSE_TYPE"
71+
if [ "$DETECTED_LICENSE_TYPE" != "\"${EXPECTED_LICENSE_TYPE}\"" ]; then
72+
echo "::error file=${DETECTED_LICENSE_FILE}::detected license type $DETECTED_LICENSE_TYPE doesn't match expected \"${EXPECTED_LICENSE_TYPE}\""
73+
EXIT_STATUS=1
74+
fi
75+
76+
exit $EXIT_STATUS
77+
78+
- name: Check debian copyright file
79+
run: |
80+
task update-deb-copyright
81+
git diff --color --exit-code

.github/workflows/checks.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Test Go
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+
- name: Configure credential to download private go modules
31+
run: |
32+
echo "machine github.com login $GITHUB_USERNAME password $GITHUB_TOKEN" > ~/.netrc
33+
34+
- uses: dprint/[email protected]
35+
with:
36+
dprint-version: 0.48.0
37+
38+
- uses: golangci/golangci-lint-action@v8
39+
with:
40+
version: v2.4.0
41+
args: --timeout 300s
42+
43+
- name: Check go mod
44+
run: |
45+
go mod tidy
46+
git diff --color --exit-code
47+

.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: 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-orchestrator:
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: 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://arduino:[email protected]/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: "arn:aws:iam::257442868231:role/static-website/orchestrator"
194+
role-session-name: "GHA_to_AWS_via_OIDC_for_orchestrator"
195+
- name: Upload to S3
196+
run: |
197+
aws s3 sync dist/ s3://apt-repo.oniudra.cc/tools/

0 commit comments

Comments
 (0)