|
| 1 | +name: On-Demand Prerelease |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + pr: |
| 7 | + description: 'PR Number' |
| 8 | + type: string |
| 9 | + required: true |
| 10 | + comment-id: |
| 11 | + description: 'Comment ID (Optional)' |
| 12 | + type: string |
| 13 | + required: false |
| 14 | + |
| 15 | +env: |
| 16 | + AIRBYTE_ANALYTICS_ID: ${{ vars.AIRBYTE_ANALYTICS_ID }} |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: read |
| 20 | + pull-requests: write |
| 21 | + issues: write |
| 22 | + |
| 23 | +jobs: |
| 24 | + resolve-pr: |
| 25 | + name: Set up Workflow |
| 26 | + runs-on: ubuntu-latest |
| 27 | + steps: |
| 28 | + - name: Resolve workflow variables |
| 29 | + id: vars |
| 30 | + uses: aaronsteers/resolve-ci-vars-action@2e56afab0344bbe03c047dfa39bae559d0291472 # v0.1.6 |
| 31 | + |
| 32 | + - name: Append comment with job run link |
| 33 | + id: first-comment-action |
| 34 | + uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 |
| 35 | + with: |
| 36 | + comment-id: ${{ github.event.inputs.comment-id }} |
| 37 | + issue-number: ${{ github.event.inputs.pr }} |
| 38 | + body: | |
| 39 | + > **Prerelease Build Started** |
| 40 | + > |
| 41 | + > Building and publishing prerelease package from this PR... |
| 42 | + > [Check job output.](${{ steps.vars.outputs.run-url }}) |
| 43 | +
|
| 44 | + - name: Checkout to get latest tag |
| 45 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 46 | + with: |
| 47 | + fetch-depth: 0 |
| 48 | + |
| 49 | + - name: Compute prerelease version |
| 50 | + id: version |
| 51 | + run: | |
| 52 | + # Get the latest tag version (strip 'v' prefix if present) |
| 53 | + LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") |
| 54 | + BASE_VERSION=${LATEST_TAG#v} |
| 55 | + # Create a unique prerelease version using PR number and run ID |
| 56 | + # Format: {base}.dev{pr_number}{run_id} (e.g., 0.34.0.dev825123456789) |
| 57 | + PRERELEASE_VERSION="${BASE_VERSION}.dev${{ github.event.inputs.pr }}${{ github.run_id }}" |
| 58 | + echo "version=$PRERELEASE_VERSION" >> $GITHUB_OUTPUT |
| 59 | + echo "Computed prerelease version: $PRERELEASE_VERSION" |
| 60 | + outputs: |
| 61 | + source-repo: ${{ steps.vars.outputs.pr-source-repo-name-full }} |
| 62 | + source-branch: ${{ steps.vars.outputs.pr-source-git-branch }} |
| 63 | + commit-sha: ${{ steps.vars.outputs.pr-source-git-sha }} |
| 64 | + pr-number: ${{ steps.vars.outputs.pr-number }} |
| 65 | + job-run-url: ${{ steps.vars.outputs.run-url }} |
| 66 | + first-comment-id: ${{ steps.first-comment-action.outputs.comment-id }} |
| 67 | + prerelease-version: ${{ steps.version.outputs.version }} |
| 68 | + |
| 69 | + build-and-publish: |
| 70 | + name: Call Publish Workflow |
| 71 | + needs: [resolve-pr] |
| 72 | + uses: ./.github/workflows/pypi_publish.yml |
| 73 | + with: |
| 74 | + # Use refs/pull/<PR>/head instead of raw SHA for fork compatibility |
| 75 | + git_ref: refs/pull/${{ github.event.inputs.pr }}/head |
| 76 | + version_override: ${{ needs.resolve-pr.outputs.prerelease-version }} |
| 77 | + publish: true |
| 78 | + |
| 79 | + post-result-comment: |
| 80 | + name: Write Status to PR |
| 81 | + needs: [resolve-pr, build-and-publish] |
| 82 | + if: always() |
| 83 | + runs-on: ubuntu-latest |
| 84 | + steps: |
| 85 | + - name: Post success comment |
| 86 | + if: needs.build-and-publish.result == 'success' |
| 87 | + uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 |
| 88 | + with: |
| 89 | + comment-id: ${{ needs.resolve-pr.outputs.first-comment-id }} |
| 90 | + issue-number: ${{ github.event.inputs.pr }} |
| 91 | + reactions: rocket |
| 92 | + body: | |
| 93 | + > **Prerelease Published to PyPI** |
| 94 | + > |
| 95 | + > Version: `${{ needs.resolve-pr.outputs.prerelease-version }}` |
| 96 | + > |
| 97 | + > Install with: |
| 98 | + > ```bash |
| 99 | + > pip install airbyte==${{ needs.resolve-pr.outputs.prerelease-version }} |
| 100 | + > ``` |
| 101 | + - name: Post failure comment |
| 102 | + if: needs.build-and-publish.result == 'failure' |
| 103 | + uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 |
| 104 | + with: |
| 105 | + comment-id: ${{ needs.resolve-pr.outputs.first-comment-id }} |
| 106 | + issue-number: ${{ github.event.inputs.pr }} |
| 107 | + reactions: confused |
| 108 | + body: | |
| 109 | + > **Prerelease Build/Publish Failed** |
| 110 | + > |
| 111 | + > The prerelease encountered an error. |
| 112 | + > [Check job output](${{ needs.resolve-pr.outputs.job-run-url }}) for details. |
| 113 | + > |
| 114 | + > You can still install directly from this PR branch: |
| 115 | + > ```bash |
| 116 | + > pip install 'git+https://github.com/${{ needs.resolve-pr.outputs.source-repo }}.git@${{ needs.resolve-pr.outputs.source-branch }}' |
| 117 | + > ``` |
0 commit comments