Skip to content

Commit 39150a8

Browse files
authored
GitHub actions (#6)
* GH action deploy workflow
1 parent bb8b890 commit 39150a8

File tree

3 files changed

+266
-0
lines changed

3 files changed

+266
-0
lines changed

.github/workflows/pyinstaller.yml

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
on:
2+
push:
3+
tags:
4+
- 'v*'
5+
6+
jobs:
7+
build_macos_arm64:
8+
runs-on: macos-14
9+
steps:
10+
- uses: actions/checkout@v4
11+
12+
- name: Extract version tag
13+
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
14+
15+
- uses: actions/setup-python@v5
16+
with:
17+
python-version: '3.11'
18+
19+
- run: pip install -r requirements.txt
20+
21+
- name: Install Certificate
22+
run: |
23+
echo "${{ secrets.CERTIFICATE_BASE64 }}" | base64 --decode -o certificate.p12
24+
security create-keychain -p "temp_password" build.keychain
25+
security default-keychain -s build.keychain
26+
security unlock-keychain -p "temp_password" build.keychain
27+
security import certificate.p12 -k build.keychain -P ${{ secrets.CERTIFICATE_PASSWORD }} -T /usr/bin/codesign
28+
security set-key-partition-list -S apple-tool:,apple: -s -k "temp_password" build.keychain
29+
30+
- name: Decode API Key
31+
run: |
32+
echo "${{ secrets.API_KEY }}" | base64 --decode -o ./AuthKey.p8
33+
34+
- name: Prepare Notary
35+
run: |
36+
xcrun notarytool store-credentials "GitHubActions" --key ./AuthKey.p8 --key-id ${{ secrets.API_KEY_ID }} --issuer ${{ secrets.ISSUER_ID }}
37+
38+
- name: Prepare .spec File
39+
run: |
40+
sed -i '' "s/SECRET_DEVELOPER_ID/${{ secrets.DEVELOPER_ID }}/" SmartImageShrink.spec
41+
sed -i '' "s/SmartImageShrink_TAGVERSION/SmartImageShrink_${{ env.VERSION }}/" SmartImageShrink.spec
42+
sed -i '' "s/OS_ARCHITECTURE/arm64/" SmartImageShrink.spec
43+
44+
- name: Bundle APP
45+
run: pyinstaller SmartImageShrink.spec
46+
47+
- name: Set Executable Permissions
48+
run: chmod +x dist/SmartImageShrink_${{ env.VERSION }}.app/Contents/MacOS/SmartImageShrink_${{ env.VERSION }}
49+
50+
- name: Zip the App for Notarization
51+
run: |
52+
zip -r -y -p SmartImageShrink_${{ env.VERSION }}.app.zip dist/SmartImageShrink_${{ env.VERSION }}.app
53+
54+
- name: Notarize
55+
run: |
56+
xcrun notarytool submit SmartImageShrink_${{ env.VERSION }}.app.zip --keychain-profile "GitHubActions" --wait
57+
58+
- name: Staple the App
59+
run: xcrun stapler staple dist/SmartImageShrink_${{ env.VERSION }}.app
60+
61+
- name: check
62+
run: spctl -a -t exec -vv dist/SmartImageShrink_${{ env.VERSION }}.app
63+
64+
- name: Prepare Tar Directory with name of the app
65+
run: |
66+
mkdir -p SmartImageShrink_${{ env.VERSION }}_macOS_arm64
67+
cp -R dist/SmartImageShrink_${{ env.VERSION }}.app SmartImageShrink_${{ env.VERSION }}_macOS_arm64/
68+
69+
- name: Check permissions
70+
run: ls -l SmartImageShrink_${{ env.VERSION }}_macOS_arm64/SmartImageShrink_${{ env.VERSION }}.app/Contents/MacOS/*
71+
72+
- name: Tar the application to preserve permissions
73+
run: tar -cvf SmartImageShrink_${{ env.VERSION }}_macOS_arm64.app.tar SmartImageShrink_${{ env.VERSION }}_macOS_arm64
74+
75+
- name: Upload Tarred App as Artifact
76+
uses: actions/upload-artifact@v4
77+
with:
78+
name: SmartImageShrink_${{ env.VERSION }}_macOS_arm64
79+
path: SmartImageShrink_${{ env.VERSION }}_macOS_arm64.app.tar
80+
81+
build_macos_x86_64x:
82+
runs-on: macos-13
83+
steps:
84+
- uses: actions/checkout@v4
85+
86+
- name: Extract version tag
87+
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
88+
89+
- uses: actions/setup-python@v5
90+
with:
91+
python-version: '3.11'
92+
93+
- run: pip install -r requirements.txt
94+
95+
- name: Install Certificate
96+
run: |
97+
echo "${{ secrets.CERTIFICATE_BASE64 }}" | base64 --decode -o certificate.p12
98+
security create-keychain -p "temp_password" build.keychain
99+
security default-keychain -s build.keychain
100+
security unlock-keychain -p "temp_password" build.keychain
101+
security import certificate.p12 -k build.keychain -P ${{ secrets.CERTIFICATE_PASSWORD }} -T /usr/bin/codesign
102+
security set-key-partition-list -S apple-tool:,apple: -s -k "temp_password" build.keychain
103+
104+
- name: Decode API Key
105+
run: |
106+
echo "${{ secrets.API_KEY }}" | base64 --decode -o ./AuthKey.p8
107+
108+
- name: Prepare Notary
109+
run: |
110+
xcrun notarytool store-credentials "GitHubActions" --key ./AuthKey.p8 --key-id ${{ secrets.API_KEY_ID }} --issuer ${{ secrets.ISSUER_ID }}
111+
112+
- name: Prepare .spec File
113+
run: |
114+
sed -i '' "s/SECRET_DEVELOPER_ID/${{ secrets.DEVELOPER_ID }}/" SmartImageShrink.spec
115+
sed -i '' "s/SmartImageShrink_TAGVERSION/SmartImageShrink_${{ env.VERSION }}/" SmartImageShrink.spec
116+
sed -i '' "s/OS_ARCHITECTURE/x86_64/" SmartImageShrink.spec
117+
118+
- name: Bundle APP
119+
run: pyinstaller SmartImageShrink.spec
120+
121+
- name: Set Executable Permissions
122+
run: chmod +x dist/SmartImageShrink_${{ env.VERSION }}.app/Contents/MacOS/SmartImageShrink_${{ env.VERSION }}
123+
124+
- name: Zip the App for Notarization
125+
run: |
126+
zip -r -y -p SmartImageShrink_${{ env.VERSION }}.app.zip dist/SmartImageShrink_${{ env.VERSION }}.app
127+
128+
- name: Notarize
129+
run: |
130+
xcrun notarytool submit SmartImageShrink_${{ env.VERSION }}.app.zip --keychain-profile "GitHubActions" --wait
131+
132+
- name: Staple the App
133+
run: xcrun stapler staple dist/SmartImageShrink_${{ env.VERSION }}.app
134+
135+
- name: check
136+
run: spctl -a -t exec -vv dist/SmartImageShrink_${{ env.VERSION }}.app
137+
138+
- name: Prepare Tar Directory with name of the app
139+
run: |
140+
mkdir -p SmartImageShrink_${{ env.VERSION }}_macOS_x86_64
141+
cp -R dist/SmartImageShrink_${{ env.VERSION }}.app SmartImageShrink_${{ env.VERSION }}_macOS_x86_64/
142+
143+
- name: Check permissions
144+
run: ls -l SmartImageShrink_${{ env.VERSION }}_macOS_x86_64/SmartImageShrink_${{ env.VERSION }}.app/Contents/MacOS/*
145+
146+
- name: Tar the application to preserve permissions
147+
run: tar -cvf SmartImageShrink_${{ env.VERSION }}_macOS_intel_x86_64.app.tar SmartImageShrink_${{ env.VERSION }}_macOS_x86_64
148+
149+
- name: Upload Tarred App as Artifact
150+
uses: actions/upload-artifact@v4
151+
with:
152+
name: SmartImageShrink_${{ env.VERSION }}_macOS_intel_x86_64
153+
path: SmartImageShrink_${{ env.VERSION }}_macOS_intel_x86_64.app.tar
154+
155+
build_windows:
156+
runs-on: windows-latest
157+
steps:
158+
- uses: actions/checkout@v4
159+
160+
- name: Extract version tag
161+
run: |
162+
$tagVersion = "${{ github.ref }}".Split('/')[-1]
163+
echo "VERSION=$tagVersion" | Out-File -FilePath $env:GITHUB_ENV -Append
164+
shell: pwsh
165+
166+
- uses: actions/setup-python@v5
167+
with:
168+
python-version: '3.11'
169+
170+
- run: pip install -r requirements.txt
171+
172+
- name: Prepare .spec File
173+
shell: pwsh
174+
run: |
175+
(Get-Content SmartImageShrink.spec) -replace 'SECRET_DEVELOPER_ID', '' -replace 'SmartImageShrink_TAGVERSION', 'SmartImageShrink_${{ env.VERSION }}' -replace 'OS_ARCHITECTURE', 'x86_64' -replace 'img/icon.png', 'img\\icon.ico' | Set-Content SmartImageShrink.spec
176+
177+
- name: Bundle APP
178+
run: pyinstaller SmartImageShrink.spec
179+
180+
- name: Prepare Directory with name of the app
181+
run: |
182+
New-Item -ItemType Directory -Path SmartImageShrink_${{ env.VERSION }}_win
183+
Move-Item dist\SmartImageShrink_${{ env.VERSION }}.exe SmartImageShrink_${{ env.VERSION }}_win\SmartImageShrink_${{ env.VERSION }}.exe
184+
shell: pwsh
185+
186+
- name: Zip the application to preserve permissions
187+
shell: pwsh
188+
run: Compress-Archive -Path SmartImageShrink_${{ env.VERSION }}_win -DestinationPath SmartImageShrink_${{ env.VERSION }}_win.zip
189+
190+
- name: Upload App as Artifact
191+
uses: actions/upload-artifact@v4
192+
with:
193+
name: SmartImageShrink_${{ env.VERSION }}_win
194+
path: SmartImageShrink_${{ env.VERSION }}_win.zip
195+
196+
release:
197+
needs: [build_macos_arm64, build_macos_x86_64x, build_windows]
198+
runs-on: ubuntu-latest
199+
steps:
200+
- name: Extract version tag
201+
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
202+
203+
- name: Download All Artifacts
204+
uses: actions/download-artifact@v4
205+
with:
206+
path: artifacts/
207+
merge-multiple: true
208+
209+
- name: List downloaded artifacts
210+
run: ls -R artifacts/
211+
212+
- name: Create and Upload Release
213+
uses: softprops/action-gh-release@v2
214+
with:
215+
tag_name: ${{ env.VERSION }}
216+
name: Release ${{ env.VERSION }}
217+
files: artifacts/*
218+
token: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ compress_images_windows.exe
1111
/main.spec
1212
/your_script.spec
1313
/pyinstaller.txt
14+
/SmartImageShrink_v0.4.spec
15+
/SmartImageShrink_v0.5.spec
16+
/save/

SmartImageShrink.spec

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# -*- mode: python ; coding: utf-8 -*-
2+
3+
4+
a = Analysis(
5+
['main.py'],
6+
pathex=[],
7+
binaries=[],
8+
datas=[('img', 'img')],
9+
hiddenimports=[],
10+
hookspath=[],
11+
hooksconfig={},
12+
runtime_hooks=[],
13+
excludes=[],
14+
noarchive=False,
15+
optimize=0,
16+
)
17+
pyz = PYZ(a.pure)
18+
19+
exe = EXE(
20+
pyz,
21+
a.scripts,
22+
a.binaries,
23+
a.datas,
24+
[],
25+
name='SmartImageShrink_TAGVERSION',
26+
debug=False,
27+
bootloader_ignore_signals=False,
28+
strip=False,
29+
upx=False,
30+
upx_exclude=[],
31+
runtime_tmpdir=None,
32+
console=False,
33+
disable_windowed_traceback=False,
34+
argv_emulation=False,
35+
target_arch='OS_ARCHITECTURE',
36+
codesign_identity='SECRET_DEVELOPER_ID',
37+
entitlements_file=None,
38+
icon=['img/icon.png'],
39+
)
40+
app = BUNDLE(
41+
exe,
42+
name='SmartImageShrink_TAGVERSION.app',
43+
icon='img/icon.png',
44+
bundle_identifier='com.presa.SmartImageShrink',
45+
)

0 commit comments

Comments
 (0)