|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'Release version (e.g. 0.1.0 or v0.1.0 — leading v is stripped automatically)' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + branch: |
| 11 | + description: 'Branch to cut the release from (defaults to main)' |
| 12 | + required: false |
| 13 | + type: string |
| 14 | + default: main |
| 15 | + |
| 16 | +jobs: |
| 17 | + validate-branch: |
| 18 | + name: Validate release branch |
| 19 | + runs-on: ubuntu-latest |
| 20 | + timeout-minutes: 5 |
| 21 | + steps: |
| 22 | + - name: Check branch exists on origin |
| 23 | + env: |
| 24 | + GH_TOKEN: ${{ github.token }} |
| 25 | + BRANCH: ${{ inputs.branch }} |
| 26 | + run: | |
| 27 | + ENCODED_BRANCH="${BRANCH//\//%2F}" |
| 28 | + if ! gh api "repos/${{ github.repository }}/branches/${ENCODED_BRANCH}" --silent 2>/dev/null; then |
| 29 | + echo "::error::Branch '${BRANCH}' does not exist. Check for typos." |
| 30 | + exit 1 |
| 31 | + fi |
| 32 | + echo "Branch '${BRANCH}' confirmed." |
| 33 | +
|
| 34 | + test: |
| 35 | + name: Test (Python ${{ matrix.python-version }}) |
| 36 | + needs: [validate-branch] |
| 37 | + runs-on: ubuntu-latest |
| 38 | + timeout-minutes: 30 |
| 39 | + strategy: |
| 40 | + fail-fast: true |
| 41 | + matrix: |
| 42 | + python-version: ["3.11", "3.12"] |
| 43 | + steps: |
| 44 | + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
| 45 | + with: |
| 46 | + fetch-depth: 0 |
| 47 | + ref: ${{ inputs.branch }} |
| 48 | + |
| 49 | + - name: Install uv |
| 50 | + uses: astral-sh/setup-uv@e58605a9b6da7c637471fab8847a5e5a6b8df081 # v5 |
| 51 | + |
| 52 | + - name: Install dependencies |
| 53 | + run: uv sync --locked --dev --python ${{ matrix.python-version }} |
| 54 | + |
| 55 | + - name: Lint |
| 56 | + run: uv run --python ${{ matrix.python-version }} ruff check src tests |
| 57 | + |
| 58 | + - name: Format check |
| 59 | + run: uv run --python ${{ matrix.python-version }} ruff format --check src tests |
| 60 | + |
| 61 | + - name: Type check |
| 62 | + run: uv run --python ${{ matrix.python-version }} basedpyright |
| 63 | + |
| 64 | + - name: Run tests |
| 65 | + run: uv run --python ${{ matrix.python-version }} pytest --tb=short -q |
| 66 | + |
| 67 | + license-check: |
| 68 | + needs: [validate-branch] |
| 69 | + uses: ./.github/workflows/_license-check.yml |
| 70 | + with: |
| 71 | + branch: ${{ inputs.branch }} |
| 72 | + |
| 73 | + build: |
| 74 | + name: Build distribution |
| 75 | + needs: [test, license-check] |
| 76 | + runs-on: ubuntu-latest |
| 77 | + timeout-minutes: 20 |
| 78 | + permissions: |
| 79 | + contents: write |
| 80 | + outputs: |
| 81 | + version: ${{ steps.normalize.outputs.version }} |
| 82 | + steps: |
| 83 | + - name: Normalize version |
| 84 | + id: normalize |
| 85 | + run: | |
| 86 | + VERSION="${{ inputs.version }}" |
| 87 | + VERSION="${VERSION#v}" |
| 88 | + echo "version=${VERSION}" >> "$GITHUB_OUTPUT" |
| 89 | +
|
| 90 | + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
| 91 | + with: |
| 92 | + fetch-depth: 0 |
| 93 | + ref: ${{ inputs.branch }} |
| 94 | + |
| 95 | + - name: Configure git identity |
| 96 | + run: | |
| 97 | + git config user.name "github-actions[bot]" |
| 98 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 99 | +
|
| 100 | + - name: Create local release tag |
| 101 | + run: git tag "v${{ steps.normalize.outputs.version }}" |
| 102 | + |
| 103 | + - name: Install uv |
| 104 | + uses: astral-sh/setup-uv@e58605a9b6da7c637471fab8847a5e5a6b8df081 # v5 |
| 105 | + |
| 106 | + - name: Build wheel and sdist |
| 107 | + run: uv build |
| 108 | + |
| 109 | + - name: Guard against duplicate tag |
| 110 | + run: | |
| 111 | + if git ls-remote --tags origin "refs/tags/v${{ steps.normalize.outputs.version }}" | grep -q .; then |
| 112 | + echo "::error::Tag v${{ steps.normalize.outputs.version }} already exists on origin. Aborting." |
| 113 | + exit 1 |
| 114 | + fi |
| 115 | +
|
| 116 | + - name: Push release tag |
| 117 | + run: git push origin "v${{ steps.normalize.outputs.version }}" |
| 118 | + |
| 119 | + - name: Upload dist artifact |
| 120 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 121 | + with: |
| 122 | + name: dist |
| 123 | + path: dist/ |
| 124 | + if-no-files-found: error |
| 125 | + |
| 126 | + publish-testpypi: |
| 127 | + name: Publish → TestPyPI |
| 128 | + needs: build |
| 129 | + runs-on: ubuntu-latest |
| 130 | + timeout-minutes: 10 |
| 131 | + environment: |
| 132 | + name: testpypi |
| 133 | + url: https://test.pypi.org/p/orcapod-types |
| 134 | + permissions: |
| 135 | + id-token: write |
| 136 | + steps: |
| 137 | + - name: Install uv |
| 138 | + uses: astral-sh/setup-uv@e58605a9b6da7c637471fab8847a5e5a6b8df081 # v5 |
| 139 | + |
| 140 | + - name: Download dist artifact |
| 141 | + uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 |
| 142 | + with: |
| 143 | + name: dist |
| 144 | + path: dist/ |
| 145 | + |
| 146 | + - name: Publish to TestPyPI |
| 147 | + run: uv publish --publish-url https://test.pypi.org/legacy/ dist/* |
| 148 | + |
| 149 | + publish-pypi: |
| 150 | + name: Publish → PyPI |
| 151 | + needs: [build, publish-testpypi] |
| 152 | + runs-on: ubuntu-latest |
| 153 | + timeout-minutes: 10 |
| 154 | + environment: |
| 155 | + name: pypi |
| 156 | + url: https://pypi.org/p/orcapod-types |
| 157 | + permissions: |
| 158 | + id-token: write |
| 159 | + contents: write |
| 160 | + steps: |
| 161 | + - name: Install uv |
| 162 | + uses: astral-sh/setup-uv@e58605a9b6da7c637471fab8847a5e5a6b8df081 # v5 |
| 163 | + |
| 164 | + - name: Download dist artifact |
| 165 | + uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 |
| 166 | + with: |
| 167 | + name: dist |
| 168 | + path: dist/ |
| 169 | + |
| 170 | + - name: Publish to PyPI |
| 171 | + run: uv publish dist/* |
| 172 | + |
| 173 | + - name: Create GitHub Release |
| 174 | + uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 # v2.6.2 |
| 175 | + with: |
| 176 | + tag_name: "v${{ needs.build.outputs.version }}" |
| 177 | + generate_release_notes: true |
| 178 | + files: dist/* |
| 179 | + |
| 180 | + linear-sync: |
| 181 | + name: Sync Linear release |
| 182 | + needs: build |
| 183 | + runs-on: ubuntu-latest |
| 184 | + timeout-minutes: 5 |
| 185 | + permissions: |
| 186 | + contents: read |
| 187 | + steps: |
| 188 | + - name: Checkout |
| 189 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
| 190 | + with: |
| 191 | + fetch-depth: 0 |
| 192 | + - name: Sync Linear release |
| 193 | + uses: linear/linear-release-action@c0cb8354a362c24c6d3e0948f37fd66d07588e3f # v0 |
| 194 | + with: |
| 195 | + access_key: ${{ secrets.LINEAR_ACCESS_KEY }} |
| 196 | + command: sync |
| 197 | + version: "v${{ needs.build.outputs.version }}" |
| 198 | + |
| 199 | + linear-complete: |
| 200 | + name: Complete Linear release |
| 201 | + needs: [build, publish-pypi, linear-sync] |
| 202 | + runs-on: ubuntu-latest |
| 203 | + timeout-minutes: 5 |
| 204 | + permissions: |
| 205 | + contents: read |
| 206 | + steps: |
| 207 | + - name: Checkout |
| 208 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
| 209 | + with: |
| 210 | + fetch-depth: 0 |
| 211 | + - name: Complete Linear release |
| 212 | + uses: linear/linear-release-action@c0cb8354a362c24c6d3e0948f37fd66d07588e3f # v0 |
| 213 | + with: |
| 214 | + access_key: ${{ secrets.LINEAR_ACCESS_KEY }} |
| 215 | + command: complete |
| 216 | + version: "v${{ needs.build.outputs.version }}" |
0 commit comments