|
| 1 | +# See: |
| 2 | +# - <https://github.com/tauri-apps/tauri-action> |
| 3 | +# - <https://pytauri.github.io/pytauri/latest/usage/tutorial/build-standalone/> |
| 4 | + |
| 5 | +name: "publish" |
| 6 | + |
| 7 | +on: |
| 8 | + # Manual trigger |
| 9 | + workflow_dispatch: |
| 10 | + # On push to `release` branch |
| 11 | + push: |
| 12 | + branches: |
| 13 | + - release |
| 14 | + |
| 15 | +defaults: |
| 16 | + run: |
| 17 | + shell: bash |
| 18 | + |
| 19 | +jobs: |
| 20 | + publish-tauri: |
| 21 | + permissions: |
| 22 | + contents: write # required for creating github releases |
| 23 | + strategy: |
| 24 | + fail-fast: false |
| 25 | + matrix: |
| 26 | + include: |
| 27 | + - platform: "macos-14" # for Intel based macs. |
| 28 | + target: "x86_64-apple-darwin" |
| 29 | + - platform: "macos-14" # for Arm based macs (M1 and above). |
| 30 | + target: "aarch64-apple-darwin" |
| 31 | + - platform: "ubuntu-22.04" |
| 32 | + target: "x86_64-unknown-linux-gnu" |
| 33 | + - platform: "ubuntu-22.04-arm" |
| 34 | + target: "aarch64-unknown-linux-gnu" |
| 35 | + - platform: "windows-2022" |
| 36 | + target: "x86_64-pc-windows-msvc" |
| 37 | + - platform: "windows-11-arm" |
| 38 | + target: "aarch64-pc-windows-msvc" |
| 39 | + |
| 40 | + runs-on: ${{ matrix.platform }} |
| 41 | + steps: |
| 42 | + - uses: actions/checkout@v4 |
| 43 | + |
| 44 | + - name: Install system dependencies (ubuntu only) |
| 45 | + if: runner.os == 'Linux' |
| 46 | + run: | |
| 47 | + sudo apt-get update |
| 48 | + sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf |
| 49 | +
|
| 50 | + - name: Install Rust stable |
| 51 | + uses: dtolnay/rust-toolchain@stable |
| 52 | + with: |
| 53 | + targets: ${{ matrix.target }} |
| 54 | + - name: Rust cache |
| 55 | + uses: swatinem/rust-cache@v2 |
| 56 | + |
| 57 | + - name: Install uv |
| 58 | + uses: astral-sh/setup-uv@v6 |
| 59 | + with: |
| 60 | + enable-cache: true |
| 61 | + # version-file: "pyproject.toml" |
| 62 | + |
| 63 | + - name: Install pnpm |
| 64 | + uses: pnpm/action-setup@v4 |
| 65 | + with: |
| 66 | + # Optional: when there is a `packageManager` field in the `package.json` |
| 67 | + version: "latest" |
| 68 | + - name: Install Node.js |
| 69 | + uses: actions/setup-node@v4 |
| 70 | + with: |
| 71 | + # Or: `node-version-file: package.json` |
| 72 | + node-version: lts/* |
| 73 | + cache: "pnpm" |
| 74 | + |
| 75 | + - name: Install project dependencies |
| 76 | + run: | |
| 77 | + pnpm install |
| 78 | +
|
| 79 | + # See: |
| 80 | + # - <https://github.com/astral-sh/python-build-standalone/releases> |
| 81 | + # - <https://raw.githubusercontent.com/astral-sh/python-build-standalone/latest-release/latest-release.json> |
| 82 | + # - <https://gregoryszorc.com/docs/python-build-standalone/main/running.html#obtaining-distributions> |
| 83 | + - name: Download python-build-standalone |
| 84 | + env: |
| 85 | + PYTHON_VERSION: "3.13.7" # update this by yourself |
| 86 | + TAG: "20250828" # update this by yourself |
| 87 | + TARGET: ${{ matrix.target }} |
| 88 | + run: | |
| 89 | + url="https://github.com/astral-sh/python-build-standalone/releases/download/${TAG}/cpython-${PYTHON_VERSION}+${TAG}-${TARGET}-install_only_stripped.tar.gz" |
| 90 | + DEST_DIR="src-tauri/pyembed" |
| 91 | +
|
| 92 | + mkdir "$DEST_DIR" |
| 93 | + curl -L "$url" | tar -xz -C "$DEST_DIR" |
| 94 | +
|
| 95 | + # ref: <https://github.com/pytauri/pytauri/issues/99#issuecomment-2704556726> |
| 96 | + if [[ "${{ runner.os }}" == "macOS" ]]; then |
| 97 | + python_major_minor="${PYTHON_VERSION%.*}" # "3.13.7" -> "3.13" |
| 98 | + install_name_tool -id "@rpath/libpython${python_major_minor}.dylib" "$DEST_DIR/python/lib/libpython${python_major_minor}.dylib" |
| 99 | + fi |
| 100 | +
|
| 101 | + - name: Install the project into the embedded python environment |
| 102 | + env: |
| 103 | + PYTAURI_STANDALONE: 1 # see your `setup.py` |
| 104 | + PYTHON_PATH: ${{ runner.os == 'Windows' && './src-tauri/pyembed/python/python.exe' || './src-tauri/pyembed/python/bin/python3' }} |
| 105 | + run: | |
| 106 | + uv pip install \ |
| 107 | + --exact \ |
| 108 | + --compile-bytecode \ |
| 109 | + --python=${{ env.PYTHON_PATH }} \ |
| 110 | + ./src-tauri |
| 111 | +
|
| 112 | + # Set build environment variables, see: |
| 113 | + # <https://pytauri.github.io/pytauri/latest/usage/tutorial/build-standalone/#build-and-bundle> |
| 114 | + |
| 115 | + - name: Set build environment variables (windows) |
| 116 | + if: runner.os == 'Windows' |
| 117 | + shell: pwsh |
| 118 | + run: | |
| 119 | + $PYO3_PYTHON = (Resolve-Path -LiteralPath ".\src-tauri\pyembed\python\python.exe").Path |
| 120 | + echo "PYO3_PYTHON=$PYO3_PYTHON" >> $env:GITHUB_ENV |
| 121 | +
|
| 122 | + - name: Set build environment variables (linux) |
| 123 | + if: runner.os == 'Linux' |
| 124 | + shell: bash |
| 125 | + env: |
| 126 | + # `example-pytauri-app-react` is your app `productName` in `tauri.conf.json` |
| 127 | + PRODUCT_NAME: "example-pytauri-app-react" |
| 128 | + run: | |
| 129 | + PYO3_PYTHON=$(realpath ./src-tauri/pyembed/python/bin/python3) |
| 130 | + RUSTFLAGS=" \ |
| 131 | + -C link-arg=-Wl,-rpath,\$ORIGIN/../lib/$PRODUCT_NAME/lib \ |
| 132 | + -L $(realpath ./src-tauri/pyembed/python/lib)" |
| 133 | +
|
| 134 | + echo "PYO3_PYTHON=$PYO3_PYTHON" >> $GITHUB_ENV |
| 135 | + echo "RUSTFLAGS=$RUSTFLAGS" >> $GITHUB_ENV |
| 136 | +
|
| 137 | + - name: Set build environment variables (macos) |
| 138 | + if: runner.os == 'macOS' |
| 139 | + shell: bash |
| 140 | + run: | |
| 141 | + PYO3_PYTHON=$(realpath ./src-tauri/pyembed/python/bin/python3) |
| 142 | + RUSTFLAGS=" \ |
| 143 | + -C link-arg=-Wl,-rpath,@executable_path/../Resources/lib \ |
| 144 | + -L $(realpath ./src-tauri/pyembed/python/lib)" |
| 145 | +
|
| 146 | + echo "PYO3_PYTHON=$PYO3_PYTHON" >> $GITHUB_ENV |
| 147 | + echo "RUSTFLAGS=$RUSTFLAGS" >> $GITHUB_ENV |
| 148 | +
|
| 149 | + - name: Build and bundle the app |
| 150 | + uses: tauri-apps/tauri-action@v0 |
| 151 | + env: |
| 152 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 153 | + with: |
| 154 | + tagName: app-v__VERSION__ # the action automatically replaces \_\_VERSION\_\_ with the app version. |
| 155 | + releaseName: "App v__VERSION__" |
| 156 | + releaseBody: "See the assets to download this version and install." |
| 157 | + releaseDraft: true |
| 158 | + includeDebug: true # Optional, disable to speed up the build |
| 159 | + args: '--target=${{ matrix.target }} --config="src-tauri/tauri.bundle.json" --verbose' |
0 commit comments