-
Notifications
You must be signed in to change notification settings - Fork 45
272 lines (229 loc) · 10.1 KB
/
build_executable.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
name: Build executable version of CLI and upload artifact. On dispatch event build the latest tag and upload to release assets
on:
workflow_dispatch:
push:
branches:
- main
- CM-30405-add-building-of-executable-cli-in-the-onedir-mode
permissions:
contents: write
jobs:
build:
name: Build on ${{ matrix.os }} (${{ matrix.mode }} mode)
strategy:
fail-fast: false
matrix:
os: [ ubuntu-20.04, macos-11, macos-13-xlarge, windows-2019 ]
mode: [ 'onefile', 'onedir' ]
exclude:
- os: ubuntu-20.04
mode: onedir
- os: windows-2019
mode: onedir
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
steps:
- name: Run Cimon
if: matrix.os == 'ubuntu-20.04'
uses: cycodelabs/cimon-action@v0
with:
client-id: ${{ secrets.CIMON_CLIENT_ID }}
secret: ${{ secrets.CIMON_SECRET }}
prevent: true
allowed-hosts: >
files.pythonhosted.org
install.python-poetry.org
pypi.org
uploads.github.com
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout latest release tag
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
git checkout $LATEST_TAG
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Load cached Poetry setup
id: cached-poetry
uses: actions/cache@v3
with:
path: ~/.local
key: poetry-${{ matrix.os }}-1 # increment to reset cache
- name: Setup Poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
with:
version: 1.5.1
- name: Add Poetry to PATH
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install dependencies
run: |
# we are exporting dependencies to do the trick with pyinstaller version
# we want to use new pyinstaller version with python 3.12, but our project uses Python 3.7
# the pyinstaller v6 dropped support of python 3.7
poetry export -f "requirements.txt" -o "requirements.txt"
pip install -r requirements.txt
pip install pyinstaller==6.3.0 dunamai==1.18.0
- name: Import macOS signing certificate
if: runner.os == 'macOS'
env:
APPLE_CERT: ${{ secrets.APPLE_CERT }}
APPLE_CERT_PWD: ${{ secrets.APPLE_CERT_PWD }}
APPLE_CERT_NAME: ${{ secrets.APPLE_CERT_NAME }}
APPLE_KEYCHAIN_PASSWORD: ${{ secrets.APPLE_KEYCHAIN_PASSWORD }}
run: |
# import certificate
CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12
echo -n "$APPLE_CERT" | base64 --decode -o $CERTIFICATE_PATH
# create temporary keychain
KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db
security create-keychain -p "$APPLE_KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
security set-keychain-settings -lut 21600 $KEYCHAIN_PATH
security unlock-keychain -p "$APPLE_KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
# import certificate to keychain
security import $CERTIFICATE_PATH -P "$APPLE_CERT_PWD" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH
security list-keychain -d user -s $KEYCHAIN_PATH
- name: Build executable (onefile)
if: matrix.mode == 'onefile'
env:
APPLE_CERT_NAME: ${{ secrets.APPLE_CERT_NAME }}
run: poetry run pyinstaller pyinstaller.spec
- name: Build executable (onedir)
if: matrix.mode == 'onedir'
env:
CYCODE_ONEDIR_MODE: 1
APPLE_CERT_NAME: ${{ secrets.APPLE_CERT_NAME }}
run: poetry run pyinstaller pyinstaller.spec
- name: Test executable (onefile)
if: matrix.mode == 'onefile'
run: time ./dist/cycode version
- name: Test executable (onedir)
if: matrix.mode == 'onedir'
run: time ./dist/cycode/cycode version
- name: Sign macOS executable
if: runner.os == 'macOS' && matrix.mode == 'onefile'
env:
APPLE_CERT_NAME: ${{ secrets.APPLE_CERT_NAME }}
run: |
# sign executable
codesign --deep --force --options=runtime --entitlements entitlements.plist --sign "$APPLE_CERT_NAME" --timestamp dist/cycode
- name: Sign macOS executable (onedir)
if: runner.os == 'macOS' && matrix.mode == 'onedir'
env:
APPLE_CERT_NAME: ${{ secrets.APPLE_CERT_NAME }}
run: |
# sign executable
codesign --deep --force --options=runtime --entitlements entitlements.plist --sign "$APPLE_CERT_NAME" --timestamp dist/cycode/cycode
- name: Notarize macOS executable
if: runner.os == 'macOS'
env:
APPLE_NOTARIZATION_EMAIL: ${{ secrets.APPLE_NOTARIZATION_EMAIL }}
APPLE_NOTARIZATION_PWD: ${{ secrets.APPLE_NOTARIZATION_PWD }}
APPLE_NOTARIZATION_TEAM_ID: ${{ secrets.APPLE_NOTARIZATION_TEAM_ID }}
run: |
# create keychain profile
xcrun notarytool store-credentials "notarytool-profile" --apple-id "$APPLE_NOTARIZATION_EMAIL" --team-id "$APPLE_NOTARIZATION_TEAM_ID" --password "$APPLE_NOTARIZATION_PWD"
# create zip file (notarization does not support binaries)
ditto -c -k --keepParent dist/cycode notarization.zip
# notarize app (this will take a while)
xcrun notarytool submit notarization.zip --keychain-profile "notarytool-profile" --wait
# we can't staple the app because it's executable. we should only staple app bundles like .dmg
# xcrun stapler staple dist/cycode
- name: Test macOS signed executable (onefile)
if: runner.os == 'macOS' && matrix.mode == 'onefile'
run: time ./dist/cycode version
- name: Test executable (onedir)
if: runner.os == 'macOS' && matrix.mode == 'onedir'
run: time ./dist/cycode/cycode version
- name: Import cert for Windows and setup envs
if: runner.os == 'Windows'
env:
SM_CLIENT_CERT_FILE_B64: ${{ secrets.SM_CLIENT_CERT_FILE_B64 }}
run: |
# import certificate
echo "$SM_CLIENT_CERT_FILE_B64" | base64 --decode > /d/Certificate_pkcs12.p12
echo "SM_CLIENT_CERT_FILE=D:\\Certificate_pkcs12.p12" >> "$GITHUB_ENV"
# add required soft to the path
echo "C:\Program Files (x86)\Windows Kits\10\App Certification Kit" >> $GITHUB_PATH
echo "C:\Program Files\DigiCert\DigiCert One Signing Manager Tools" >> $GITHUB_PATH
- name: Sign Windows executable
if: runner.os == 'Windows'
shell: cmd
env:
SM_HOST: ${{ secrets.SM_HOST }}
SM_API_KEY: ${{ secrets.SM_API_KEY }}
SM_CLIENT_CERT_PASSWORD: ${{ secrets.SM_CLIENT_CERT_PASSWORD }}
SM_CODE_SIGNING_CERT_SHA1_HASH: ${{ secrets.SM_CODE_SIGNING_CERT_SHA1_HASH }}
run: |
:: setup SSM KSP
curl -X GET https://one.digicert.com/signingmanager/api-ui/v1/releases/smtools-windows-x64.msi/download -H "x-api-key:%SM_API_KEY%" -o smtools-windows-x64.msi
msiexec /i smtools-windows-x64.msi /quiet /qn
C:\Windows\System32\certutil.exe -csp "DigiCert Signing Manager KSP" -key -user
smksp_cert_sync.exe
:: sign executable
signtool.exe sign /sha1 %SM_CODE_SIGNING_CERT_SHA1_HASH% /tr http://timestamp.digicert.com /td SHA256 /fd SHA256 ".\dist\cycode.exe"
- name: Test Windows signed executable
if: runner.os == 'Windows'
shell: cmd
run: |
:: call executable and expect correct output
.\dist\cycode.exe version
:: verify signature
signtool.exe verify /v /pa ".\dist\cycode.exe"
- name: Prepare files on Windows
if: runner.os == 'Windows'
run: |
echo "ARTIFACT_NAME=cycode-win" >> $GITHUB_ENV
mv dist/cycode.exe dist/cycode-win.exe
powershell -Command "(Get-FileHash -Algorithm SHA256 dist/cycode-win.exe).Hash" > sha256
head -c 64 sha256 > dist/cycode-win.exe.sha256
- name: Prepare files on Intel macOS (onefile)
if: runner.os == 'macOS' && runner.arch == 'X64' && matrix.mode == 'onefile'
run: |
echo "ARTIFACT_NAME=cycode-mac" >> $GITHUB_ENV
mv dist/cycode dist/cycode-mac
shasum -a 256 dist/cycode-mac > sha256
head -c 64 sha256 > dist/cycode-mac.sha256
- name: Prepare files on Apple Silicon macOS (onefile)
if: runner.os == 'macOS' && runner.arch == 'ARM64' && matrix.mode == 'onefile'
run: |
echo "ARTIFACT_NAME=cycode-mac-arm" >> $GITHUB_ENV
mv dist/cycode dist/cycode-mac-arm
shasum -a 256 dist/cycode-mac-arm > sha256
head -c 64 sha256 > dist/cycode-mac-arm.sha256
- name: Prepare files on Intel macOS (onedir)
if: runner.os == 'macOS' && runner.arch == 'X64' && matrix.mode == 'onedir'
run: |
echo "ARTIFACT_NAME=cycode-mac-onedir" >> $GITHUB_ENV
- name: Prepare files on Apple Silicon macOS (onedir)
if: runner.os == 'macOS' && runner.arch == 'ARM64' && matrix.mode == 'onedir'
run: |
echo "ARTIFACT_NAME=cycode-mac-arm-onedir" >> $GITHUB_ENV
- name: Prepare files on Linux
if: runner.os == 'Linux'
run: |
echo "ARTIFACT_NAME=cycode-linux" >> $GITHUB_ENV
mv dist/cycode dist/cycode-linux
sha256sum dist/cycode-linux > sha256
head -c 64 sha256 > dist/cycode-linux.sha256
- name: Upload files as artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}
path: dist
- name: Upload files to release
if: ${{ github.event_name == 'workflow_dispatch' }}
uses: svenstaro/upload-release-action@v2
with:
file: dist/*
tag: ${{ env.LATEST_TAG }}
overwrite: true
file_glob: true