Skip to content

Commit 30aad33

Browse files
authored
ci(publish): use windows-latest and powershell for windows builds (#405)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 6c5bbd2 commit 30aad33

File tree

1 file changed

+86
-36
lines changed

1 file changed

+86
-36
lines changed

.github/workflows/publish.yml

Lines changed: 86 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ on:
88

99
concurrency: ${{ github.ref }}
1010

11+
env:
12+
APPLICATION_NAME: 'adder'
13+
1114
jobs:
1215
create-draft-release:
1316
runs-on: ubuntu-latest
@@ -59,10 +62,10 @@ jobs:
5962
- runner: ubuntu-latest
6063
os: linux
6164
arch: arm64
62-
- runner: ubuntu-latest
65+
- runner: windows-latest
6366
os: windows
6467
arch: amd64
65-
- runner: ubuntu-latest
68+
- runner: windows-latest
6669
os: windows
6770
arch: arm64
6871
runs-on: ${{ matrix.runner }}
@@ -75,17 +78,31 @@ jobs:
7578
id-token: write
7679
packages: write
7780
statuses: write
78-
env:
79-
APPLICATION_NAME: 'adder'
8081
steps:
81-
- run: "echo \"RELEASE_TAG=${GITHUB_REF#refs/tags/}\" >> $GITHUB_ENV"
82+
- name: Set RELEASE_TAG (Windows)
83+
if: matrix.os == 'windows'
84+
shell: pwsh
85+
run: |
86+
$tagName = $env:GITHUB_REF -replace 'refs/tags/', ''
87+
echo "RELEASE_TAG=$tagName" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
88+
- name: Set RELEASE_TAG
89+
if: matrix.os != 'windows'
90+
run: "echo \"RELEASE_TAG=${GITHUB_REF#refs/tags/}\" >> $GITHUB_ENV"
8291
- uses: actions/checkout@v4
8392
with:
8493
fetch-depth: '0'
8594
- uses: actions/setup-go@v5
8695
with:
8796
go-version: 1.23.x
97+
- name: Build binary (Windows)
98+
if: matrix.os == 'windows'
99+
shell: pwsh
100+
run: |
101+
$env:GOOS = "${{ matrix.os }}"
102+
$env:GOARCH = "${{ matrix.arch }}"
103+
make build
88104
- name: Build binary
105+
if: matrix.os != 'windows'
89106
run: GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} make build
90107

91108
# Sign Windows build
@@ -104,32 +121,45 @@ jobs:
104121
- name: Set up Cloud SDK
105122
if: ${{ startsWith(github.ref, 'refs/tags/') && matrix.os == 'windows' }}
106123
uses: 'google-github-actions/setup-gcloud@v2'
107-
- name: Sign windows binary
124+
- name: Sign binary (Windows)
108125
if: ${{ startsWith(github.ref, 'refs/tags/') && matrix.os == 'windows' }}
126+
shell: pwsh
109127
run: |
110-
echo "Downloading jsign.jar"
111-
curl -L -o jsign.jar https://github.com/ebourg/jsign/releases/download/6.0/jsign-6.0.jar
112-
echo "Verifying jsign.jar checksum"
113-
echo '05ca18d4ab7b8c2183289b5378d32860f0ea0f3bdab1f1b8cae5894fb225fa8a jsign.jar' | sha256sum -c
114-
echo "${{ secrets.CERTIFICATE_CHAIN }}" | base64 --decode > codesign-chain.pem
115-
set +x
116-
_filename=${{ env.APPLICATION_NAME }}
117-
ACCESS_TOKEN=$(gcloud auth print-access-token)
118-
echo "::add-mask::$ACCESS_TOKEN"
119-
java -jar jsign.jar \
120-
--storetype ${{ secrets.CERTIFICATE_STORE_TYPE }} \
121-
--storepass "$ACCESS_TOKEN" \
122-
--keystore ${{ secrets.CERTIFICATE_KEYSTORE }} \
123-
--alias ${{ secrets.CERTIFICATE_KEY_NAME }} \
124-
--certfile codesign-chain.pem \
125-
--tsmode RFC3161 \
126-
--tsaurl http://timestamp.globalsign.com/tsa/r6advanced1 \
127-
${_filename}
128-
unset ACCESS_TOKEN
129-
set -x
130-
echo "Signed Windows binary: ${_filename}"
131-
echo "Cleaning up certificate chain"
132-
rm -f codesign-chain.pem
128+
Write-Host "Downloading jsign.jar"
129+
Invoke-WebRequest -Uri "https://github.com/ebourg/jsign/releases/download/6.0/jsign-6.0.jar" -OutFile "jsign.jar"
130+
131+
Write-Host "Verifying jsign.jar checksum"
132+
$expectedHash = "05ca18d4ab7b8c2183289b5378d32860f0ea0f3bdab1f1b8cae5894fb225fa8a"
133+
$actualHash = (Get-FileHash -Path "jsign.jar" -Algorithm SHA256).Hash.ToLower()
134+
135+
if ($actualHash -ne $expectedHash) {
136+
Write-Error "Hash verification failed for jsign.jar"
137+
Write-Error "Expected: $expectedHash"
138+
Write-Error "Actual: $actualHash"
139+
exit 1
140+
}
141+
142+
[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String("${{ secrets.CERTIFICATE_CHAIN }}")) | Out-File -FilePath "codesign-chain.pem" -Encoding utf8
143+
144+
$filename = "${{ env.APPLICATION_NAME }}.exe"
145+
$ACCESS_TOKEN = & gcloud auth print-access-token
146+
Write-Host "::add-mask::$ACCESS_TOKEN"
147+
148+
java -jar jsign.jar `
149+
--storetype ${{ secrets.CERTIFICATE_STORE_TYPE }} `
150+
--storepass "$ACCESS_TOKEN" `
151+
--keystore ${{ secrets.CERTIFICATE_KEYSTORE }} `
152+
--alias ${{ secrets.CERTIFICATE_KEY_NAME }} `
153+
--certfile "codesign-chain.pem" `
154+
--tsmode RFC3161 `
155+
--tsaurl "http://timestamp.globalsign.com/tsa/r6advanced1" `
156+
$filename
157+
158+
$ACCESS_TOKEN = $null
159+
160+
Write-Host "Signed Windows binary: $filename"
161+
Write-Host "Cleaning up certificate chain"
162+
Remove-Item -Path "codesign-chain.pem" -Force
133163
134164
# Sign MacOS build
135165

@@ -177,15 +207,28 @@ jobs:
177207
ditto -c -k --keepParent "${{ env.APPLICATION_NAME }}.app" "notarization.zip"
178208
xcrun notarytool submit "notarization.zip" --keychain-profile "notarytool-profile" --wait
179209
xcrun stapler staple "${{ env.APPLICATION_NAME }}.app"
210+
211+
- name: Upload release asset (Windows)
212+
if: startsWith(github.ref, 'refs/tags/') && matrix.os == 'windows'
213+
shell: pwsh
214+
run: |
215+
$filename = "${{ env.APPLICATION_NAME }}-${{ env.RELEASE_TAG }}-${{ matrix.os }}-${{ matrix.arch }}.zip"
216+
Compress-Archive "${{ env.APPLICATION_NAME }}.exe" "$filename"
217+
Write-Host "Uploading file: $filename"
218+
# Upload file using PowerShell
219+
$headers = @{
220+
"Authorization" = "token ${{ secrets.GITHUB_TOKEN }}"
221+
"Content-Type" = "application/octet-stream"
222+
}
223+
$uploadUrl = "https://uploads.github.com/repos/${{ github.repository }}/releases/${{ needs.create-draft-release.outputs.RELEASE_ID }}/assets?name=$filename"
224+
Invoke-RestMethod -Uri $uploadUrl -Method Post -Headers $headers -InFile $filename
225+
180226
- name: Upload release asset
181-
if: startsWith(github.ref, 'refs/tags/')
227+
if: startsWith(github.ref, 'refs/tags/') && matrix.os != 'windows'
182228
run: |
183-
_filename=${{ env.APPLICATION_NAME }}-${{ env.RELEASE_TAG }}-${{ matrix.os }}-${{ matrix.arch }}
184-
if [[ "${{ matrix.os }}" == "windows" ]]; then
185-
_filename=${_filename}.exe
186-
fi
187-
if [[ "${{ matrix.os }}" == "windows" || "${{ matrix.os }}" == "linux" || "${{ matrix.os }}" == "freebsd" ]]; then
188-
cp ${{ env.APPLICATION_NAME }} ${_filename}
229+
_filename=${{ env.APPLICATION_NAME }}-${{ env.RELEASE_TAG }}-${{ matrix.os }}-${{ matrix.arch }}.tar.gz
230+
if [[ "${{ matrix.os }}" != "windows" ]]; then
231+
tar czf ${_filename} ${{ env.APPLICATION_NAME }}
189232
fi
190233
if [[ "${{ matrix.os }}" == "darwin" ]]; then
191234
_filename=${{ env.APPLICATION_NAME }}-${{ env.RELEASE_TAG }}-${{ matrix.os }}-${{ matrix.arch }}.zip
@@ -197,7 +240,14 @@ jobs:
197240
--data-binary @${_filename} \
198241
https://uploads.github.com/repos/${{ github.repository_owner }}/adder/releases/${{ needs.create-draft-release.outputs.RELEASE_ID }}/assets?name=${_filename}
199242
243+
- name: Attest binary (Windows)
244+
if: startsWith(github.ref, 'refs/tags/') && matrix.os == 'windows'
245+
uses: actions/attest-build-provenance@v2
246+
with:
247+
subject-path: '${{ env.APPLICATION_NAME }}.exe'
248+
200249
- name: Attest binary
250+
if: startsWith(github.ref, 'refs/tags/') && matrix.os != 'windows'
201251
uses: actions/attest-build-provenance@v2
202252
with:
203253
subject-path: '${{ env.APPLICATION_NAME }}'

0 commit comments

Comments
 (0)