|
| 1 | +name: On-Demand Prerelease |
| 2 | + |
| 3 | +# Minimal permissions for security (addresses GitHub Advanced Security feedback) |
| 4 | +permissions: |
| 5 | + contents: read |
| 6 | + pull-requests: write |
| 7 | + issues: write |
| 8 | + |
| 9 | +on: |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + pr: |
| 13 | + description: "PR Number" |
| 14 | + type: string |
| 15 | + required: false |
| 16 | + comment-id: |
| 17 | + description: "Comment ID (Optional)" |
| 18 | + type: string |
| 19 | + required: false |
| 20 | + |
| 21 | +jobs: |
| 22 | + prerelease-on-demand: |
| 23 | + name: Trigger Prerelease Publish |
| 24 | + runs-on: ubuntu-24.04 |
| 25 | + steps: |
| 26 | + - name: Authenticate as GitHub App |
| 27 | + uses: actions/create-github-app-token@v2 |
| 28 | + id: get-app-token |
| 29 | + with: |
| 30 | + owner: "airbytehq" |
| 31 | + repositories: "airbyte-python-cdk" |
| 32 | + app-id: ${{ secrets.OCTAVIA_BOT_APP_ID }} |
| 33 | + private-key: ${{ secrets.OCTAVIA_BOT_PRIVATE_KEY }} |
| 34 | + |
| 35 | + - name: Create URL to the run output |
| 36 | + id: vars |
| 37 | + run: echo "run-url=https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_OUTPUT |
| 38 | + |
| 39 | + - name: Check that PR number is provided |
| 40 | + if: github.event.inputs.pr == '' |
| 41 | + run: | |
| 42 | + echo "Error: /prerelease command must be invoked on a pull request, not an issue." |
| 43 | + exit 1 |
| 44 | +
|
| 45 | + - name: Get PR info |
| 46 | + id: pr-info |
| 47 | + run: | |
| 48 | + PR_JSON=$(gh api repos/${{ github.repository }}/pulls/${{ github.event.inputs.pr }}) |
| 49 | + HEAD_REF=$(echo "$PR_JSON" | jq -r .head.ref) |
| 50 | + HEAD_REPO=$(echo "$PR_JSON" | jq -r .head.repo.full_name) |
| 51 | + echo "head-ref=${HEAD_REF}" >> $GITHUB_OUTPUT |
| 52 | + echo "head-repo=${HEAD_REPO}" >> $GITHUB_OUTPUT |
| 53 | + echo "PR branch: ${HEAD_REF} from ${HEAD_REPO}" |
| 54 | + env: |
| 55 | + GH_TOKEN: ${{ steps.get-app-token.outputs.token }} |
| 56 | + |
| 57 | + - name: Check that PR is from this repository (not a fork) |
| 58 | + if: steps.pr-info.outputs.head-repo != github.repository |
| 59 | + run: | |
| 60 | + echo "Error: /prerelease only works for branches in this repository, not forks." |
| 61 | + echo "PR is from: ${{ steps.pr-info.outputs.head-repo }}" |
| 62 | + echo "Expected: ${{ github.repository }}" |
| 63 | + exit 1 |
| 64 | +
|
| 65 | + - name: Append comment with job run link |
| 66 | + if: github.event.inputs.comment-id |
| 67 | + id: first-comment-action |
| 68 | + uses: peter-evans/create-or-update-comment@v4 |
| 69 | + with: |
| 70 | + comment-id: ${{ github.event.inputs.comment-id }} |
| 71 | + issue-number: ${{ github.event.inputs.pr }} |
| 72 | + body: | |
| 73 | + > **Prerelease Job Info** |
| 74 | + > |
| 75 | + > This job triggers the publish workflow with default arguments to create a prerelease. |
| 76 | + > |
| 77 | + > Prerelease job started... [Check job output.][1] |
| 78 | +
|
| 79 | + [1]: ${{ steps.vars.outputs.run-url }} |
| 80 | +
|
| 81 | + - name: Trigger publish workflow |
| 82 | + id: trigger-publish |
| 83 | + uses: the-actions-org/workflow-dispatch@v4 |
| 84 | + with: |
| 85 | + workflow: publish.yml |
| 86 | + token: ${{ steps.get-app-token.outputs.token }} |
| 87 | + ref: ${{ steps.pr-info.outputs.head-ref }} |
| 88 | + wait-for-completion: true |
| 89 | + display-workflow-run-url: false |
| 90 | + inputs: >- |
| 91 | + { |
| 92 | + "publish_to_pypi": "true", |
| 93 | + "publish_to_dockerhub": "true", |
| 94 | + "publish_manifest_server": "false", |
| 95 | + "update_connector_builder": "false" |
| 96 | + } |
| 97 | +
|
| 98 | + - name: Append success comment |
| 99 | + if: github.event.inputs.comment-id |
| 100 | + uses: peter-evans/create-or-update-comment@v4 |
| 101 | + with: |
| 102 | + comment-id: ${{ steps.first-comment-action.outputs.comment-id }} |
| 103 | + reactions: hooray |
| 104 | + body: | |
| 105 | + > ✅ Prerelease workflow triggered successfully. |
| 106 | + > |
| 107 | + > View the publish workflow run: ${{ steps.trigger-publish.outputs.workflow-url }} |
| 108 | +
|
| 109 | + - name: Append failure comment |
| 110 | + if: failure() && github.event.inputs.comment-id |
| 111 | + uses: peter-evans/create-or-update-comment@v4 |
| 112 | + with: |
| 113 | + comment-id: ${{ steps.first-comment-action.outputs.comment-id }} |
| 114 | + reactions: confused |
| 115 | + body: | |
| 116 | + > ❌ Failed to trigger prerelease workflow. |
0 commit comments