Skip to content

Commit 689c7fd

Browse files
Add workflow to release arduino-flasher-cli tool (#654)
Co-authored-by: Luca Rinaldi <lucarin@protonmail.com>
1 parent 022bbe1 commit 689c7fd

File tree

2 files changed

+165
-0
lines changed

2 files changed

+165
-0
lines changed
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
name: Release Arduino Flasher tool
2+
3+
on:
4+
push:
5+
tags:
6+
- "flasher-*" # Trigger on all tags
7+
8+
env:
9+
GO_VERSION: "1.25.0"
10+
PROJECT_NAME: "arduino-flasher"
11+
GITHUB_TOKEN: ${{ secrets.ARDUINOBOT_TOKEN }}
12+
GITHUB_USERNAME: ArduinoBot
13+
DIST_DIR: build
14+
15+
jobs:
16+
build:
17+
strategy:
18+
matrix:
19+
os: [linux, darwin, windows]
20+
arch: [amd64, arm64]
21+
exclude:
22+
- os: windows
23+
arch: arm64
24+
runs-on: ubuntu-22.04
25+
outputs:
26+
release: ${{ steps.set-version.outputs.RELEASE_NAME }}
27+
steps:
28+
- name: Extract version
29+
run: |
30+
TAG_NAME="${GITHUB_REF##*/}"
31+
VERSION="${TAG_NAME#flasher-}" # Remove 'flasher-' prefix
32+
echo "RELEASE_NAME=${{ env.PROJECT_NAME }}-${VERSION}-${{ matrix.os }}-${{ matrix.arch }}" >> $GITHUB_ENV
33+
env:
34+
GITHUB_REF: ${{ github.ref }}
35+
36+
- name: Set Windows version
37+
id: set-version
38+
run: |
39+
echo "RELEASE_NAME=${{ env.RELEASE_NAME }}" >> $GITHUB_OUTPUT
40+
if: matrix.os == 'windows'
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: Install Taskfile
53+
uses: arduino/setup-task@v2
54+
with:
55+
version: "3.x"
56+
repo-token: ${{ secrets.GITHUB_TOKEN }}
57+
58+
- name: Configure Git for private repo cloning
59+
run: |
60+
git config --global url."https://${{ env.GITHUB_USERNAME }}:${{ env.GITHUB_TOKEN }}@github.com".insteadOf "https://github.com"
61+
62+
- name: Build Binary
63+
env:
64+
GOARCH: ${{ matrix.arch }}
65+
GOOS: ${{ matrix.os }}
66+
run: |
67+
task arduino-flasher-cli:build
68+
69+
- name: Rename Windows exe
70+
working-directory: ./${{ env.DIST_DIR }}
71+
run: |
72+
mv arduino-flasher-cli arduino-flasher-cli.exe
73+
if: matrix.os == 'windows'
74+
75+
- name: Prepare Build Artifacts
76+
working-directory: ./${{ env.DIST_DIR }}
77+
run: |
78+
tar -czf ${{ env.RELEASE_NAME }}.tar.gz arduino-flasher-cli*
79+
80+
- name: Upload artifacts
81+
uses: actions/upload-artifact@v4
82+
with:
83+
name: ${{ env.PROJECT_NAME }}-${{ matrix.os }}-${{ matrix.arch }}
84+
path: |
85+
${{ env.DIST_DIR }}/${{ env.RELEASE_NAME }}.tar.gz
86+
if-no-files-found: error
87+
88+
sign-windows-executable:
89+
runs-on: windows-sign-pc
90+
needs: build
91+
92+
defaults:
93+
run:
94+
shell: bash
95+
96+
env:
97+
INSTALLER_CERT_WINDOWS_CER: "/tmp/cert.cer"
98+
# We are hardcoding the path for signtool because is not present on the windows PATH env var by default.
99+
# Keep in mind that this path could change when upgrading to a new runner version
100+
SIGNTOOL_PATH: "C:/Program Files (x86)/Windows Kits/10/bin/10.0.19041.0/x86/signtool.exe"
101+
RELEASE_NAME: ${{ needs.build.outputs.release }}
102+
103+
steps:
104+
- name: Download artifacts
105+
uses: actions/download-artifact@v5
106+
with:
107+
name: ${{ env.PROJECT_NAME }}-windows-amd64
108+
109+
- name: Save Win signing certificate to file
110+
run: echo "${{ secrets.INSTALLER_CERT_WINDOWS_CER }}" | base64 --decode > ${{ env.INSTALLER_CERT_WINDOWS_CER}}
111+
112+
- name: Extract build
113+
run: |
114+
tar -xvf ${{ env.RELEASE_NAME }}.tar.gz
115+
rm ${{ env.RELEASE_NAME }}.tar.gz
116+
117+
- name: Sign executable
118+
env:
119+
CERT_PASSWORD: ${{ secrets.INSTALLER_CERT_WINDOWS_PASSWORD }}
120+
CONTAINER_NAME: ${{ secrets.INSTALLER_CERT_WINDOWS_CONTAINER }}
121+
# https://stackoverflow.com/questions/17927895/automate-extended-validation-ev-code-signing-with-safenet-etoken
122+
run: |
123+
"${{ env.SIGNTOOL_PATH }}" sign -d "Arduino Flasher CLI" -f ${{ env.INSTALLER_CERT_WINDOWS_CER}} -csp "eToken Base Cryptographic Provider" -k "[{{${{ env.CERT_PASSWORD }}}}]=${{ env.CONTAINER_NAME }}" -fd sha256 -tr http://timestamp.digicert.com -td SHA256 -v "arduino-flasher-cli.exe"
124+
125+
- name: Prepare Build Artifacts
126+
run: |
127+
tar -czf ${{ env.RELEASE_NAME }}.tar.gz arduino-flasher-cli.exe
128+
rm arduino-flasher-cli.exe
129+
130+
- name: Upload artifacts
131+
uses: actions/upload-artifact@v4
132+
with:
133+
name: ${{ env.PROJECT_NAME }}-windows-amd64
134+
path: |
135+
${{ env.RELEASE_NAME }}.tar.gz
136+
if-no-files-found: error
137+
overwrite: true
138+
139+
# This step is needed because the self hosted runner does not delete files automatically
140+
- name: Cleanup
141+
run: rm ${{ env.RELEASE_NAME }}.tar.gz
142+
143+
create-release:
144+
runs-on: ubuntu-22.04
145+
needs: [build, sign-windows-executable]
146+
steps:
147+
- name: Checkout
148+
uses: actions/checkout@v4
149+
with:
150+
fetch-depth: 0 # fetch all history for the create changelog step to work properly
151+
152+
- name: Download artifact
153+
uses: actions/download-artifact@v5
154+
with:
155+
merge-multiple: true
156+
path: ${{ env.DIST_DIR }}
157+
158+
- name: Upload artifacts index
159+
uses: ncipollo/release-action@v1
160+
with:
161+
token: ${{ secrets.GITHUB_TOKEN }}
162+
draft: false
163+
prerelease: true
164+
artifacts: ${{ env.DIST_DIR }}/*

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
- "*" # Trigger on all tags
77
- "!remoteocd-*" # Exclude remoteocd tags
88
- "!releaser-*" # Exclude releaser tags
9+
- "!flasher-*" # Exclude flasher tags
910

1011
env:
1112
GO_VERSION: "1.25.0"

0 commit comments

Comments
 (0)