Skip to content

Commit 6025e9b

Browse files
authored
CM-26497 - Attach signed executables and their checksums as assets to GitHub releases (#172)
1 parent f328471 commit 6025e9b

File tree

1 file changed

+55
-10
lines changed

1 file changed

+55
-10
lines changed

.github/workflows/build_executable.yml

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
name: Build executable version of CLI
1+
name: Build executable version of CLI and upload artifact. On dispatch event build the latest tag and upload to release assets
22

33
on:
4+
workflow_dispatch:
45
push:
56
branches:
67
- main
78

9+
permissions:
10+
contents: write
11+
812
jobs:
913
build:
1014
strategy:
@@ -32,10 +36,17 @@ jobs:
3236
pypi.org
3337
3438
- name: Checkout repository
35-
uses: actions/checkout@v3
39+
uses: actions/checkout@v4
3640
with:
3741
fetch-depth: 0
3842

43+
- name: Checkout latest release tag
44+
if: ${{ github.event_name == 'workflow_dispatch' }}
45+
run: |
46+
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
47+
git checkout $LATEST_TAG
48+
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
49+
3950
- name: Set up Python 3.7
4051
uses: actions/setup-python@v4
4152
with:
@@ -67,7 +78,7 @@ jobs:
6778
run: ./dist/cycode version
6879

6980
- name: Sign macOS executable
70-
if: ${{ startsWith(matrix.os, 'macos') }}
81+
if: runner.os == 'macOS'
7182
env:
7283
APPLE_CERT: ${{ secrets.APPLE_CERT }}
7384
APPLE_CERT_PWD: ${{ secrets.APPLE_CERT_PWD }}
@@ -92,7 +103,7 @@ jobs:
92103
codesign --deep --force --options=runtime --entitlements entitlements.plist --sign "$APPLE_CERT_NAME" --timestamp dist/cycode
93104
94105
- name: Notarize macOS executable
95-
if: ${{ startsWith(matrix.os, 'macos') }}
106+
if: runner.os == 'macOS'
96107
env:
97108
APPLE_NOTARIZATION_EMAIL: ${{ secrets.APPLE_NOTARIZATION_EMAIL }}
98109
APPLE_NOTARIZATION_PWD: ${{ secrets.APPLE_NOTARIZATION_PWD }}
@@ -111,11 +122,11 @@ jobs:
111122
# xcrun stapler staple dist/cycode
112123
113124
- name: Test macOS signed executable
114-
if: ${{ startsWith(matrix.os, 'macos') }}
125+
if: runner.os == 'macOS'
115126
run: ./dist/cycode version
116127

117128
- name: Import cert for Windows and setup envs
118-
if: ${{ startsWith(matrix.os, 'windows') }}
129+
if: runner.os == 'Windows'
119130
env:
120131
SM_CLIENT_CERT_FILE_B64: ${{ secrets.SM_CLIENT_CERT_FILE_B64 }}
121132
run: |
@@ -128,7 +139,7 @@ jobs:
128139
echo "C:\Program Files\DigiCert\DigiCert One Signing Manager Tools" >> $GITHUB_PATH
129140
130141
- name: Sign Windows executable
131-
if: ${{ startsWith(matrix.os, 'windows') }}
142+
if: runner.os == 'Windows'
132143
shell: cmd
133144
env:
134145
SM_HOST: ${{ secrets.SM_HOST }}
@@ -146,7 +157,7 @@ jobs:
146157
signtool.exe sign /sha1 %SM_CODE_SIGNING_CERT_SHA1_HASH% /tr http://timestamp.digicert.com /td SHA256 /fd SHA256 ".\dist\cycode.exe"
147158
148159
- name: Test Windows signed executable
149-
if: ${{ startsWith(matrix.os, 'windows') }}
160+
if: runner.os == 'Windows'
150161
shell: cmd
151162
run: |
152163
:: call executable and expect correct output
@@ -155,7 +166,41 @@ jobs:
155166
:: verify signature
156167
signtool.exe verify /v /pa ".\dist\cycode.exe"
157168
158-
- uses: actions/upload-artifact@v3
169+
- name: Prepare files on Windows
170+
if: runner.os == 'Windows'
171+
run: |
172+
echo "ARTIFACT_NAME=cycode-win" >> $GITHUB_ENV
173+
mv dist/cycode.exe dist/cycode-win.exe
174+
powershell -Command "(Get-FileHash -Algorithm SHA256 dist/cycode-win.exe).Hash" > sha256
175+
head -c 64 sha256 > dist/cycode-win.exe.sha256
176+
177+
- name: Prepare files on macOS
178+
if: runner.os == 'macOS'
179+
run: |
180+
echo "ARTIFACT_NAME=cycode-mac" >> $GITHUB_ENV
181+
mv dist/cycode dist/cycode-mac
182+
shasum -a 256 dist/cycode-mac > sha256
183+
head -c 64 sha256 > dist/cycode-mac.sha256
184+
185+
- name: Prepare files on Linux
186+
if: runner.os == 'Linux'
187+
run: |
188+
echo "ARTIFACT_NAME=cycode-linux" >> $GITHUB_ENV
189+
mv dist/cycode dist/cycode-linux
190+
sha256sum dist/cycode-linux > sha256
191+
head -c 64 sha256 > dist/cycode-linux.sha256
192+
193+
- name: Upload files as artifact
194+
uses: actions/upload-artifact@v3
159195
with:
160-
name: cycode-cli-${{ matrix.os }}
196+
name: ${{ env.ARTIFACT_NAME }}
161197
path: dist
198+
199+
- name: Upload files to release
200+
if: ${{ github.event_name == 'workflow_dispatch' }}
201+
uses: svenstaro/upload-release-action@v2
202+
with:
203+
file: dist/*
204+
tag: ${{ env.LATEST_TAG }}
205+
overwrite: true
206+
file_glob: true

0 commit comments

Comments
 (0)