|
| 1 | +name: Build & Publish flexfoil Python wheels |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "pypi-v*" |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + publish: |
| 10 | + description: "Publish to PyPI" |
| 11 | + type: boolean |
| 12 | + default: false |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + |
| 17 | +jobs: |
| 18 | + # ---------- Build the frontend (shared artifact) ---------- |
| 19 | + build-frontend: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v5 |
| 23 | + |
| 24 | + - uses: dtolnay/rust-toolchain@stable |
| 25 | + |
| 26 | + - name: Install wasm-pack |
| 27 | + run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh |
| 28 | + |
| 29 | + - name: Build WASM |
| 30 | + run: | |
| 31 | + cd crates/rustfoil-wasm |
| 32 | + wasm-pack build --target web --release --out-dir ../../pkg |
| 33 | +
|
| 34 | + - uses: actions/setup-node@v5 |
| 35 | + with: |
| 36 | + node-version: 20 |
| 37 | + cache: npm |
| 38 | + cache-dependency-path: flexfoil-ui/package-lock.json |
| 39 | + |
| 40 | + - name: Build frontend |
| 41 | + run: | |
| 42 | + cd flexfoil-ui |
| 43 | + npm ci |
| 44 | + NODE_OPTIONS="--max-old-space-size=4096" npx vite build |
| 45 | +
|
| 46 | + - name: Upload frontend dist |
| 47 | + uses: actions/upload-artifact@v4 |
| 48 | + with: |
| 49 | + name: frontend-dist |
| 50 | + path: flexfoil-ui/dist/ |
| 51 | + |
| 52 | + # ---------- Build platform wheels ---------- |
| 53 | + build-wheels: |
| 54 | + needs: build-frontend |
| 55 | + strategy: |
| 56 | + fail-fast: false |
| 57 | + matrix: |
| 58 | + include: |
| 59 | + - os: ubuntu-latest |
| 60 | + target: x86_64-unknown-linux-gnu |
| 61 | + - os: ubuntu-latest |
| 62 | + target: aarch64-unknown-linux-gnu |
| 63 | + - os: macos-14 |
| 64 | + target: aarch64-apple-darwin |
| 65 | + - os: macos-14 |
| 66 | + target: x86_64-apple-darwin |
| 67 | + - os: windows-latest |
| 68 | + target: x86_64-pc-windows-msvc |
| 69 | + |
| 70 | + runs-on: ${{ matrix.os }} |
| 71 | + steps: |
| 72 | + - uses: actions/checkout@v5 |
| 73 | + with: |
| 74 | + sparse-checkout: | |
| 75 | + crates |
| 76 | + packages |
| 77 | + Cargo.toml |
| 78 | + Cargo.lock |
| 79 | +
|
| 80 | + - name: Download frontend dist |
| 81 | + uses: actions/download-artifact@v4 |
| 82 | + with: |
| 83 | + name: frontend-dist |
| 84 | + path: packages/flexfoil-python/src/flexfoil/_static |
| 85 | + |
| 86 | + - uses: actions/setup-python@v5 |
| 87 | + with: |
| 88 | + python-version: "3.11" |
| 89 | + |
| 90 | + - name: Build wheel |
| 91 | + uses: PyO3/maturin-action@v1 |
| 92 | + with: |
| 93 | + target: ${{ matrix.target }} |
| 94 | + args: --release --out dist |
| 95 | + working-directory: packages/flexfoil-python |
| 96 | + manylinux: auto |
| 97 | + |
| 98 | + - name: Upload wheel |
| 99 | + uses: actions/upload-artifact@v4 |
| 100 | + with: |
| 101 | + name: wheel-${{ matrix.target }} |
| 102 | + path: packages/flexfoil-python/dist/*.whl |
| 103 | + |
| 104 | + # ---------- Build sdist ---------- |
| 105 | + build-sdist: |
| 106 | + needs: build-frontend |
| 107 | + runs-on: ubuntu-latest |
| 108 | + steps: |
| 109 | + - uses: actions/checkout@v5 |
| 110 | + |
| 111 | + - name: Download frontend dist |
| 112 | + uses: actions/download-artifact@v4 |
| 113 | + with: |
| 114 | + name: frontend-dist |
| 115 | + path: packages/flexfoil-python/src/flexfoil/_static |
| 116 | + |
| 117 | + - name: Build sdist |
| 118 | + uses: PyO3/maturin-action@v1 |
| 119 | + with: |
| 120 | + command: sdist |
| 121 | + args: --out dist |
| 122 | + working-directory: packages/flexfoil-python |
| 123 | + |
| 124 | + - name: Upload sdist |
| 125 | + uses: actions/upload-artifact@v4 |
| 126 | + with: |
| 127 | + name: sdist |
| 128 | + path: packages/flexfoil-python/dist/*.tar.gz |
| 129 | + |
| 130 | + # ---------- Publish to Test PyPI ---------- |
| 131 | + publish-test: |
| 132 | + needs: [build-wheels, build-sdist] |
| 133 | + runs-on: ubuntu-latest |
| 134 | + if: github.event_name == 'workflow_dispatch' |
| 135 | + environment: |
| 136 | + name: testpypi |
| 137 | + url: https://test.pypi.org/p/flexfoil |
| 138 | + permissions: |
| 139 | + id-token: write |
| 140 | + steps: |
| 141 | + - name: Download wheels |
| 142 | + uses: actions/download-artifact@v4 |
| 143 | + with: |
| 144 | + path: dist |
| 145 | + pattern: wheel-* |
| 146 | + merge-multiple: true |
| 147 | + |
| 148 | + - name: Download sdist |
| 149 | + uses: actions/download-artifact@v4 |
| 150 | + with: |
| 151 | + name: sdist |
| 152 | + path: dist |
| 153 | + |
| 154 | + - name: Publish to Test PyPI |
| 155 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 156 | + with: |
| 157 | + repository-url: https://test.pypi.org/legacy/ |
| 158 | + packages-dir: dist/ |
| 159 | + |
| 160 | + # ---------- Publish to PyPI ---------- |
| 161 | + publish: |
| 162 | + needs: [build-wheels, build-sdist] |
| 163 | + runs-on: ubuntu-latest |
| 164 | + if: startsWith(github.ref, 'refs/tags/pypi-v') || (github.event_name == 'workflow_dispatch' && inputs.publish) |
| 165 | + environment: |
| 166 | + name: pypi |
| 167 | + url: https://pypi.org/p/flexfoil |
| 168 | + permissions: |
| 169 | + id-token: write |
| 170 | + steps: |
| 171 | + - name: Download wheels |
| 172 | + uses: actions/download-artifact@v4 |
| 173 | + with: |
| 174 | + path: dist |
| 175 | + pattern: wheel-* |
| 176 | + merge-multiple: true |
| 177 | + |
| 178 | + - name: Download sdist |
| 179 | + uses: actions/download-artifact@v4 |
| 180 | + with: |
| 181 | + name: sdist |
| 182 | + path: dist |
| 183 | + |
| 184 | + - name: Publish to PyPI |
| 185 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 186 | + with: |
| 187 | + packages-dir: dist/ |
0 commit comments