1010 publish-prerelease :
1111 name : Publish prerelease
1212 runs-on : ubuntu-latest
13+ env :
14+ PR_COMMENT_TOKEN : ${{ secrets.PR_COMMENT_TOKEN }}
15+ OWNER : ${{ github.repository_owner }}
16+ REPOSITORY : ${{ github.event.repository.name }}
17+ RUN_ID : ${{ github.run_id }}
18+ # For a `pull_request` event, the branch is `github.head_ref`.
19+ # For a `push` event, the branch is `github.ref_name`.
20+ BRANCH : ${{ github.head_ref || github.ref_name }}
21+ PR_NUMBER : ${{ github.event.pull_request.number }}
22+ BASE_COMMIT_HASH : ${{ github.event.pull_request.base.sha }}
23+ HEAD_COMMIT_HASH : ${{ github.event.pull_request.head.sha }}
24+ MERGE_BASE_COMMIT_HASH : ' ' # placeholder so that we have autocomplete and logs
25+ CLOUDFRONT_REPO_URL : ${{ vars.AWS_CLOUDFRONT_URL }}/${{ github.event.repository.name }}
26+ HOST_URL : ${{ vars.AWS_CLOUDFRONT_URL }}/${{ github.event.repository.name }}/${{ github.run_id }}
1327 steps :
1428 - name : Checkout and setup high risk environment
1529 uses : MetaMask/action-checkout-and-setup@v1
@@ -19,26 +33,33 @@ jobs:
1933 fetch-depth : 0 # This is needed to get merge base to calculate bundle size diff
2034 yarn-custom-url : ${{ vars.YARN_URL }}
2135
36+ - name : Find the associated PR
37+ if : ${{ startsWith(env.BRANCH, 'Version-v') && (!env.PR_NUMBER || !env.BASE_COMMIT_HASH || !env.HEAD_COMMIT_HASH) }}
38+ uses : actions/github-script@v7
39+ with :
40+ script : |
41+ const prs = await github.rest.pulls.list({
42+ owner: context.repo.owner,
43+ repo: context.repo.repo,
44+ head: `${context.repo.owner}:${process.env.BRANCH}`
45+ base: 'master',
46+ });
47+ if (prs.data.length > 0) {
48+ core.exportVariable("PR_NUMBER", prs.data[0].number);
49+ core.exportVariable("BASE_COMMIT_HASH", prs.data[0].base.sha);
50+ core.exportVariable("HEAD_COMMIT_HASH", prs.data[0].head.sha);
51+ core.info(`The pull request number is '${process.env.PR_NUMBER}', the base commit hash is '${process.env.BASE_COMMIT_HASH}', and the head commit hash is '${process.env.HEAD_COMMIT_HASH}'`);
52+ } else {
53+ core.info(`No pull request detected for branch '${process.env.BRANCH}'`);
54+ }
55+
2256 - name : Get merge base commit hash
23- id : get-merge-base
24- env :
25- BASE_SHA : ${{ github.event.pull_request.base.sha }}
26- HEAD_SHA : ${{ github.event.pull_request.head.sha }}
57+ if : ${{ env.BASE_COMMIT_HASH && env.HEAD_COMMIT_HASH }}
2758 run : |
28- merge_base ="$(git merge-base "${BASE_SHA }" "${HEAD_SHA }")"
29- echo "MERGE_BASE =${merge_base }" >> "$GITHUB_OUTPUT "
30- echo "Merge base is '${merge_base }'"
59+ merge_base_commit_hash ="$(git merge-base "${BASE_COMMIT_HASH }" "${HEAD_COMMIT_HASH }")"
60+ echo "MERGE_BASE_COMMIT_HASH =${merge_base_commit_hash }" >> "${GITHUB_ENV} "
61+ echo "The merge base commit hash is '${merge_base_commit_hash }'"
3162
3263 - name : Publish prerelease
33- if : ${{ env.PR_COMMENT_TOKEN && vars.AWS_CLOUDFRONT_URL }}
34- env :
35- PR_COMMENT_TOKEN : ${{ secrets.PR_COMMENT_TOKEN }}
36- OWNER : ${{ github.repository_owner }}
37- REPOSITORY : ${{ github.event.repository.name }}
38- RUN_ID : ${{ github.run_id }}
39- PR_NUMBER : ${{ github.event.pull_request.number }}
40- HEAD_COMMIT_HASH : ${{ github.event.pull_request.head.sha }}
41- MERGE_BASE_COMMIT_HASH : ${{ steps.get-merge-base.outputs.MERGE_BASE }}
42- CLOUDFRONT_REPO_URL : ${{ vars.AWS_CLOUDFRONT_URL }}/${{ github.event.repository.name }}
43- HOST_URL : ${{ vars.AWS_CLOUDFRONT_URL }}/${{ github.event.repository.name }}/${{ github.run_id }}
64+ if : ${{ env.MERGE_BASE_COMMIT_HASH && env.PR_NUMBER && env.PR_COMMENT_TOKEN && vars.AWS_CLOUDFRONT_URL }}
4465 run : yarn tsx ./development/metamaskbot-build-announce.ts
0 commit comments