|
1 | | -# Stub: Pre-Release Workflow |
| 1 | +# Pre-Release Workflow |
2 | 2 | # |
3 | | -# Minimal placeholder to register the workflow_dispatch trigger on main. |
4 | | -# Full implementation arrives in a follow-up PR. |
| 3 | +# Builds and publishes a pre-release version of the Python SDK to PyPI. |
| 4 | +# Pre-releases are installable via `pip install airbyte-api==1.0.0rc1` but |
| 5 | +# are NOT the default version, so existing users are unaffected. |
| 6 | +# |
| 7 | +# Triggers: |
| 8 | +# - Manual workflow_dispatch: From the Actions tab |
| 9 | +# - Slash command: `/pre-release version=1.0.0rc1` on a PR comment |
| 10 | +# |
| 11 | +# Inputs: |
| 12 | +# |
| 13 | +# version (REQUIRED): The pre-release version string. |
| 14 | +# Must contain a PEP 440 pre-release suffix: rcN, betaN, alphaN, devN. |
| 15 | +# Examples: 1.0.0rc1, 1.0.0a1, 1.0.0b1, 1.0.0.dev1 |
| 16 | +# |
| 17 | +# ref (optional, default: main): The branch, tag, or commit SHA to build from. |
| 18 | +# When triggered via slash command on a PR, defaults to the PR's head branch. |
5 | 19 |
|
6 | 20 | name: Pre-Release |
7 | 21 |
|
8 | 22 | on: |
9 | 23 | workflow_dispatch: |
10 | 24 | inputs: |
11 | 25 | version: |
12 | | - description: 'Pre-release version (e.g. 1.0.0rc1)' |
| 26 | + description: >- |
| 27 | + Pre-release version (e.g. 1.0.0rc1, 1.0.0a1). |
| 28 | + Must contain a PEP 440 pre-release suffix. |
13 | 29 | required: true |
14 | 30 | type: string |
15 | 31 | ref: |
|
26 | 42 | required: false |
27 | 43 | type: string |
28 | 44 |
|
| 45 | +concurrency: |
| 46 | + group: pre-release-${{ inputs.version }} |
| 47 | + cancel-in-progress: true |
| 48 | + |
| 49 | +permissions: |
| 50 | + contents: read |
| 51 | + |
29 | 52 | jobs: |
30 | | - stub: |
31 | | - name: Stub (placeholder) |
32 | | - if: false |
| 53 | + pre_release: |
| 54 | + name: Build & Publish Pre-Release |
33 | 55 | runs-on: ubuntu-latest |
| 56 | + environment: |
| 57 | + name: pypi |
| 58 | + url: https://pypi.org/project/airbyte-api/ |
| 59 | + permissions: |
| 60 | + contents: write |
| 61 | + pull-requests: write |
| 62 | + id-token: write |
34 | 63 | steps: |
35 | | - - run: echo "stub" |
| 64 | + # ── Slash command: post starting comment ──────────────────────── |
| 65 | + - name: Authenticate as GitHub App |
| 66 | + if: ${{ inputs.pr != '' }} |
| 67 | + uses: actions/create-github-app-token@v3 |
| 68 | + id: get-app-token |
| 69 | + with: |
| 70 | + app-id: ${{ secrets.OCTAVIA_BOT_APP_ID }} |
| 71 | + private-key: ${{ secrets.OCTAVIA_BOT_PRIVATE_KEY }} |
| 72 | + |
| 73 | + - name: Post starting comment |
| 74 | + if: ${{ inputs.pr != '' }} |
| 75 | + id: start-comment |
| 76 | + uses: peter-evans/create-or-update-comment@v5 |
| 77 | + with: |
| 78 | + token: ${{ steps.get-app-token.outputs.token }} |
| 79 | + issue-number: ${{ inputs.pr }} |
| 80 | + comment-id: ${{ inputs.comment-id || '' }} |
| 81 | + body: | |
| 82 | + > **Pre-Release Job Info** |
| 83 | + > |
| 84 | + > Building pre-release `${{ inputs.version }}` from ref `${{ inputs.ref || 'PR head branch' }}`. |
| 85 | +
|
| 86 | + > Job started... [Check job output.](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) |
| 87 | +
|
| 88 | + # ── Resolve ref from PR if not explicitly provided ────────────── |
| 89 | + - name: Resolve PR head branch |
| 90 | + if: ${{ inputs.pr != '' && inputs.ref == 'main' }} |
| 91 | + id: resolve-ref |
| 92 | + env: |
| 93 | + GH_TOKEN: ${{ steps.get-app-token.outputs.token || secrets.GITHUB_TOKEN }} |
| 94 | + run: | |
| 95 | + PR_HEAD=$(gh pr view "${{ inputs.pr }}" --repo "${{ github.repository }}" --json headRefName -q '.headRefName') |
| 96 | + echo "ref=$PR_HEAD" >> "$GITHUB_OUTPUT" |
| 97 | +
|
| 98 | + # ── Validate version input ────────────────────────────────────── |
| 99 | + - name: Validate pre-release version |
| 100 | + run: | |
| 101 | + VERSION="${{ inputs.version }}" |
| 102 | +
|
| 103 | + # PEP 440 pre-release pattern: X.Y.Z(a|b|rc|dev)N |
| 104 | + if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+(a|b|rc|dev|\.dev|\.post)[0-9]+$'; then |
| 105 | + echo "::error::Invalid version or missing pre-release suffix. Expected PEP 440 format: X.Y.Z(a|b|rc|dev)N (e.g. 1.0.0rc1). Got: $VERSION" |
| 106 | + exit 1 |
| 107 | + fi |
| 108 | +
|
| 109 | + echo "Pre-release version validated: $VERSION" |
| 110 | +
|
| 111 | + # ── Checkout ──────────────────────────────────────────────────── |
| 112 | + - name: Checkout repository |
| 113 | + uses: actions/checkout@v4 |
| 114 | + with: |
| 115 | + ref: ${{ steps.resolve-ref.outputs.ref || inputs.ref }} |
| 116 | + |
| 117 | + - name: Install uv |
| 118 | + uses: astral-sh/setup-uv@v5 |
| 119 | + |
| 120 | + - name: Set up Python |
| 121 | + uses: actions/setup-python@v5 |
| 122 | + with: |
| 123 | + python-version: '3.12' |
| 124 | + |
| 125 | + # ── Set version and build ─────────────────────────────────────── |
| 126 | + - name: Set pre-release version in pyproject.toml |
| 127 | + run: | |
| 128 | + VERSION="${{ inputs.version }}" |
| 129 | + # Use sed to update version in pyproject.toml |
| 130 | + sed -i "s/^version = \".*\"/version = \"${VERSION}\"/" pyproject.toml |
| 131 | + echo "Updated pyproject.toml version to: $VERSION" |
| 132 | + grep 'version' pyproject.toml | head -1 |
| 133 | +
|
| 134 | + - name: Build package |
| 135 | + run: uv build |
| 136 | + |
| 137 | + - name: Publish to PyPI |
| 138 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 139 | + |
| 140 | + # ── Tag the commit ────────────────────────────────────────────── |
| 141 | + - name: Create and push tag |
| 142 | + run: | |
| 143 | + VERSION="${{ inputs.version }}" |
| 144 | + git config user.name "github-actions[bot]" |
| 145 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 146 | + git tag -a "v${VERSION}" -m "Pre-release v${VERSION}" |
| 147 | + git push origin "v${VERSION}" |
| 148 | +
|
| 149 | + # ── Slash command: post result comment ────────────────────────── |
| 150 | + - name: Post result comment |
| 151 | + if: ${{ always() && inputs.pr != '' }} |
| 152 | + uses: peter-evans/create-or-update-comment@v5 |
| 153 | + with: |
| 154 | + token: ${{ steps.get-app-token.outputs.token || secrets.GITHUB_TOKEN }} |
| 155 | + issue-number: ${{ inputs.pr }} |
| 156 | + body: | |
| 157 | + > **Pre-Release Result:** ${{ job.status == 'success' && 'Published' || 'Failed' }} |
| 158 | + > |
| 159 | + > Version: `${{ inputs.version }}` |
| 160 | + > Ref: `${{ steps.resolve-ref.outputs.ref || inputs.ref }}` |
| 161 | + > [View run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) |
| 162 | + ${{ job.status == 'success' && format('> Install: `pip install airbyte-api=={0}`', inputs.version) || '' }} |
0 commit comments