|
| 1 | +# ref: |
| 2 | +# - <https://github.com/pytauri/pytauri/blob/v0.8.0/.github/workflows/lint-test.yml> |
| 3 | +# - <https://github.com/pawamoy/copier-uv/blob/1.9.0/.github/workflows/ci.yml> |
| 4 | + |
| 5 | +name: Test |
| 6 | + |
| 7 | +# We only automatically run checks for PRs. |
| 8 | +# It is best to avoid direct commits to the main branch, instead make a PR for checks. |
| 9 | +on: |
| 10 | + pull_request: |
| 11 | + merge_group: # needed for merge queue |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +defaults: |
| 15 | + run: |
| 16 | + shell: bash |
| 17 | + |
| 18 | +env: |
| 19 | + project-name: "pytauri-app" |
| 20 | + repo-dir: "create-pytauri-app-repo" |
| 21 | + |
| 22 | +jobs: |
| 23 | + # don't use `pull_request.paths`, see: <https://github.com/github/docs/issues/8926#issuecomment-1635678516> |
| 24 | + changes: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + # Required permissions |
| 27 | + permissions: |
| 28 | + pull-requests: read |
| 29 | + outputs: |
| 30 | + # ref: <https://github.com/dorny/paths-filter/issues/223#issuecomment-3187277292> |
| 31 | + changed: ${{ contains(steps.filter.outputs.changes, 'paths') }} |
| 32 | + steps: |
| 33 | + - uses: actions/checkout@v4 # IMPORTANT: <https://github.com/dorny/paths-filter/issues/212#issuecomment-1960976719> |
| 34 | + - uses: dorny/paths-filter@v3 |
| 35 | + id: filter |
| 36 | + with: |
| 37 | + # TODO: fix IDE error, see <https://github.com/dorny/paths-filter/issues/225> |
| 38 | + predicate-quantifier: "every" |
| 39 | + # 👇 see: <https://github.com/PyO3/pyo3/pull/3212> |
| 40 | + base: ${{ github.event.pull_request.base.ref || github.event.merge_group.base_ref }} |
| 41 | + ref: ${{ github.event.pull_request.head.ref || github.event.merge_group.head_ref }} |
| 42 | + # 👆 |
| 43 | + filters: | |
| 44 | + paths: |
| 45 | + - "!docs/**" |
| 46 | + - "!**/*.md" |
| 47 | + - "!.github/ISSUE_TEMPLATE/**" |
| 48 | + - "!.github/dependabot.yml" |
| 49 | + - "!.github/pull_request_template.md" |
| 50 | +
|
| 51 | + test: |
| 52 | + needs: changes |
| 53 | + if: ${{ !startsWith(github.head_ref, 'releases/') && needs.changes.outputs.changed == 'true'}} |
| 54 | + runs-on: ${{ matrix.os }} |
| 55 | + strategy: |
| 56 | + fail-fast: false |
| 57 | + matrix: |
| 58 | + # NOTE: keep python version in sync with `scripts/*/build.sh` in the template |
| 59 | + python-version: ["3.13"] |
| 60 | + os: ["ubuntu-latest", "windows-latest", "macos-latest"] |
| 61 | + # 👇 See `copier.yaml` |
| 62 | + template: ["vue", "react", "svelte"] |
| 63 | + # 👆 |
| 64 | + steps: |
| 65 | + - name: Checkout |
| 66 | + uses: actions/checkout@v4 |
| 67 | + with: |
| 68 | + fetch-depth: 0 # copier dont like shallow clone |
| 69 | + path: ${{ env.repo-dir }} |
| 70 | + - name: Install Copier |
| 71 | + run: pipx install copier -v |
| 72 | + - name: Generate project from template |
| 73 | + run: | |
| 74 | + copier copy ${{ env.repo-dir }} . \ |
| 75 | + --vcs-ref HEAD --force --defaults \ |
| 76 | + --data project_name=${{ env.project-name }} \ |
| 77 | + --data template=${{ matrix.template }} |
| 78 | + shopt -s dotglob nullglob |
| 79 | + mv ${{ env.project-name }}/* ./ |
| 80 | + rmdir ${{ env.project-name }} |
| 81 | + rm -rf ${{ env.repo-dir }} |
| 82 | + - name: List files |
| 83 | + run: | |
| 84 | + echo "PWD: $PWD" |
| 85 | + echo "Files:" |
| 86 | + find . |
| 87 | + - name: Upload generated project |
| 88 | + uses: actions/upload-artifact@v4 |
| 89 | + with: |
| 90 | + name: "template-${{ matrix.template }}-${{ matrix.os }}-py${{ matrix.python-version }}" |
| 91 | + path: "./" |
| 92 | + if-no-files-found: error |
| 93 | + |
| 94 | + - name: Install uv |
| 95 | + uses: astral-sh/setup-uv@v6 |
| 96 | + with: |
| 97 | + # see: <https://docs.astral.sh/uv/guides/integration/github/> |
| 98 | + # |
| 99 | + # NOTE: For matrix jobs, we must set `python-version`, |
| 100 | + # otherwise `uv` may incorrectly use other Python versions cached in GitHub Actions. |
| 101 | + # See: <https://github.com/astral-sh/uv/pull/9454>. |
| 102 | + python-version: ${{ matrix.python-version }} |
| 103 | + # TODO: set `[tool.uv].required-version` version in template |
| 104 | + # version-file: "pyproject.toml" |
| 105 | + version: "latest" |
| 106 | + enable-cache: true |
| 107 | + activate-environment: true |
| 108 | + - name: Setup Python |
| 109 | + uses: actions/setup-python@v5 |
| 110 | + id: setup-python |
| 111 | + with: |
| 112 | + python-version: ${{ matrix.python-version }} |
| 113 | + |
| 114 | + # see: <https://github.com/pnpm/action-setup> |
| 115 | + - name: Install pnpm |
| 116 | + uses: pnpm/action-setup@v4 |
| 117 | + with: |
| 118 | + # TODO: set `packageManager` version in template |
| 119 | + version: "latest" |
| 120 | + # see: <https://github.com/actions/setup-node> |
| 121 | + - name: Install Node.js |
| 122 | + uses: actions/setup-node@v4 |
| 123 | + with: |
| 124 | + # TODO: set `engines.node` version in template |
| 125 | + # node-version-file: package.json |
| 126 | + node-version: lts/* |
| 127 | + cache: "pnpm" |
| 128 | + # TODO: We need to manually specify `cache-dependency-path`, |
| 129 | + # because the generated template doesn't include `pnpm-lock.yaml`, |
| 130 | + # which would cause `actions/setup-node` errors, see: |
| 131 | + # - <https://github.com/actions/setup-node/issues/782#issuecomment-1594677973> |
| 132 | + # - <https://github.com/actions/setup-node/issues/928> |
| 133 | + cache-dependency-path: | |
| 134 | + **/package.json |
| 135 | + **/pnpm-lock.yaml |
| 136 | +
|
| 137 | + # see: <https://github.com/dtolnay/rust-toolchain> |
| 138 | + - name: Install Rust stable |
| 139 | + uses: dtolnay/rust-toolchain@stable |
| 140 | + # with: |
| 141 | + # components: rustfmt, clippy |
| 142 | + # see: <https://github.com/swatinem/rust-cache> |
| 143 | + - name: Rust cache |
| 144 | + uses: swatinem/rust-cache@v2 |
| 145 | + with: |
| 146 | + key: py-${{ matrix.python-version }} # IMPORTANT: will link to different libpython |
| 147 | + save-if: ${{ github.event_name != 'merge_group' }} # see: <https://github.com/PyO3/pyo3/pull/3886> |
| 148 | + |
| 149 | + # see: <https://github.com/tauri-apps/tauri-action/tree/6a45448f17a006facb105cc5257b3edbc353038a?tab=readme-ov-file#usage> |
| 150 | + - name: Install system dependencies (ubuntu only) |
| 151 | + if: matrix.os == 'ubuntu-latest' |
| 152 | + run: | |
| 153 | + sudo apt-get update |
| 154 | + sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf |
| 155 | + - name: Install project dependencies |
| 156 | + run: | |
| 157 | + pnpm install |
| 158 | + uv sync |
| 159 | +
|
| 160 | + - name: Test Building (Windows) |
| 161 | + if: matrix.os == 'windows-latest' |
| 162 | + shell: pwsh |
| 163 | + run: | |
| 164 | + scripts\windows\download-py.ps1 |
| 165 | + scripts\windows\build.ps1 |
| 166 | + - name: Test Building (Linux) |
| 167 | + if: matrix.os == 'ubuntu-latest' |
| 168 | + shell: bash |
| 169 | + run: | |
| 170 | + chmod +x scripts/linux/*.sh |
| 171 | + scripts/linux/download-py.sh |
| 172 | + scripts/linux/build.sh |
| 173 | + - name: Test Building (macOS) |
| 174 | + if: matrix.os == 'macos-latest' |
| 175 | + shell: bash |
| 176 | + run: | |
| 177 | + chmod +x scripts/macos/*.sh |
| 178 | + scripts/macos/download-py.sh |
| 179 | + scripts/macos/build.sh |
| 180 | +
|
| 181 | + - name: Upload build artifacts |
| 182 | + uses: actions/upload-artifact@v4 |
| 183 | + with: |
| 184 | + name: "build-${{ matrix.os }}-${{ matrix.template }}-py${{ matrix.python-version }}" |
| 185 | + # ``` |
| 186 | + # target/bundle-release/bundle/deb/pytauri-app_0.1.0_amd64.deb |
| 187 | + # target/{profile}/bundle/{bundle_type}/{product_name}_{version}_{arch}.{bundle_ext} |
| 188 | + # ``` |
| 189 | + # see: <https://github.com/pytauri/example-nicegui-app/releases> |
| 190 | + path: | |
| 191 | + target/*/bundle/*/*.deb |
| 192 | + target/*/bundle/*/*.rpm |
| 193 | + target/*/bundle/*/*.AppImage |
| 194 | + target/*/bundle/*/*.msi |
| 195 | + target/*/bundle/*/*.exe |
| 196 | + target/*/bundle/*/*.dmg |
| 197 | + target/*/bundle/*/*.app/ |
| 198 | + if-no-files-found: error |
| 199 | + |
| 200 | + # https://github.com/marketplace/actions/alls-green#why |
| 201 | + lint-test-all-green: # This job does nothing and is only used for the branch protection |
| 202 | + if: always() # IMPORTANT: mandatory |
| 203 | + needs: |
| 204 | + - changes |
| 205 | + - test |
| 206 | + runs-on: ubuntu-latest |
| 207 | + steps: |
| 208 | + - name: Decide whether the needed jobs succeeded or failed |
| 209 | + uses: re-actors/alls-green@release/v1 |
| 210 | + with: |
| 211 | + jobs: ${{ toJSON(needs) }} |
| 212 | + allowed-skips: "test" |
0 commit comments