vercel.deployment.success #297
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # This will trigger the E2E workflow. | |
| # IMPORTANT: this is always taken from main - so if this is changed in branch it won't be applied | |
| # until this is merged to main | |
| # This behaviour is because the repository_dispatch trigger | |
| # | |
| # Created August 16th, 2025 | |
| # @author ywarezk | |
| # @license MIT | |
| # | |
| name: Trigger E2E | |
| on: | |
| repository_dispatch: | |
| types: | |
| - 'vercel.deployment.success' | |
| workflow_dispatch: | |
| inputs: | |
| repository: | |
| description: "Source repository owner/name (optional)" | |
| required: false | |
| sha: | |
| description: "Commit SHA (optional)" | |
| required: false | |
| prNumber: | |
| description: "PR number for fork/head ref fallback (optional)" | |
| required: false | |
| checkoutRef: | |
| description: "Explicit ref to checkout in e2e workflow (optional)" | |
| required: false | |
| url: | |
| description: "Preview URL" | |
| required: true | |
| jobs: | |
| run-e2es: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/create-github-app-token@v3.0.0 | |
| id: app-token | |
| with: | |
| app-id: ${{ vars.ACADEMEEZ_APP_ID }} | |
| private-key: ${{ secrets.ACADEMEEZ_APP_PRIVATE_KEY }} | |
| - name: Trigger workflow with SHA | |
| uses: actions/github-script@v7 | |
| if: ${{ github.event_name == 'workflow_dispatch' || github.event.client_payload.environment != 'production' }} | |
| with: | |
| github-token: ${{ steps.app-token.outputs.token }} | |
| script: | | |
| const isManual = context.eventName === 'workflow_dispatch' | |
| const payload = context.payload.client_payload || {} | |
| const sha = isManual ? (`${{ inputs.sha }}` || '') : (payload.git?.sha || '') | |
| const prNumber = isManual | |
| ? (`${{ inputs.prNumber }}` || '') | |
| : (payload.meta?.githubPullRequestId || payload.pullRequest?.number || '') | |
| const defaultBranch = context.payload.repository?.default_branch || 'main' | |
| const baseRepo = `${context.repo.owner}/${context.repo.repo}` | |
| const repository = isManual | |
| ? (`${{ inputs.repository }}` || baseRepo) | |
| : ( | |
| payload.git?.repo || | |
| payload.git?.repoName || | |
| payload.git?.full_name || | |
| payload.pullRequest?.head?.repo?.full_name || | |
| baseRepo | |
| ) | |
| let checkoutRef = isManual | |
| ? (`${{ inputs.checkoutRef }}` || '') | |
| : (payload.git?.branch || payload.git?.ref || '') | |
| // For same-repo commits this gives us a normal branch name. | |
| if (!checkoutRef && sha) { | |
| try { | |
| const { data: branches } = await github.rest.repos.listBranchesForHeadCommit({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| commit_sha: sha, | |
| }) | |
| if (branches.length) { | |
| checkoutRef = branches[0].name | |
| } | |
| } catch (error) { | |
| core.info(`Could not resolve branch from SHA ${sha}: ${error.message}`) | |
| } | |
| } | |
| // For PR previews (especially forks), prefer GitHub pull refs. | |
| // A plain branch name in payload can refer to a fork branch that does not | |
| // exist in the base repository, which breaks checkout in the downstream workflow. | |
| if (prNumber && !isManual) { | |
| checkoutRef = `refs/pull/${prNumber}/head` | |
| } else if (!checkoutRef && prNumber) { | |
| checkoutRef = `refs/pull/${prNumber}/head` | |
| } | |
| // workflow_dispatch must run from a ref in the base repo; always use default branch. | |
| const dispatchRef = defaultBranch | |
| checkoutRef = checkoutRef || dispatchRef | |
| const previewUrl = isManual ? `${{ inputs.url }}` : `${{ github.event.client_payload.url }}` | |
| core.info(`Dispatching E2E from ref=${dispatchRef} repository=${repository} checkoutRef=${checkoutRef} sha=${sha || 'n/a'}`) | |
| await github.rest.actions.createWorkflowDispatch({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| workflow_id: 'e2e.yml', // Replace with your workflow file name | |
| ref: dispatchRef, | |
| inputs: { | |
| repository, | |
| ref: checkoutRef, | |
| sha, | |
| url: previewUrl | |
| } | |
| }); | |