Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 7ca87d0

Browse files
authored
Feat python package codesign (#1780)
* feat: add codesign for macos * feat: add codesign for macos * fix: notary python zipped folder --------- Co-authored-by: Hien To <[email protected]>
1 parent 6113040 commit 7ca87d0

File tree

1 file changed

+96
-54
lines changed

1 file changed

+96
-54
lines changed

.github/workflows/python-package.yml

Lines changed: 96 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,23 @@ env:
3030
jobs:
3131
build-and-test:
3232
runs-on: ${{ matrix.runs-on }}
33-
timeout-minutes: 60
33+
timeout-minutes: 360
3434
strategy:
3535
fail-fast: false
3636
matrix:
3737
include:
3838
# - os: "linux"
3939
# name: "amd64"
4040
# runs-on: "ubuntu-20-04-cuda-12-0"
41-
# - os: "mac"
42-
# name: "amd64"
43-
# runs-on: "macos-selfhosted-12"
44-
# - os: "mac"
45-
# name: "arm64"
46-
# runs-on: "macos-silicon"
47-
- os: "windows"
41+
- os: "mac"
4842
name: "amd64"
49-
runs-on: "windows-cuda-12-0"
43+
runs-on: "macos-selfhosted-12"
44+
- os: "mac"
45+
name: "arm64"
46+
runs-on: "macos-silicon"
47+
# - os: "windows"
48+
# name: "amd64"
49+
# runs-on: "windows-cuda-12-0"
5050
steps:
5151
- name: Clone
5252
id: checkout
@@ -66,13 +66,33 @@ jobs:
6666
with:
6767
python-version: "3.11"
6868

69+
- name: Get Cer for code signing
70+
if: runner.os == 'macOS'
71+
run: base64 -d <<< "$CODE_SIGN_P12_BASE64" > /tmp/codesign.p12
72+
shell: bash
73+
env:
74+
CODE_SIGN_P12_BASE64: ${{ secrets.CODE_SIGN_P12_BASE64 }}
75+
76+
- uses: apple-actions/import-codesign-certs@v2
77+
continue-on-error: true
78+
if: runner.os == 'macOS'
79+
with:
80+
p12-file-base64: ${{ secrets.CODE_SIGN_P12_BASE64 }}
81+
p12-password: ${{ secrets.CODE_SIGN_P12_PASSWORD }}
82+
83+
- name: Get Cer for code signing
84+
if: runner.os == 'macOS'
85+
run: base64 -d <<< "$NOTARIZE_P8_BASE64" > /tmp/notary-key.p8
86+
shell: bash
87+
env:
88+
NOTARIZE_P8_BASE64: ${{ secrets.NOTARIZE_P8_BASE64 }}
89+
6990
- name: Install dependencies Windows
7091
if: runner.os == 'windows'
7192
shell: pwsh
7293
run: |
73-
74-
python3 -m pip install --upgrade pip
75-
python3 -m pip install -r ${{env.MODEL_DIR}}/requirements.cuda.txt
94+
python3 -m pip install --upgrade pip
95+
python3 -m pip install -r ${{env.MODEL_DIR}}/requirements.cuda.txt
7696
7797
- name: Install dependencies Linux
7898
if: runner.os == 'linux'
@@ -102,9 +122,8 @@ jobs:
102122
echo "Python path (where.exe): $pythonPath"
103123
$pythonFolder = Split-Path -Path "$pythonPath" -Parent
104124
echo "PYTHON_FOLDER=$pythonFolder" >> $env:GITHUB_ENV
105-
106125
copy "$pythonFolder\python*.*" "$pythonFolder\Scripts\"
107-
126+
108127
- name: prepare python package macos
109128
if : runner.os == 'macOs'
110129
run: |
@@ -128,7 +147,65 @@ jobs:
128147
rm -rf $PYTHON_FOLDER/lib/python3.1
129148
echo "PYTHON_FOLDER=$PYTHON_FOLDER" >> $GITHUB_ENV
130149
echo "github end PYTHON_FOLDER: ${{env.PYTHON_FOLDER}}"
131-
150+
151+
- name: create plist file
152+
if: runner.os == 'macOS'
153+
run: |
154+
cat << EOF > /tmp/entitlements.plist
155+
<?xml version="1.0" encoding="UTF-8"?>
156+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
157+
<plist version="1.0">
158+
<dict>
159+
<!-- These are required for binaries built by PyInstaller -->
160+
<key>com.apple.security.cs.allow-jit</key>
161+
<true/>
162+
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
163+
<true/>
164+
165+
<!-- Add these for additional permissions -->
166+
<key>com.apple.security.app-sandbox</key>
167+
<false/>
168+
<key>com.apple.security.network.client</key>
169+
<true/>
170+
<key>com.apple.security.network.server</key>
171+
<true/>
172+
<key>com.apple.security.device.audio-input</key>
173+
<true/>
174+
<key>com.apple.security.device.microphone</key>
175+
<true/>
176+
<key>com.apple.security.device.camera</key>
177+
<true/>
178+
<key>com.apple.security.files.user-selected.read-write</key>
179+
<true/>
180+
<key>com.apple.security.cs.disable-library-validation</key>
181+
<true/>
182+
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
183+
<true/>
184+
<key>com.apple.security.cs.allow-executable-memory</key>
185+
<true/>
186+
</dict>
187+
</plist>
188+
EOF
189+
190+
- name: Notary macOS Binary
191+
if: runner.os == 'macOS'
192+
run: |
193+
codesign --force --entitlements="/tmp/entitlements.plist" -s "${{ secrets.DEVELOPER_ID }}" --options=runtime ${{env.PYTHON_FOLDER}}/bin/python
194+
codesign --force --entitlements="/tmp/entitlements.plist" -s "${{ secrets.DEVELOPER_ID }}" --options=runtime ${{env.PYTHON_FOLDER}}/bin/python3
195+
# Code sign all .so files and .dylib files
196+
197+
find ${{env.PYTHON_FOLDER}} -type f \( -name "*.so" -o -name "*.dylib" \) -exec codesign --force --entitlements="/tmp/entitlements.plist" -s "${{ secrets.DEVELOPER_ID }}" --options=runtime {} \;
198+
199+
curl -sSfL https://raw.githubusercontent.com/anchore/quill/main/install.sh | sudo sh -s -- -b /usr/local/bin
200+
# Notarize the binary
201+
quill notarize ${{env.PYTHON_FOLDER}}/bin/python
202+
quill notarize ${{env.PYTHON_FOLDER}}/bin/python3
203+
find ${{env.PYTHON_FOLDER}} -type f \( -name "*.so" -o -name "*.dylib" \) -exec quill notarize {} \;
204+
env:
205+
QUILL_NOTARY_KEY_ID: ${{ secrets.NOTARY_KEY_ID }}
206+
QUILL_NOTARY_ISSUER: ${{ secrets.NOTARY_ISSUER }}
207+
QUILL_NOTARY_KEY: "/tmp/notary-key.p8"
208+
132209
- name: Upload Artifact
133210
#if : runner.os == 'windows' || runner.os == 'linux'
134211
uses: actions/upload-artifact@v4
@@ -143,43 +220,8 @@ jobs:
143220
run: |
144221
rm ${{env.PYTHON_FOLDER}}/Scripts/python*.*
145222
146-
codesign:
147-
runs-on: macos-latest
148-
needs: build-and-test
149-
steps:
150-
- name: checkout
151-
uses: actions/checkout@v3
152-
- uses: apple-actions/import-codesign-certs@v2
223+
- name: Remove Keychain
153224
continue-on-error: true
154-
with:
155-
p12-file-base64: ${{ secrets.CODE_SIGN_P12_BASE64 }}
156-
p12-password: ${{ secrets.CODE_SIGN_P12_PASSWORD }}
157-
- name: Download Artifact
158-
uses: actions/download-artifact@v4
159-
with:
160-
name: ${{env.MODEL_NAME}}-mac-amd64
161-
path: ${{env.MODEL_NAME}}-mac-amd64
162-
- name: Download Artifact
163-
uses: actions/download-artifact@v4
164-
with:
165-
name: ${{env.MODEL_NAME}}-mac-arm64
166-
path: ${{env.MODEL_NAME}}-mac-arm64
167-
168-
- run: |
169-
find "${{env.MODEL_NAME}}-mac-amd64" \( -type f -perm +111 \) -exec codesign --force --entitlements="./engine/templates/macos/entitlements.plist" -s "${{ secrets.DEVELOPER_ID }}" --options=runtime {} \;
170-
find "${{env.MODEL_NAME}}-mac-arm64" \( -type f -perm +111 \) -exec codesign --force --entitlements="./engine/templates/macos/entitlements.plist" -s "${{ secrets.DEVELOPER_ID }}" --options=runtime {} \;
171-
172-
- name: Upload Artifact
173-
uses: actions/upload-artifact@v4
174-
with:
175-
name: ${{env.MODEL_NAME}}-mac-amd64-signed
176-
path: ${{env.MODEL_NAME}}-mac-amd64
177-
include-hidden-files: true
178-
compression-level: 9
179-
- name: Upload Artifact
180-
uses: actions/upload-artifact@v4
181-
with:
182-
name: ${{env.MODEL_NAME}}-mac-arm64-signed
183-
path: ${{env.MODEL_NAME}}-mac-arm64
184-
include-hidden-files: true
185-
compression-level: 9
225+
if: always() && runner.os == 'macOS'
226+
run: |
227+
security delete-keychain signing_temp.keychain

0 commit comments

Comments
 (0)