From 39150a8d6912cf8441e10c01798a24ad4d92e10a Mon Sep 17 00:00:00 2001 From: Presa <124523559+zenWai@users.noreply.github.com> Date: Sun, 21 Apr 2024 16:40:27 +0200 Subject: [PATCH] GitHub actions (#6) * GH action deploy workflow --- .github/workflows/pyinstaller.yml | 218 ++++++++++++++++++++++++++++++ .gitignore | 3 + SmartImageShrink.spec | 45 ++++++ 3 files changed, 266 insertions(+) create mode 100644 .github/workflows/pyinstaller.yml create mode 100644 SmartImageShrink.spec diff --git a/.github/workflows/pyinstaller.yml b/.github/workflows/pyinstaller.yml new file mode 100644 index 0000000..57becfd --- /dev/null +++ b/.github/workflows/pyinstaller.yml @@ -0,0 +1,218 @@ +on: + push: + tags: + - 'v*' + +jobs: + build_macos_arm64: + runs-on: macos-14 + steps: + - uses: actions/checkout@v4 + + - name: Extract version tag + run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + + - uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - run: pip install -r requirements.txt + + - name: Install Certificate + run: | + echo "${{ secrets.CERTIFICATE_BASE64 }}" | base64 --decode -o certificate.p12 + security create-keychain -p "temp_password" build.keychain + security default-keychain -s build.keychain + security unlock-keychain -p "temp_password" build.keychain + security import certificate.p12 -k build.keychain -P ${{ secrets.CERTIFICATE_PASSWORD }} -T /usr/bin/codesign + security set-key-partition-list -S apple-tool:,apple: -s -k "temp_password" build.keychain + + - name: Decode API Key + run: | + echo "${{ secrets.API_KEY }}" | base64 --decode -o ./AuthKey.p8 + + - name: Prepare Notary + run: | + xcrun notarytool store-credentials "GitHubActions" --key ./AuthKey.p8 --key-id ${{ secrets.API_KEY_ID }} --issuer ${{ secrets.ISSUER_ID }} + + - name: Prepare .spec File + run: | + sed -i '' "s/SECRET_DEVELOPER_ID/${{ secrets.DEVELOPER_ID }}/" SmartImageShrink.spec + sed -i '' "s/SmartImageShrink_TAGVERSION/SmartImageShrink_${{ env.VERSION }}/" SmartImageShrink.spec + sed -i '' "s/OS_ARCHITECTURE/arm64/" SmartImageShrink.spec + + - name: Bundle APP + run: pyinstaller SmartImageShrink.spec + + - name: Set Executable Permissions + run: chmod +x dist/SmartImageShrink_${{ env.VERSION }}.app/Contents/MacOS/SmartImageShrink_${{ env.VERSION }} + + - name: Zip the App for Notarization + run: | + zip -r -y -p SmartImageShrink_${{ env.VERSION }}.app.zip dist/SmartImageShrink_${{ env.VERSION }}.app + + - name: Notarize + run: | + xcrun notarytool submit SmartImageShrink_${{ env.VERSION }}.app.zip --keychain-profile "GitHubActions" --wait + + - name: Staple the App + run: xcrun stapler staple dist/SmartImageShrink_${{ env.VERSION }}.app + + - name: check + run: spctl -a -t exec -vv dist/SmartImageShrink_${{ env.VERSION }}.app + + - name: Prepare Tar Directory with name of the app + run: | + mkdir -p SmartImageShrink_${{ env.VERSION }}_macOS_arm64 + cp -R dist/SmartImageShrink_${{ env.VERSION }}.app SmartImageShrink_${{ env.VERSION }}_macOS_arm64/ + + - name: Check permissions + run: ls -l SmartImageShrink_${{ env.VERSION }}_macOS_arm64/SmartImageShrink_${{ env.VERSION }}.app/Contents/MacOS/* + + - name: Tar the application to preserve permissions + run: tar -cvf SmartImageShrink_${{ env.VERSION }}_macOS_arm64.app.tar SmartImageShrink_${{ env.VERSION }}_macOS_arm64 + + - name: Upload Tarred App as Artifact + uses: actions/upload-artifact@v4 + with: + name: SmartImageShrink_${{ env.VERSION }}_macOS_arm64 + path: SmartImageShrink_${{ env.VERSION }}_macOS_arm64.app.tar + + build_macos_x86_64x: + runs-on: macos-13 + steps: + - uses: actions/checkout@v4 + + - name: Extract version tag + run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + + - uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - run: pip install -r requirements.txt + + - name: Install Certificate + run: | + echo "${{ secrets.CERTIFICATE_BASE64 }}" | base64 --decode -o certificate.p12 + security create-keychain -p "temp_password" build.keychain + security default-keychain -s build.keychain + security unlock-keychain -p "temp_password" build.keychain + security import certificate.p12 -k build.keychain -P ${{ secrets.CERTIFICATE_PASSWORD }} -T /usr/bin/codesign + security set-key-partition-list -S apple-tool:,apple: -s -k "temp_password" build.keychain + + - name: Decode API Key + run: | + echo "${{ secrets.API_KEY }}" | base64 --decode -o ./AuthKey.p8 + + - name: Prepare Notary + run: | + xcrun notarytool store-credentials "GitHubActions" --key ./AuthKey.p8 --key-id ${{ secrets.API_KEY_ID }} --issuer ${{ secrets.ISSUER_ID }} + + - name: Prepare .spec File + run: | + sed -i '' "s/SECRET_DEVELOPER_ID/${{ secrets.DEVELOPER_ID }}/" SmartImageShrink.spec + sed -i '' "s/SmartImageShrink_TAGVERSION/SmartImageShrink_${{ env.VERSION }}/" SmartImageShrink.spec + sed -i '' "s/OS_ARCHITECTURE/x86_64/" SmartImageShrink.spec + + - name: Bundle APP + run: pyinstaller SmartImageShrink.spec + + - name: Set Executable Permissions + run: chmod +x dist/SmartImageShrink_${{ env.VERSION }}.app/Contents/MacOS/SmartImageShrink_${{ env.VERSION }} + + - name: Zip the App for Notarization + run: | + zip -r -y -p SmartImageShrink_${{ env.VERSION }}.app.zip dist/SmartImageShrink_${{ env.VERSION }}.app + + - name: Notarize + run: | + xcrun notarytool submit SmartImageShrink_${{ env.VERSION }}.app.zip --keychain-profile "GitHubActions" --wait + + - name: Staple the App + run: xcrun stapler staple dist/SmartImageShrink_${{ env.VERSION }}.app + + - name: check + run: spctl -a -t exec -vv dist/SmartImageShrink_${{ env.VERSION }}.app + + - name: Prepare Tar Directory with name of the app + run: | + mkdir -p SmartImageShrink_${{ env.VERSION }}_macOS_x86_64 + cp -R dist/SmartImageShrink_${{ env.VERSION }}.app SmartImageShrink_${{ env.VERSION }}_macOS_x86_64/ + + - name: Check permissions + run: ls -l SmartImageShrink_${{ env.VERSION }}_macOS_x86_64/SmartImageShrink_${{ env.VERSION }}.app/Contents/MacOS/* + + - name: Tar the application to preserve permissions + run: tar -cvf SmartImageShrink_${{ env.VERSION }}_macOS_intel_x86_64.app.tar SmartImageShrink_${{ env.VERSION }}_macOS_x86_64 + + - name: Upload Tarred App as Artifact + uses: actions/upload-artifact@v4 + with: + name: SmartImageShrink_${{ env.VERSION }}_macOS_intel_x86_64 + path: SmartImageShrink_${{ env.VERSION }}_macOS_intel_x86_64.app.tar + + build_windows: + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + + - name: Extract version tag + run: | + $tagVersion = "${{ github.ref }}".Split('/')[-1] + echo "VERSION=$tagVersion" | Out-File -FilePath $env:GITHUB_ENV -Append + shell: pwsh + + - uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - run: pip install -r requirements.txt + + - name: Prepare .spec File + shell: pwsh + run: | + (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 + + - name: Bundle APP + run: pyinstaller SmartImageShrink.spec + + - name: Prepare Directory with name of the app + run: | + New-Item -ItemType Directory -Path SmartImageShrink_${{ env.VERSION }}_win + Move-Item dist\SmartImageShrink_${{ env.VERSION }}.exe SmartImageShrink_${{ env.VERSION }}_win\SmartImageShrink_${{ env.VERSION }}.exe + shell: pwsh + + - name: Zip the application to preserve permissions + shell: pwsh + run: Compress-Archive -Path SmartImageShrink_${{ env.VERSION }}_win -DestinationPath SmartImageShrink_${{ env.VERSION }}_win.zip + + - name: Upload App as Artifact + uses: actions/upload-artifact@v4 + with: + name: SmartImageShrink_${{ env.VERSION }}_win + path: SmartImageShrink_${{ env.VERSION }}_win.zip + + release: + needs: [build_macos_arm64, build_macos_x86_64x, build_windows] + runs-on: ubuntu-latest + steps: + - name: Extract version tag + run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + + - name: Download All Artifacts + uses: actions/download-artifact@v4 + with: + path: artifacts/ + merge-multiple: true + + - name: List downloaded artifacts + run: ls -R artifacts/ + + - name: Create and Upload Release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ env.VERSION }} + name: Release ${{ env.VERSION }} + files: artifacts/* + token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index c6434db..cf79e52 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,6 @@ compress_images_windows.exe /main.spec /your_script.spec /pyinstaller.txt +/SmartImageShrink_v0.4.spec +/SmartImageShrink_v0.5.spec +/save/ diff --git a/SmartImageShrink.spec b/SmartImageShrink.spec new file mode 100644 index 0000000..781bf51 --- /dev/null +++ b/SmartImageShrink.spec @@ -0,0 +1,45 @@ +# -*- mode: python ; coding: utf-8 -*- + + +a = Analysis( + ['main.py'], + pathex=[], + binaries=[], + datas=[('img', 'img')], + hiddenimports=[], + hookspath=[], + hooksconfig={}, + runtime_hooks=[], + excludes=[], + noarchive=False, + optimize=0, +) +pyz = PYZ(a.pure) + +exe = EXE( + pyz, + a.scripts, + a.binaries, + a.datas, + [], + name='SmartImageShrink_TAGVERSION', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=False, + upx_exclude=[], + runtime_tmpdir=None, + console=False, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch='OS_ARCHITECTURE', + codesign_identity='SECRET_DEVELOPER_ID', + entitlements_file=None, + icon=['img/icon.png'], +) +app = BUNDLE( + exe, + name='SmartImageShrink_TAGVERSION.app', + icon='img/icon.png', + bundle_identifier='com.presa.SmartImageShrink', +)