|
| 1 | +name: Build Wheels |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: [main] |
| 7 | + workflow_dispatch: |
| 8 | + release: |
| 9 | + types: [published] |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: build-wheels-${{ github.workflow }}-${{ github.ref || github.run_id }} |
| 16 | + cancel-in-progress: false |
| 17 | + |
| 18 | +jobs: |
| 19 | + build: |
| 20 | + name: Build ${{ matrix.os }} py${{ matrix.python-version }} |
| 21 | + runs-on: ${{ matrix.os }} |
| 22 | + timeout-minutes: 20 |
| 23 | + strategy: |
| 24 | + fail-fast: false |
| 25 | + matrix: |
| 26 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 27 | + python-version: ["3.10", "3.11", "3.12"] |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Checkout |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Setup Python |
| 34 | + uses: actions/setup-python@v5 |
| 35 | + with: |
| 36 | + python-version: ${{ matrix.python-version }} |
| 37 | + |
| 38 | + - name: Install build tooling |
| 39 | + run: | |
| 40 | + python -m pip install --upgrade pip |
| 41 | + python -m pip install build |
| 42 | +
|
| 43 | + - name: Build wheel and sdist |
| 44 | + run: python -m build |
| 45 | + |
| 46 | + - name: Upload build artifacts |
| 47 | + uses: actions/upload-artifact@v4 |
| 48 | + with: |
| 49 | + name: dist-${{ matrix.os }}-py${{ matrix.python-version }} |
| 50 | + path: dist/* |
| 51 | + if-no-files-found: error |
| 52 | + retention-days: 7 |
| 53 | + |
| 54 | + smoke-test: |
| 55 | + name: Smoke Test Built Artifacts |
| 56 | + runs-on: ubuntu-latest |
| 57 | + timeout-minutes: 15 |
| 58 | + needs: [build] |
| 59 | + |
| 60 | + steps: |
| 61 | + - name: Setup Python |
| 62 | + uses: actions/setup-python@v5 |
| 63 | + with: |
| 64 | + python-version: "3.11" |
| 65 | + |
| 66 | + - name: Download artifacts |
| 67 | + uses: actions/download-artifact@v4 |
| 68 | + with: |
| 69 | + name: dist-ubuntu-latest-py3.11 |
| 70 | + path: artifacts |
| 71 | + |
| 72 | + - name: Install wheel and run smoke test |
| 73 | + shell: bash |
| 74 | + run: | |
| 75 | + python -m venv .venv |
| 76 | + source .venv/bin/activate |
| 77 | + python -m pip install --upgrade pip |
| 78 | +
|
| 79 | + wheel_path="$(find artifacts -type f -name '*.whl' | head -n 1)" |
| 80 | + if [ -z "$wheel_path" ]; then |
| 81 | + echo "No wheel artifact found." |
| 82 | + exit 1 |
| 83 | + fi |
| 84 | + python -m pip install "$wheel_path" |
| 85 | +
|
| 86 | + sdist_path="$(find artifacts -type f -name '*.tar.gz' | head -n 1)" |
| 87 | + if [ -z "$sdist_path" ]; then |
| 88 | + echo "No sdist artifact found." |
| 89 | + exit 1 |
| 90 | + fi |
| 91 | +
|
| 92 | + temp_dir="$(mktemp -d)" |
| 93 | + cd "$temp_dir" |
| 94 | + python -c "import pyisolate; print(pyisolate.__version__)" |
| 95 | +
|
| 96 | + publish: |
| 97 | + name: Publish To PyPI (Trusted Publishing) |
| 98 | + runs-on: ubuntu-latest |
| 99 | + timeout-minutes: 10 |
| 100 | + needs: [build, smoke-test] |
| 101 | + if: >- |
| 102 | + github.repository == 'Comfy-Org/pyisolate' && |
| 103 | + github.event_name == 'release' && |
| 104 | + github.event.action == 'published' && |
| 105 | + github.event.release.tag_name != '' && |
| 106 | + startsWith(github.event.release.tag_name, 'v') |
| 107 | + permissions: |
| 108 | + id-token: write |
| 109 | + contents: read |
| 110 | + concurrency: |
| 111 | + group: publish-pypi-${{ github.event.release.tag_name }} |
| 112 | + cancel-in-progress: false |
| 113 | + |
| 114 | + steps: |
| 115 | + - name: Download artifacts |
| 116 | + uses: actions/download-artifact@v4 |
| 117 | + with: |
| 118 | + pattern: dist-* |
| 119 | + merge-multiple: false |
| 120 | + path: downloaded |
| 121 | + |
| 122 | + - name: Collect distributions |
| 123 | + shell: bash |
| 124 | + run: | |
| 125 | + mkdir -p dist |
| 126 | + find downloaded -type f \( -name "*.whl" -o -name "*.tar.gz" \) -print0 | while IFS= read -r -d '' src; do |
| 127 | + base="$(basename "$src")" |
| 128 | + dest="dist/$base" |
| 129 | + if [ -e "$dest" ]; then |
| 130 | + # Deduplicate byte-identical files produced in multiple matrix legs. |
| 131 | + if cmp -s "$src" "$dest"; then |
| 132 | + continue |
| 133 | + fi |
| 134 | + echo "Conflicting distribution filename with different content: $base" |
| 135 | + exit 1 |
| 136 | + fi |
| 137 | + cp "$src" "$dest" |
| 138 | + done |
| 139 | +
|
| 140 | + wheel_count="$(find dist -maxdepth 1 -type f -name '*.whl' | wc -l)" |
| 141 | + sdist_count="$(find dist -maxdepth 1 -type f -name '*.tar.gz' | wc -l)" |
| 142 | + if [ "$wheel_count" -eq 0 ] || [ "$sdist_count" -eq 0 ]; then |
| 143 | + echo "Expected at least one wheel and one sdist for publish." |
| 144 | + exit 1 |
| 145 | + fi |
| 146 | +
|
| 147 | + ls -l dist |
| 148 | +
|
| 149 | + - name: Publish to PyPI via OIDC |
| 150 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 151 | + with: |
| 152 | + packages-dir: dist |
0 commit comments