|
| 1 | +name: Main Workflow |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +permissions: |
| 9 | + id-token: write |
| 10 | + contents: write |
| 11 | + pull-requests: write |
| 12 | + issues: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + setup: |
| 16 | + name: Setup Environment |
| 17 | + runs-on: ubuntu-latest |
| 18 | + defaults: |
| 19 | + run: |
| 20 | + shell: bash |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + fetch-depth: 0 # Required for semantic-release |
| 25 | + |
| 26 | + - name: Set up python |
| 27 | + uses: actions/setup-python@v4 |
| 28 | + with: |
| 29 | + python-version: 3.11 |
| 30 | + |
| 31 | + - name: Configure Poetry |
| 32 | + uses: snok/install-poetry@v1 |
| 33 | + with: |
| 34 | + version: 1.7.1 |
| 35 | + virtualenvs-create: true |
| 36 | + virtualenvs-in-project: true |
| 37 | + |
| 38 | + - name: Cache virtualenv |
| 39 | + uses: actions/cache@v4 |
| 40 | + with: |
| 41 | + path: ./.venv |
| 42 | + key: ${{ runner.os }}-venv-${{ hashFiles('**/poetry.lock') }} |
| 43 | + |
| 44 | + - name: Install dependencies |
| 45 | + run: | |
| 46 | + poetry install |
| 47 | + |
| 48 | + - name: Upload workspace |
| 49 | + uses: actions/upload-artifact@v4 |
| 50 | + with: |
| 51 | + name: workspace |
| 52 | + include-hidden-files: true |
| 53 | + path: | |
| 54 | + . |
| 55 | + !.git |
| 56 | + !.github |
| 57 | + !node_modules |
| 58 | + !.venv |
| 59 | +
|
| 60 | + verify: |
| 61 | + needs: setup |
| 62 | + runs-on: ubuntu-latest |
| 63 | + strategy: |
| 64 | + matrix: |
| 65 | + task: [lint] |
| 66 | + include: |
| 67 | + - task: lint |
| 68 | + command: make lint |
| 69 | + name: ${{ matrix.task }} |
| 70 | + steps: |
| 71 | + - name: Download workspace |
| 72 | + uses: actions/download-artifact@v4 |
| 73 | + with: |
| 74 | + name: workspace |
| 75 | + |
| 76 | + - name: Set up python |
| 77 | + uses: actions/setup-python@v4 |
| 78 | + with: |
| 79 | + python-version: 3.11 |
| 80 | + |
| 81 | + - name: Configure Poetry |
| 82 | + uses: snok/install-poetry@v1 |
| 83 | + with: |
| 84 | + version: 1.7.1 |
| 85 | + virtualenvs-create: true |
| 86 | + virtualenvs-in-project: true |
| 87 | + |
| 88 | + - name: Cache virtualenv |
| 89 | + uses: actions/cache@v4 |
| 90 | + with: |
| 91 | + path: ./.venv |
| 92 | + key: ${{ runner.os }}-venv-${{ hashFiles('**/poetry.lock') }} |
| 93 | + |
| 94 | + - name: Run ${{ matrix.task }} |
| 95 | + run: | |
| 96 | + poetry run ${{ matrix.command }} |
| 97 | +
|
| 98 | + test: |
| 99 | + needs: setup |
| 100 | + runs-on: ubuntu-latest |
| 101 | + strategy: |
| 102 | + matrix: |
| 103 | + python-version: ['3.9', '3.10', '3.11', '3.12', '3.13'] |
| 104 | + name: Test Python ${{ matrix.python-version }} |
| 105 | + steps: |
| 106 | + - name: Download workspace |
| 107 | + uses: actions/download-artifact@v4 |
| 108 | + with: |
| 109 | + name: workspace |
| 110 | + |
| 111 | + - name: Set up python ${{ matrix.python-version }} |
| 112 | + uses: actions/setup-python@v4 |
| 113 | + with: |
| 114 | + python-version: ${{ matrix.python-version }} |
| 115 | + |
| 116 | + - name: Configure Poetry |
| 117 | + uses: snok/install-poetry@v1 |
| 118 | + with: |
| 119 | + version: 1.7.1 |
| 120 | + virtualenvs-create: true |
| 121 | + virtualenvs-in-project: true |
| 122 | + |
| 123 | + - name: Cache virtualenv |
| 124 | + uses: actions/cache@v4 |
| 125 | + with: |
| 126 | + path: ./.venv |
| 127 | + key: ${{ runner.os }}-venv-${{ hashFiles('**/poetry.lock') }} |
| 128 | + |
| 129 | + - name: Run tests |
| 130 | + run: poetry run make test |
| 131 | + timeout-minutes: 5 |
| 132 | + |
| 133 | + release: |
| 134 | + needs: [verify, test] |
| 135 | + runs-on: ubuntu-latest |
| 136 | + concurrency: release |
| 137 | + outputs: |
| 138 | + released: ${{ steps.release.outputs.released }} |
| 139 | + steps: |
| 140 | + # Note: we need to checkout the repository at the workflow sha in case during the workflow |
| 141 | + # the branch was updated. To keep PSR working with the configured release branches, |
| 142 | + # we force a checkout of the desired release branch but at the workflow sha HEAD. |
| 143 | + - name: Setup | Checkout Repository at workflow sha |
| 144 | + uses: actions/checkout@v4 |
| 145 | + with: |
| 146 | + fetch-depth: 0 |
| 147 | + ref: ${{ github.sha }} |
| 148 | + |
| 149 | + - name: Setup | Force correct release branch on workflow sha |
| 150 | + run: | |
| 151 | + git checkout -B ${{ github.ref_name }} ${{ github.sha }} |
| 152 | +
|
| 153 | + - name: Action | Semantic Version Release |
| 154 | + id: release |
| 155 | + uses: python-semantic-release/python-semantic-release@v9.15.1 |
| 156 | + with: |
| 157 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 158 | + git_committer_name: "github-actions" |
| 159 | + git_committer_email: "actions@users.noreply.github.com" |
| 160 | + |
| 161 | + # Add Poetry-based PyPI publishing steps |
| 162 | + - name: Set up python |
| 163 | + if: steps.release.outputs.released == 'true' |
| 164 | + uses: actions/setup-python@v4 |
| 165 | + with: |
| 166 | + python-version: 3.11 |
| 167 | + |
| 168 | + - name: Configure Poetry |
| 169 | + if: steps.release.outputs.released == 'true' |
| 170 | + uses: snok/install-poetry@v1 |
| 171 | + with: |
| 172 | + version: 1.7.1 |
| 173 | + virtualenvs-create: true |
| 174 | + virtualenvs-in-project: true |
| 175 | + |
| 176 | + - name: Configure poetry credentials |
| 177 | + if: steps.release.outputs.released == 'true' |
| 178 | + run: | |
| 179 | + poetry config pypi-token.pypi ${{ secrets.PYPI_API_TOKEN }} |
| 180 | +
|
| 181 | + - name: Build and publish |
| 182 | + if: steps.release.outputs.released == 'true' |
| 183 | + run: | |
| 184 | + poetry build |
| 185 | + poetry publish |
| 186 | +
|
| 187 | + # Add the download workspace as a separate step before build and publish |
| 188 | + - name: Download workspace |
| 189 | + if: steps.release.outputs.released == 'true' |
| 190 | + uses: actions/download-artifact@v4 |
| 191 | + with: |
| 192 | + name: workspace |
0 commit comments