|
| 1 | +name: Test, Release, and Publish |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - 'dev-create-release' |
| 7 | + # tags: |
| 8 | + # - 'v*' |
| 9 | + workflow_dispatch: # allows manual triggering of the workflow from the GitHub Actions tab |
| 10 | + |
| 11 | +jobs: |
| 12 | + # 1. TEST JOB: Runs Pytest |
| 13 | + test: |
| 14 | + name: Run Unit Tests |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Checkout code |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Set up Python |
| 21 | + uses: actions/setup-python@v5 |
| 22 | + with: |
| 23 | + python-version: '3.8.12' # to match pyproject.tom exactly |
| 24 | + |
| 25 | + - name: Install dependencies |
| 26 | + run: | |
| 27 | + python -m pip install --upgrade pip setuptools wheel |
| 28 | + # Install the package in editable mode with all dependencies |
| 29 | + pip install -e ".[dev]" |
| 30 | +
|
| 31 | + - name: Run Pytest |
| 32 | + run: pytest |
| 33 | + |
| 34 | + # 2. RELEASE JOB: Only runs if 'test' passes |
| 35 | + release: |
| 36 | + name: Create GitHub Release |
| 37 | + needs: test |
| 38 | + runs-on: ubuntu-latest |
| 39 | + permissions: |
| 40 | + contents: write |
| 41 | + steps: |
| 42 | + - name: Checkout code |
| 43 | + uses: actions/checkout@v4 |
| 44 | + |
| 45 | + - name: Create Release |
| 46 | + uses: softprops/action-gh-release@v2 |
| 47 | + with: |
| 48 | + # tag_name: ${{ github.ref_name }} |
| 49 | + tag_name: dev-build-${{ github.run_number }} # Use a unique tag for each release |
| 50 | + # name: Release ${{ github.ref_name }} |
| 51 | + name: Dev Build ${{ github.run_number }} |
| 52 | + # body: "Automated release for version ${{ github.ref_name }} (Tests Passed)" |
| 53 | + body: "Automated dev release from branch 'dev-create-release' (Commit: ${{ github.sha }})" |
| 54 | + draft: false |
| 55 | + # prerelease: false |
| 56 | + prerelease: true # Mark as pre-release since it's from a dev branch |
| 57 | + |
| 58 | + # 3. PUBLISH JOB: Only runs if 'release' passes |
| 59 | + publish: |
| 60 | + name: Build and Publish to PyPI |
| 61 | + needs: release |
| 62 | + runs-on: ubuntu-latest |
| 63 | + environment: pypi |
| 64 | + permissions: |
| 65 | + id-token: write |
| 66 | + steps: |
| 67 | + - name: Checkout code |
| 68 | + uses: actions/checkout@v4 |
| 69 | + |
| 70 | + - name: Set up Python |
| 71 | + uses: actions/setup-python@v5 |
| 72 | + with: |
| 73 | + python-version: '3.8.12' # to match pyproject.tom exactly |
| 74 | + |
| 75 | + - name: Install build tools |
| 76 | + run: pip install build |
| 77 | + |
| 78 | + - name: Build binary wheel and source tarball |
| 79 | + # Note: This will still use the version in pyproject.toml |
| 80 | + # To test PyPI repeatedly, you'd need to change the version in the file |
| 81 | + run: python -m build |
| 82 | + |
| 83 | + - name: Publish to PyPI |
| 84 | + # We use 'continue-on-error' for dev branch PyPI pushes |
| 85 | + # because PyPI will reject duplicate versions. |
| 86 | + continue-on-error: true |
| 87 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments