|
| 1 | +name: Manual PR Publish Trigger |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [labeled] |
| 6 | + |
| 7 | +jobs: |
| 8 | + pr-label-trigger: |
| 9 | + # This job only runs if the event is a label being added to a Pull Request. |
| 10 | + if: github.event.issue.pull_request |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Dispatch build for PR branch |
| 14 | + if: github.event.label.name == 'publish-qt5' || github.event.label.name == 'publish-qt6' |
| 15 | + uses: actions/github-script@v8 |
| 16 | + with: |
| 17 | + script: | |
| 18 | + const label = context.payload.label.name; |
| 19 | + const prNumber = context.issue.number; |
| 20 | +
|
| 21 | + // 1. Determine which workflow to call and its parameters |
| 22 | + const workflow_id = (label === 'publish-qt5') ? 'publish-daily-qt5.yml' : 'publish-daily-qt6.yml'; |
| 23 | +
|
| 24 | + // 2. Check user's permission level |
| 25 | + const { data: permission } = await github.rest.repos.getCollaboratorPermissionLevel({ |
| 26 | + owner: context.repo.owner, repo: context.repo.repo, username: context.actor }); |
| 27 | + if (!['admin', 'write', 'maintain'].includes(permission.permission)) { |
| 28 | + return core.setFailed(`User @${context.actor} does not have sufficient permission.`); |
| 29 | + } |
| 30 | +
|
| 31 | + // 3. Get the PR's source branch |
| 32 | + const { data: pr } = await github.rest.pulls.get({ |
| 33 | + owner: context.repo.owner, repo: context.repo.repo, pull_number: prNumber }); |
| 34 | + const prBranch = pr.head.ref; |
| 35 | +
|
| 36 | + // 4. Construct the Snap Store release channel for this PR |
| 37 | + const releaseChannel = `edge/pr${prNumber}`; |
| 38 | +
|
| 39 | + // 5. Trigger the target workflow with the correct inputs |
| 40 | + console.log(`Triggering '${workflow_id}' for PR branch '${prBranch}' to be published to '${releaseChannel}'`); |
| 41 | + await github.rest.actions.createWorkflowDispatch({ |
| 42 | + owner: context.repo.owner, |
| 43 | + repo: context.repo.repo, |
| 44 | + workflow_id: workflow_id, |
| 45 | + ref: 'main', // The dispatch action must be triggered from a branch that has the workflow file |
| 46 | + inputs: { |
| 47 | + checkout_ref: prBranch, |
| 48 | + release_channel: releaseChannel |
| 49 | + } |
| 50 | + }); |
| 51 | +
|
| 52 | + // 6. Add a confirmation comment to the PR |
| 53 | + await github.rest.issues.createComment({ |
| 54 | + owner: context.repo.owner, repo: context.repo.repo, issue_number: prNumber, |
| 55 | + body: `✅ \`${label}\` build triggered for branch \`${prBranch}\` by @${context.actor}. The snap will be published to the \`${releaseChannel}\` channel.` |
| 56 | + }); |
| 57 | +
|
| 58 | + - name: Remove trigger label |
| 59 | + if: success() && (github.event.label.name == 'publish-qt5' || github.event.label.name == 'publish-qt6') |
| 60 | + uses: actions/github-script@v8 |
| 61 | + with: |
| 62 | + script: | |
| 63 | + await github.rest.issues.removeLabel({ |
| 64 | + owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, name: context.payload.label.name }); |
0 commit comments