diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 601cab6..1274d16 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,14 +2,15 @@ name: Build on: push: - tags: - - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 + # tags: + # - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 jobs: createrelease: name: Create Release runs-on: [ubuntu-latest] + if: startsWith(github.ref, 'refs/tags/v') steps: - uses: actions/checkout@v3 with: @@ -52,18 +53,43 @@ jobs: pyinstaller sticker_convert.spec cd dist Compress-Archive -Path sticker-convert -DestinationPath sticker-convert-windows.zip - OUT_FILE_NAME: sticker-convert-windows.zip + OUT_FILE_NAME: ./dist/sticker-convert-windows.zip - os: macos-11 TARGET: macos CMD_BUILD: | python -m pip install --upgrade pip - pip install wheel - pip install -r requirements-build.txt - pyinstaller sticker_convert.spec - cp run_me_first.command ./dist + python -m venv venv + source ./venv/bin/activate + pip install wheel delocate pyinstaller~=5.13.2 + pip install -r requirements-src.txt + mkdir wheel_arm + mkdir wheel_x64 + mkdir wheel_universal2 + pip download -r requirements-bin.txt --platform macosx_11_0_arm64 --only-binary=:all: -d wheel_arm + pip download -r requirements-bin.txt --platform macosx_11_0_x86_64 --only-binary=:all: -d wheel_x64 + python ./scripts/delocate-fuse-dir.py ./wheel_arm ./wheel_x64 ./wheel_universal2 + pip install ./wheel_universal2/*.whl + + SC_TARGET_ARCH=x86_64 pyinstaller sticker_convert.spec + cp ./scripts/run_me_first.command ./dist cd dist/ zip -r9 sticker-convert-macos-x86_64.zip sticker-convert.app run_me_first.command - OUT_FILE_NAME: sticker-convert-macos-x86_64.zip + cd ../ + + SC_TARGET_ARCH=arm64 pyinstaller sticker_convert.spec + cp ./scripts/run_me_first.command ./dist + cd dist/ + zip -r9 sticker-convert-macos-arm64.zip sticker-convert.app run_me_first.command + cd ../ + + SC_TARGET_ARCH=universal2 pyinstaller sticker_convert.spec + cp ./scripts/run_me_first.command ./dist + cd dist/ + zip -r9 sticker-convert-macos-universal2.zip sticker-convert.app run_me_first.command + OUT_FILE_NAME: | + ./dist/sticker-convert-macos-x86_64.zip + ./dist/sticker-convert-macos-arm64.zip + ./dist/sticker-convert-macos-universal2.zip - os: ubuntu-20.04 TARGET: linux CMD_BUILD: | @@ -87,7 +113,7 @@ jobs: chmod +x sticker-convert-x86_64.AppImage mkdir dist mv ./sticker-convert-x86_64.AppImage ./dist/sticker-convert-x86_64.AppImage - OUT_FILE_NAME: sticker-convert-x86_64.AppImage + OUT_FILE_NAME: ./dist/sticker-convert-x86_64.AppImage steps: - uses: actions/checkout@v3 with: @@ -106,10 +132,11 @@ jobs: - name: Upload Release Asset id: upload-release-asset uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/v') env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - files: dist/${{ matrix.OUT_FILE_NAME}} + files: dist/${{ matrix.OUT_FILE_NAME }} build-docker: name: Build Docker image and push @@ -146,6 +173,7 @@ jobs: - name: Build and push Docker image uses: docker/build-push-action@v4 + if: startsWith(github.ref, 'refs/tags/v') with: context: . push: true @@ -156,6 +184,7 @@ jobs: name: Upload to pypi needs: [build-wheel, build-binary] runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/v') steps: - uses: actions/download-artifact@v3 with: diff --git a/Dockerfile b/Dockerfile index e5184fe..90cbb8c 100755 --- a/Dockerfile +++ b/Dockerfile @@ -46,7 +46,7 @@ RUN apt purge -y curl wget gpg git && \ apt autoremove --yes && \ rm -rf /var/lib/{apt,dpkg,cache,log}/ -COPY startapp.sh /startapp.sh +COPY ./scripts/startapp.sh /startapp.sh COPY ./src /app/ RUN chmod -R 777 /app diff --git a/requirements-bin.txt b/requirements-bin.txt new file mode 100644 index 0000000..79fd173 --- /dev/null +++ b/requirements-bin.txt @@ -0,0 +1,17 @@ +apngasm_python~=1.0.7 +av~=10.0.0 +beautifulsoup4~=4.12.2 +browser-cookie3~=0.19.1 +imageio~=2.31.3 +memory-tempfile~=2.2.3 +mergedeep~=1.3.4 +Pillow~=10.0.0 +pyoxipng~=8.0.0 +python-telegram-bot~=20.5 +requests~=2.31.0 +rlottie_python~=1.1.5 +selenium~=4.12.0 +signalstickers-client~=3.3.0 +tqdm~=4.66.1 +ttkbootstrap-fork-laggykiller~=1.5.1 +webp~=0.2.0 \ No newline at end of file diff --git a/requirements-src.txt b/requirements-src.txt new file mode 100644 index 0000000..c4b515d --- /dev/null +++ b/requirements-src.txt @@ -0,0 +1 @@ +lottie~=0.7.0 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 5249e6b..beb5697 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,18 +1,2 @@ -apngasm_python~=1.0.4 -av~=10.0.0 -beautifulsoup4~=4.12.2 -browser-cookie3~=0.19.1 -imageio~=2.31.3 -lottie~=0.7.0 -memory-tempfile~=2.2.3 -mergedeep~=1.3.4 -Pillow~=10.0.0 -pyoxipng~=8.0.0 -python-telegram-bot~=20.5 -requests~=2.31.0 -rlottie_python~=1.1.4 -selenium~=4.12.0 -signalstickers-client~=3.3.0 -tqdm~=4.66.1 -ttkbootstrap-fork-laggykiller~=1.5.1 -webp~=0.1.8 \ No newline at end of file +-r requirements-src.txt +-r requirements-bin.txt \ No newline at end of file diff --git a/scripts/delocate-fuse-dir.py b/scripts/delocate-fuse-dir.py new file mode 100755 index 0000000..b9d76e6 --- /dev/null +++ b/scripts/delocate-fuse-dir.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +# A script for creating universal2 wheels from x86_64 and arm64 wheels +# Used for creating macOS application + +import sys +import os +import shutil +import subprocess + +in_dir1 = sys.argv[1] +in_dir2 = sys.argv[2] +out_dir = sys.argv[3] + +def search_wheel_in_dir(package, dir): + for i in os.listdir(dir): + if i.startswith(package): + return i + +def copy_if_universal(wheel_name, in_dir, out_dir): + if wheel_name.endswith('universal2.whl') or wheel_name.endswith('any.whl'): + src_path = os.path.join(in_dir, wheel_name) + dst_path = os.path.join( + out_dir, + wheel_name + .replace('x86_64', 'universal2') + .replace('arm64', 'universal2') + ) + + shutil.copy(src_path, dst_path) + return True + else: + return False + +for wheel_name_1 in os.listdir(in_dir1): + package = wheel_name_1.split('-')[0] + wheel_name_2 = search_wheel_in_dir(package, in_dir2) + if copy_if_universal(wheel_name_1, in_dir1, out_dir): + continue + if copy_if_universal(wheel_name_2, in_dir2, out_dir): + continue + + wheel_path_1 = os.path.join(in_dir1, wheel_name_1) + wheel_path_2 = os.path.join(in_dir2, wheel_name_2) + subprocess.run(['delocate-fuse', wheel_path_1, wheel_path_2, '-w', out_dir]) \ No newline at end of file diff --git a/run_me_first.command b/scripts/run_me_first.command similarity index 100% rename from run_me_first.command rename to scripts/run_me_first.command diff --git a/startapp.sh b/scripts/startapp.sh similarity index 100% rename from startapp.sh rename to scripts/startapp.sh diff --git a/sticker_convert.spec b/sticker_convert.spec index 84ee4c7..db3bbcf 100755 --- a/sticker_convert.spec +++ b/sticker_convert.spec @@ -22,6 +22,8 @@ else: proot = os.path.dirname(importlib.import_module('rlottie_python').__file__) datas.append((os.path.join(proot, rlottie_dll), 'rlottie_python/')) +target_arch = os.getenv('SC_TARGET_ARCH') + a = Analysis( ['src/sticker_convert/__main__.py'], pathex=['src/sticker_convert'], @@ -52,7 +54,7 @@ exe = EXE( console=True, disable_windowed_traceback=False, argv_emulation=False, - target_arch=None, + target_arch=target_arch, codesign_identity=None, entitlements_file=None, icon='./src/sticker_convert/resources/appicon.ico' @@ -71,4 +73,4 @@ coll = COLLECT( app = BUNDLE(coll, name=f'sticker-convert.app', icon='./src/sticker_convert/resources/appicon.icns', - bundle_identifier=None) \ No newline at end of file + bundle_identifier=None)