|
| 1 | +name: Publish to PyPI |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + # ========================================================================= |
| 10 | + # Job 1: Run ALL tests (including API tests) |
| 11 | + # ========================================================================= |
| 12 | + test: |
| 13 | + runs-on: ${{ matrix.os }} |
| 14 | + strategy: |
| 15 | + fail-fast: true # Stop immediately if any test fails |
| 16 | + matrix: |
| 17 | + os: [ubuntu-latest, windows-latest] |
| 18 | + python-version: ['3.10', '3.11', '3.12'] |
| 19 | + |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Set up Python ${{ matrix.python-version }} |
| 24 | + uses: actions/setup-python@v5 |
| 25 | + with: |
| 26 | + python-version: ${{ matrix.python-version }} |
| 27 | + |
| 28 | + - name: Install dependencies |
| 29 | + run: | |
| 30 | + python -m pip install --upgrade pip |
| 31 | + pip install -r requirements.txt |
| 32 | + pip install pytest pytest-cov |
| 33 | +
|
| 34 | + - name: Run ALL tests (library, API, scripts, integration) |
| 35 | + run: | |
| 36 | + python -m pytest tests/ -v --tb=short |
| 37 | + |
| 38 | + - name: Verify package imports |
| 39 | + run: | |
| 40 | + python -c "from src.core.flow_model import TwoPhaseFlowModel; print('Import OK')" |
| 41 | +
|
| 42 | + # ========================================================================= |
| 43 | + # Job 2: Build the package (only if ALL tests pass) |
| 44 | + # ========================================================================= |
| 45 | + build: |
| 46 | + needs: test |
| 47 | + runs-on: ubuntu-latest |
| 48 | + |
| 49 | + steps: |
| 50 | + - uses: actions/checkout@v4 |
| 51 | + |
| 52 | + - name: Set up Python |
| 53 | + uses: actions/setup-python@v5 |
| 54 | + with: |
| 55 | + python-version: '3.12' |
| 56 | + |
| 57 | + - name: Install build tools |
| 58 | + run: | |
| 59 | + python -m pip install --upgrade pip |
| 60 | + pip install build twine |
| 61 | +
|
| 62 | + - name: Build package |
| 63 | + run: python -m build |
| 64 | + |
| 65 | + - name: Verify package |
| 66 | + run: twine check dist/* |
| 67 | + |
| 68 | + - name: Upload artifacts |
| 69 | + uses: actions/upload-artifact@v4 |
| 70 | + with: |
| 71 | + name: python-package-distributions |
| 72 | + path: dist/ |
| 73 | + |
| 74 | + # ========================================================================= |
| 75 | + # Job 3: Publish directly to PyPI (no TestPyPI) |
| 76 | + # ========================================================================= |
| 77 | + publish: |
| 78 | + needs: build |
| 79 | + runs-on: ubuntu-latest |
| 80 | + |
| 81 | + environment: |
| 82 | + name: pypi |
| 83 | + url: https://pypi.org/p/pydebflow |
| 84 | + |
| 85 | + permissions: |
| 86 | + id-token: write |
| 87 | + |
| 88 | + steps: |
| 89 | + - name: Download artifacts |
| 90 | + uses: actions/download-artifact@v4 |
| 91 | + with: |
| 92 | + name: python-package-distributions |
| 93 | + path: dist/ |
| 94 | + |
| 95 | + - name: Publish to PyPI |
| 96 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 97 | + with: |
| 98 | + password: ${{ secrets.PYPI_API_TOKEN }} |
0 commit comments