From 069d9c482219ef9dfd27bb506fef0b5b9ca875f4 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Wed, 31 Jan 2024 23:36:31 -0800 Subject: [PATCH 01/73] Post comment after e2e smoke --- bitrise.yml | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/bitrise.yml b/bitrise.yml index 952acd25988..285a50c7270 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -266,27 +266,34 @@ workflows: # Send a Slack message when workflow succeeds notify_success_on_slack: - before_run: - - _get_workflow_info + # before_run: + # - _get_workflow_info steps: - - slack@3: + - comment-on-github-pull-request@0: inputs: - - text: '${BITRISE_APP_TITLE} ${BITRISEIO_PIPELINE_TITLE} workflow notification' - - pretext: ':large_green_circle: *${BITRISEIO_PIPELINE_TITLE} succeeded!*' - - title: 'Commit #$COMMIT_SHORT_HASH $BRANCH_HEIGHT' - - title_link: https://github.com/${BITRISEIO_GIT_REPOSITORY_OWNER}/${BITRISEIO_GIT_REPOSITORY_SLUG}/commit/${COMMIT_SHORT_HASH} - - message: ${BITRISE_GIT_MESSAGE} - - fields: | - Branch|${BITRISE_GIT_BRANCH} - Workflow|${BITRISEIO_PIPELINE_TITLE} - Trigger|${WORKFLOW_TRIGGER} - Build|${BITRISE_BUILD_NUMBER} - - buttons: | - View app|${BITRISE_APP_URL} - View build|${BITRISEIO_PIPELINE_BUILD_URL} - View commit|https://github.com/${BITRISEIO_GIT_REPOSITORY_OWNER}/${BITRISEIO_GIT_REPOSITORY_SLUG}/commit/${COMMIT_SHORT_HASH} - - footer: 'Bitrise ${BITRISEIO_PIPELINE_TITLE} workflow notification' - - webhook_url: https://hooks.slack.com/services/${MM_SLACK_TOKEN}/${MM_SLACK_SECRET}/${MM_SLACK_ROOM} + - body: |- + ![QR code]($BITRISE_PUBLIC_INSTALL_PAGE_QR_CODE_IMAGE_URL) + + $BITRISE_PUBLIC_INSTALL_PAGE_URL + - personal_access_token: '$GITHUB_ACCESS_TOKEN' + # - slack@3: + # inputs: + # - text: '${BITRISE_APP_TITLE} ${BITRISEIO_PIPELINE_TITLE} workflow notification' + # - pretext: ':large_green_circle: *${BITRISEIO_PIPELINE_TITLE} succeeded!*' + # - title: 'Commit #$COMMIT_SHORT_HASH $BRANCH_HEIGHT' + # - title_link: https://github.com/${BITRISEIO_GIT_REPOSITORY_OWNER}/${BITRISEIO_GIT_REPOSITORY_SLUG}/commit/${COMMIT_SHORT_HASH} + # - message: ${BITRISE_GIT_MESSAGE} + # - fields: | + # Branch|${BITRISE_GIT_BRANCH} + # Workflow|${BITRISEIO_PIPELINE_TITLE} + # Trigger|${WORKFLOW_TRIGGER} + # Build|${BITRISE_BUILD_NUMBER} + # - buttons: | + # View app|${BITRISE_APP_URL} + # View build|${BITRISEIO_PIPELINE_BUILD_URL} + # View commit|https://github.com/${BITRISEIO_GIT_REPOSITORY_OWNER}/${BITRISEIO_GIT_REPOSITORY_SLUG}/commit/${COMMIT_SHORT_HASH} + # - footer: 'Bitrise ${BITRISEIO_PIPELINE_TITLE} workflow notification' + # - webhook_url: https://hooks.slack.com/services/${MM_SLACK_TOKEN}/${MM_SLACK_SECRET}/${MM_SLACK_ROOM} # Send a Slack message when workflow fails _notify_failure_on_slack: From 6d325acae94c9e638093c5a00d26f3af2b4a690f Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Mon, 5 Feb 2024 21:45:02 -0800 Subject: [PATCH 02/73] Remove extra steps for testing --- bitrise.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bitrise.yml b/bitrise.yml index 285a50c7270..81db2282dfb 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -51,8 +51,8 @@ pipelines: #PR_e2e_verfication (build ios & android), run iOS (smoke), emulator Android pr_smoke_e2e_pipeline: stages: - - build_smoke_e2e_ios_android_stage: {} - - run_smoke_e2e_ios_android_stage: {} + # - build_smoke_e2e_ios_android_stage: {} + # - run_smoke_e2e_ios_android_stage: {} - notify: {} # Pipeline for Flask create_flask_release_builds_pipeline: From 09fed8cf001979b24c06cea6ea4dd8baa4a53dd8 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Mon, 5 Feb 2024 21:55:03 -0800 Subject: [PATCH 03/73] Provide missing params to step --- bitrise.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bitrise.yml b/bitrise.yml index 81db2282dfb..df2e30b15c9 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -271,11 +271,13 @@ workflows: steps: - comment-on-github-pull-request@0: inputs: + - personal_access_token: '$GITHUB_ACCESS_TOKEN' - body: |- - ![QR code]($BITRISE_PUBLIC_INSTALL_PAGE_QR_CODE_IMAGE_URL) - + HELLO $BITRISE_PUBLIC_INSTALL_PAGE_URL - - personal_access_token: '$GITHUB_ACCESS_TOKEN' + - repository_url: '$GIT_REPOSITORY_URL' + - issue_number: '$BITRISE_PULL_REQUEST' + - api_base_url: 'https://api.github.com' # - slack@3: # inputs: # - text: '${BITRISE_APP_TITLE} ${BITRISEIO_PIPELINE_TITLE} workflow notification' From 6e9d35e0b7d9d310ac009f36ff6751e6391eb8e3 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Mon, 5 Feb 2024 22:04:58 -0800 Subject: [PATCH 04/73] Manually apply PR number for now --- bitrise.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitrise.yml b/bitrise.yml index df2e30b15c9..379a9d39830 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -276,7 +276,7 @@ workflows: HELLO $BITRISE_PUBLIC_INSTALL_PAGE_URL - repository_url: '$GIT_REPOSITORY_URL' - - issue_number: '$BITRISE_PULL_REQUEST' + - issue_number: 8495 - api_base_url: 'https://api.github.com' # - slack@3: # inputs: From 664d9b3a63669932924df449ec1f38c63dab6eed Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Tue, 6 Feb 2024 15:18:09 -0800 Subject: [PATCH 05/73] Create action for detecting Bitrise status --- .../check-bitrise-status.ts | 86 +++++++++++++++++++ .github/workflows/check-bitrise-status.yml | 35 ++++++++ package.json | 1 + 3 files changed, 122 insertions(+) create mode 100644 .github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts create mode 100644 .github/workflows/check-bitrise-status.yml diff --git a/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts b/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts new file mode 100644 index 00000000000..89335c3881f --- /dev/null +++ b/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts @@ -0,0 +1,86 @@ +import * as core from '@actions/core'; +import { context, getOctokit } from '@actions/github'; +import { GitHub } from '@actions/github/lib/utils'; + +main().catch((error: Error): void => { + console.error(error); + process.exit(1); +}); + +async function main(): Promise { + const githubToken = process.env.GITHUB_TOKEN; + const e2eLabel = process.env.E2E_LABEL; + const pullRequestLink = `https://github.com/MetaMask/metamask-mobile/pull/${context.issue.number}`; + + if (!githubToken) { + core.setFailed('GITHUB_TOKEN not found'); + process.exit(1); + } + + if (!e2eLabel) { + core.setFailed('E2E_LABEL not found'); + process.exit(1); + } + + // Check if the "Run Smoke E2E" label is applied + const { owner, repo, number: issue_number } = context.issue; + const octokit: InstanceType = getOctokit(githubToken); + const { data: labels } = await octokit.rest.issues.listLabelsOnIssue({ owner, repo, issue_number }); + const hasSmokeTestLabel = labels.some(label => label.name === e2eLabel); + + if (!hasSmokeTestLabel) { + console.log(`"${e2eLabel}" label not applied. Skipping Bitrise status check.`) + return; + } + +// console.log(`Workflow triggered by the event (${triggerAction})`); + +// switch (triggerAction) { +// case PullRequestTriggerType.ReadyForReview: +// shouldTriggerE2E = true; +// console.log( +// `Starting E2E smoke since PR has changed to ready for review.`, +// ); +// break; +// case PullRequestTriggerType.Labeled: +// shouldTriggerE2E = e2eLabel === context.payload.label.name; +// if (!shouldTriggerE2E) { +// console.log( +// `Skipping E2E smoke since (${e2eLabel}) is not the label that triggered this workflow.`, +// ); +// } else { +// console.log( +// `Starting E2E smoke since (${e2eLabel}) is the label that triggered this workflow.`, +// ); +// } +// break; +// } + + if (shouldTriggerE2E) { + // Apply the E2E smoke label + const { owner, repo, number: issue_number } = context.issue; + const octokit: InstanceType = getOctokit(githubToken); + try { + const applyLabelResponse = await octokit.rest.issues.addLabels({ + owner, + repo, + issue_number, + labels: [e2eLabel], + }); + if (applyLabelResponse.status === 200) { + console.log(`Applied (${e2eLabel}) label to PR ${pullRequestLink}`); + } else { + core.setFailed( + `Failed to apply (${e2eLabel}) label to ${pullRequestLink}`, + ); + process.exit(1); + } + } catch (error) { + core.setFailed(`Error occured when applying label: ${error}`); + process.exit(1); + } + } + + // Set the output for the next step to use. + core.setOutput("shouldTriggerE2E", shouldTriggerE2E); +} diff --git a/.github/workflows/check-bitrise-status.yml b/.github/workflows/check-bitrise-status.yml new file mode 100644 index 00000000000..b8f5a46dfe0 --- /dev/null +++ b/.github/workflows/check-bitrise-status.yml @@ -0,0 +1,35 @@ +name: Check Bitrise Status + +on: + issue_comment: + types: [created] + pull_request: + types: [labeled, unlabeled] + +env: + E2E_LABEL: 'Run Smoke E2E' + +jobs: + check-bitrise-e2e-smoke: + runs-on: ubuntu-latest + if: ${{ github.event.issue.pull_request || github.event_name == 'pull_request' }} + permissions: + pull-requests: write + contents: write + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version-file: '.nvmrc' + cache: yarn + + - name: Install dependencies + run: yarn --immutable + + - name: Check Bitrise Status + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: yarn run check-bitrise-status diff --git a/package.json b/package.json index b2702ad3f64..46351268ee5 100644 --- a/package.json +++ b/package.json @@ -87,6 +87,7 @@ "create-release": "./scripts/set-versions.sh && yarn update-changelog", "add-release-label-to-pr-and-linked-issues": "ts-node ./.github/scripts/add-release-label-to-pr-and-linked-issues.ts", "check-e2e-smoke-trigger": "ts-node ./.github/scripts/check-bitrise-e2e-smoke/check-e2e-smoke-trigger.ts", + "check-bitrise-status": "ts-node ./.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts", "run-bitrise-e2e-smoke": "ts-node ./.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts", "check-pr-has-required-labels": "ts-node ./.github/scripts/check-pr-has-required-labels.ts", "close-release-bug-report-issue": "ts-node ./.github/scripts/close-release-bug-report-issue.ts", From 1fe01fd3195b72adcdc32dbe10b7a3d881d84f56 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Tue, 6 Feb 2024 17:09:45 -0800 Subject: [PATCH 06/73] Fix check-bitrise-status script --- .../check-bitrise-status.ts | 56 +++---------------- 1 file changed, 8 insertions(+), 48 deletions(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts b/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts index 89335c3881f..d2946848999 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts @@ -10,7 +10,6 @@ main().catch((error: Error): void => { async function main(): Promise { const githubToken = process.env.GITHUB_TOKEN; const e2eLabel = process.env.E2E_LABEL; - const pullRequestLink = `https://github.com/MetaMask/metamask-mobile/pull/${context.issue.number}`; if (!githubToken) { core.setFailed('GITHUB_TOKEN not found'); @@ -33,54 +32,15 @@ async function main(): Promise { return; } -// console.log(`Workflow triggered by the event (${triggerAction})`); + // Check if the "Bitrise build passed!" comment is posted + const { data: comments } = await octokit.rest.issues.listComments({ owner, repo, issue_number }); + const isBitriseSuccessStatus = comments.some(comment => { + return (comment.body || '').trim() === "Bitrise build passed!" + }); -// switch (triggerAction) { -// case PullRequestTriggerType.ReadyForReview: -// shouldTriggerE2E = true; -// console.log( -// `Starting E2E smoke since PR has changed to ready for review.`, -// ); -// break; -// case PullRequestTriggerType.Labeled: -// shouldTriggerE2E = e2eLabel === context.payload.label.name; -// if (!shouldTriggerE2E) { -// console.log( -// `Skipping E2E smoke since (${e2eLabel}) is not the label that triggered this workflow.`, -// ); -// } else { -// console.log( -// `Starting E2E smoke since (${e2eLabel}) is the label that triggered this workflow.`, -// ); -// } -// break; -// } - - if (shouldTriggerE2E) { - // Apply the E2E smoke label - const { owner, repo, number: issue_number } = context.issue; - const octokit: InstanceType = getOctokit(githubToken); - try { - const applyLabelResponse = await octokit.rest.issues.addLabels({ - owner, - repo, - issue_number, - labels: [e2eLabel], - }); - if (applyLabelResponse.status === 200) { - console.log(`Applied (${e2eLabel}) label to PR ${pullRequestLink}`); - } else { - core.setFailed( - `Failed to apply (${e2eLabel}) label to ${pullRequestLink}`, - ); - process.exit(1); - } - } catch (error) { - core.setFailed(`Error occured when applying label: ${error}`); - process.exit(1); - } + if (!isBitriseSuccessStatus) { + core.setFailed("Bitrise has not passed yet."); } - // Set the output for the next step to use. - core.setOutput("shouldTriggerE2E", shouldTriggerE2E); + console.log("Bitrise build has passed!") } From 9effdf55a46b596006e7d37331ea8fea65137290 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Tue, 6 Feb 2024 22:42:00 -0800 Subject: [PATCH 07/73] Try removing conditional --- .github/workflows/check-bitrise-status.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-bitrise-status.yml b/.github/workflows/check-bitrise-status.yml index b8f5a46dfe0..c3d43b80ea9 100644 --- a/.github/workflows/check-bitrise-status.yml +++ b/.github/workflows/check-bitrise-status.yml @@ -12,7 +12,7 @@ env: jobs: check-bitrise-e2e-smoke: runs-on: ubuntu-latest - if: ${{ github.event.issue.pull_request || github.event_name == 'pull_request' }} + # if: ${{ github.event.issue.pull_request || github.event_name == 'pull_request' }} permissions: pull-requests: write contents: write From 43d1079c1a198c9a1cb121ca550e97571d970857 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Tue, 6 Feb 2024 22:48:40 -0800 Subject: [PATCH 08/73] Remove condition --- .github/workflows/check-bitrise-status.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-bitrise-status.yml b/.github/workflows/check-bitrise-status.yml index c3d43b80ea9..c17845fa3cd 100644 --- a/.github/workflows/check-bitrise-status.yml +++ b/.github/workflows/check-bitrise-status.yml @@ -3,8 +3,8 @@ name: Check Bitrise Status on: issue_comment: types: [created] - pull_request: - types: [labeled, unlabeled] + # pull_request: + # types: [labeled, unlabeled] env: E2E_LABEL: 'Run Smoke E2E' From e55a296b708e5e06f7fc3675c182f5ff4608166e Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Tue, 6 Feb 2024 22:59:04 -0800 Subject: [PATCH 09/73] Update Bitrise message --- .github/workflows/check-bitrise-status.yml | 6 +++--- bitrise.yml | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/check-bitrise-status.yml b/.github/workflows/check-bitrise-status.yml index c17845fa3cd..b8f5a46dfe0 100644 --- a/.github/workflows/check-bitrise-status.yml +++ b/.github/workflows/check-bitrise-status.yml @@ -3,8 +3,8 @@ name: Check Bitrise Status on: issue_comment: types: [created] - # pull_request: - # types: [labeled, unlabeled] + pull_request: + types: [labeled, unlabeled] env: E2E_LABEL: 'Run Smoke E2E' @@ -12,7 +12,7 @@ env: jobs: check-bitrise-e2e-smoke: runs-on: ubuntu-latest - # if: ${{ github.event.issue.pull_request || github.event_name == 'pull_request' }} + if: ${{ github.event.issue.pull_request || github.event_name == 'pull_request' }} permissions: pull-requests: write contents: write diff --git a/bitrise.yml b/bitrise.yml index 379a9d39830..e49affc1266 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -273,10 +273,9 @@ workflows: inputs: - personal_access_token: '$GITHUB_ACCESS_TOKEN' - body: |- - HELLO - $BITRISE_PUBLIC_INSTALL_PAGE_URL + Bitrise build passed! - repository_url: '$GIT_REPOSITORY_URL' - - issue_number: 8495 + - issue_number: '$BITRISE_PULL_REQUEST' - api_base_url: 'https://api.github.com' # - slack@3: # inputs: From ad586b1e9055ec4fa9f18c3d0e10fbff1cbf3a44 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Wed, 7 Feb 2024 01:21:10 -0800 Subject: [PATCH 10/73] Pass PR number to bitrise build --- .github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts index ba41e29745b..4e3677c1057 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts @@ -39,6 +39,7 @@ async function main(): Promise { branch: process.env.GITHUB_HEAD_REF, pipeline_id: e2ePipeline, commit_message: `Triggered by (${workflowName}) workflow in ${pullRequestLink}`, + pull_request_id: pullRequestNumber }, triggered_by: workflowName, }; From 5549e150c89f32a3e1a71def107fd5ac9458a56c Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Wed, 7 Feb 2024 01:27:00 -0800 Subject: [PATCH 11/73] Remove PR id --- .../scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts index 4e3677c1057..61a650c0724 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts @@ -39,7 +39,7 @@ async function main(): Promise { branch: process.env.GITHUB_HEAD_REF, pipeline_id: e2ePipeline, commit_message: `Triggered by (${workflowName}) workflow in ${pullRequestLink}`, - pull_request_id: pullRequestNumber + // pull_request_id: pullRequestNumber }, triggered_by: workflowName, }; From bf3424ca94c464baa40d1f08994d0cdc6483b71f Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Wed, 7 Feb 2024 01:33:12 -0800 Subject: [PATCH 12/73] Put PR number --- .../run-bitrise-e2e-smoke.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts index 61a650c0724..0d49cb3c300 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts @@ -57,13 +57,16 @@ async function main(): Promise { }, ); - if (!bitriseBuildResponse.data.build_slug) { - core.setFailed(`Bitrise build slug not found`); - process.exit(1); - } + // if (!bitriseBuildResponse.data.build_slug) { + // core.setFailed(`Bitrise build slug not found`); + // process.exit(1); + // } + + // const buildLink = `${bitriseProjectUrl}/pipelines/${bitriseBuildResponse.data.build_slug}`; + // const message = `E2E test started on Bitrise: ${buildLink}\nYou can also kick off another Bitrise E2E smoke test by removing and re-applying the (${e2eLabel}) label`; + const message = 'hello' - const buildLink = `${bitriseProjectUrl}/pipelines/${bitriseBuildResponse.data.build_slug}`; - const message = `E2E test started on Bitrise: ${buildLink}\nYou can also kick off another Bitrise E2E smoke test by removing and re-applying the (${e2eLabel}) label`; + console.log(bitriseBuildResponse) if (bitriseBuildResponse.status === 201) { console.log(message); From c3a13ccdcd36d765ab1e715aad3194a754c281f8 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Wed, 7 Feb 2024 01:40:07 -0800 Subject: [PATCH 13/73] Provide PR number as env var --- .../run-bitrise-e2e-smoke.ts | 23 +++++++++++-------- bitrise.yml | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts index 0d49cb3c300..047f107bbd3 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts @@ -39,7 +39,13 @@ async function main(): Promise { branch: process.env.GITHUB_HEAD_REF, pipeline_id: e2ePipeline, commit_message: `Triggered by (${workflowName}) workflow in ${pullRequestLink}`, - // pull_request_id: pullRequestNumber + environments: [ + { + "is_expand": true, + "mapped_to": "GITHUB_PR_NUMBER", + "value": pullRequestNumber + } + ], }, triggered_by: workflowName, }; @@ -57,16 +63,13 @@ async function main(): Promise { }, ); - // if (!bitriseBuildResponse.data.build_slug) { - // core.setFailed(`Bitrise build slug not found`); - // process.exit(1); - // } - - // const buildLink = `${bitriseProjectUrl}/pipelines/${bitriseBuildResponse.data.build_slug}`; - // const message = `E2E test started on Bitrise: ${buildLink}\nYou can also kick off another Bitrise E2E smoke test by removing and re-applying the (${e2eLabel}) label`; - const message = 'hello' + if (!bitriseBuildResponse.data.build_slug) { + core.setFailed(`Bitrise build slug not found`); + process.exit(1); + } - console.log(bitriseBuildResponse) + const buildLink = `${bitriseProjectUrl}/pipelines/${bitriseBuildResponse.data.build_slug}`; + const message = `E2E test started on Bitrise: ${buildLink}\nYou can also kick off another Bitrise E2E smoke test by removing and re-applying the (${e2eLabel}) label`; if (bitriseBuildResponse.status === 201) { console.log(message); diff --git a/bitrise.yml b/bitrise.yml index e49affc1266..88437554b15 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -275,7 +275,7 @@ workflows: - body: |- Bitrise build passed! - repository_url: '$GIT_REPOSITORY_URL' - - issue_number: '$BITRISE_PULL_REQUEST' + - issue_number: '$GITHUB_PR_NUMBER' - api_base_url: 'https://api.github.com' # - slack@3: # inputs: From d158b51215a0a85b9cdc70fa33f0e4426b0f8239 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Wed, 7 Feb 2024 01:47:07 -0800 Subject: [PATCH 14/73] Use new bitrise endpoint --- .../run-bitrise-e2e-smoke.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts index 047f107bbd3..71422b8c1b5 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts @@ -39,22 +39,22 @@ async function main(): Promise { branch: process.env.GITHUB_HEAD_REF, pipeline_id: e2ePipeline, commit_message: `Triggered by (${workflowName}) workflow in ${pullRequestLink}`, - environments: [ - { - "is_expand": true, - "mapped_to": "GITHUB_PR_NUMBER", - "value": pullRequestNumber - } - ], + // environments: [ + // { + // "is_expand": true, + // "mapped_to": "GITHUB_PR_NUMBER", + // "value": pullRequestNumber + // } + // ], }, triggered_by: workflowName, }; - const bitriseProjectUrl = `https://app.bitrise.io/app/${process.env.BITRISE_APP_ID}`; + const bitriseProjectUrl = `https://api.bitrise.io/v0.1/apps/${process.env.BITRISE_APP_ID}/builds`; // Start Bitrise build. const bitriseBuildResponse = await axios.post( - `${bitriseProjectUrl}/build/start.json`, + bitriseProjectUrl, data, { headers: { From 520c27ce94db4ee3e29bed97dd5cac133b942e90 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Wed, 7 Feb 2024 01:53:27 -0800 Subject: [PATCH 15/73] Update bitrise headers --- .../scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts index 71422b8c1b5..cb88c4e1fdc 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts @@ -33,7 +33,6 @@ async function main(): Promise { const data = { hook_info: { type: 'bitrise', - build_trigger_token: process.env.BITRISE_BUILD_TRIGGER_TOKEN, }, build_params: { branch: process.env.GITHUB_HEAD_REF, @@ -58,6 +57,7 @@ async function main(): Promise { data, { headers: { + 'Authorization': `Bearer ${process.env.BITRISE_BUILD_TRIGGER_TOKEN}`, 'Content-Type': 'application/json', }, }, From 737b6a066284a7d900b56a6dd1cd9f2f53f7b385 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Tue, 20 Feb 2024 14:10:52 -0800 Subject: [PATCH 16/73] Pass PR number as env var --- .../run-bitrise-e2e-smoke.ts | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts index cb88c4e1fdc..74d997560ed 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts @@ -38,13 +38,13 @@ async function main(): Promise { branch: process.env.GITHUB_HEAD_REF, pipeline_id: e2ePipeline, commit_message: `Triggered by (${workflowName}) workflow in ${pullRequestLink}`, - // environments: [ - // { - // "is_expand": true, - // "mapped_to": "GITHUB_PR_NUMBER", - // "value": pullRequestNumber - // } - // ], + environments: [ + { + mapped_to: 'GITHUB_PR_NUMBER', + value: pullRequestNumber, + is_expand: true, + }, + ], }, triggered_by: workflowName, }; @@ -52,16 +52,12 @@ async function main(): Promise { const bitriseProjectUrl = `https://api.bitrise.io/v0.1/apps/${process.env.BITRISE_APP_ID}/builds`; // Start Bitrise build. - const bitriseBuildResponse = await axios.post( - bitriseProjectUrl, - data, - { - headers: { - 'Authorization': `Bearer ${process.env.BITRISE_BUILD_TRIGGER_TOKEN}`, - 'Content-Type': 'application/json', - }, + const bitriseBuildResponse = await axios.post(bitriseProjectUrl, data, { + headers: { + Authorization: `Bearer ${process.env.BITRISE_BUILD_TRIGGER_TOKEN}`, + 'Content-Type': 'application/json', }, - ); + }); if (!bitriseBuildResponse.data.build_slug) { core.setFailed(`Bitrise build slug not found`); From 464c88d717088b5f385193d0d213da1ce51acb0c Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Tue, 20 Feb 2024 14:17:11 -0800 Subject: [PATCH 17/73] Comment out environments --- .../run-bitrise-e2e-smoke.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts index 74d997560ed..82b9156a2f8 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts @@ -38,13 +38,13 @@ async function main(): Promise { branch: process.env.GITHUB_HEAD_REF, pipeline_id: e2ePipeline, commit_message: `Triggered by (${workflowName}) workflow in ${pullRequestLink}`, - environments: [ - { - mapped_to: 'GITHUB_PR_NUMBER', - value: pullRequestNumber, - is_expand: true, - }, - ], + // environments: [ + // { + // mapped_to: 'GITHUB_PR_NUMBER', + // value: pullRequestNumber, + // is_expand: true, + // }, + // ], }, triggered_by: workflowName, }; From cdadf86836fc9089f8928765acebfb78d64face7 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Tue, 20 Feb 2024 14:24:17 -0800 Subject: [PATCH 18/73] Change api back to original --- .../run-bitrise-e2e-smoke.ts | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts index 82b9156a2f8..fdd2d32ddaa 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts @@ -33,31 +33,35 @@ async function main(): Promise { const data = { hook_info: { type: 'bitrise', + build_trigger_token: process.env.BITRISE_BUILD_TRIGGER_TOKEN, }, build_params: { branch: process.env.GITHUB_HEAD_REF, pipeline_id: e2ePipeline, commit_message: `Triggered by (${workflowName}) workflow in ${pullRequestLink}`, - // environments: [ - // { - // mapped_to: 'GITHUB_PR_NUMBER', - // value: pullRequestNumber, - // is_expand: true, - // }, - // ], + environments: [ + { + mapped_to: 'GITHUB_PR_NUMBER', + value: pullRequestNumber, + is_expand: true, + }, + ], }, triggered_by: workflowName, }; - const bitriseProjectUrl = `https://api.bitrise.io/v0.1/apps/${process.env.BITRISE_APP_ID}/builds`; + const bitriseProjectUrl = `https://app.bitrise.io/app/${process.env.BITRISE_APP_ID}`; // Start Bitrise build. - const bitriseBuildResponse = await axios.post(bitriseProjectUrl, data, { - headers: { - Authorization: `Bearer ${process.env.BITRISE_BUILD_TRIGGER_TOKEN}`, - 'Content-Type': 'application/json', + const bitriseBuildResponse = await axios.post( + `${bitriseProjectUrl}/build/start.json`, + data, + { + headers: { + 'Content-Type': 'application/json', + }, }, - }); + ); if (!bitriseBuildResponse.data.build_slug) { core.setFailed(`Bitrise build slug not found`); From ea2ce3798e8642446c4ce61bf222f8fd9e3ac3af Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Tue, 20 Feb 2024 14:29:56 -0800 Subject: [PATCH 19/73] Remove environments --- .../run-bitrise-e2e-smoke.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts index fdd2d32ddaa..244d694acaa 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts @@ -39,13 +39,13 @@ async function main(): Promise { branch: process.env.GITHUB_HEAD_REF, pipeline_id: e2ePipeline, commit_message: `Triggered by (${workflowName}) workflow in ${pullRequestLink}`, - environments: [ - { - mapped_to: 'GITHUB_PR_NUMBER', - value: pullRequestNumber, - is_expand: true, - }, - ], + // environments: [ + // { + // mapped_to: 'GITHUB_PR_NUMBER', + // value: pullRequestNumber, + // is_expand: true, + // }, + // ], }, triggered_by: workflowName, }; From 7a358ed6db96bca04c8d4e5962897850e6b1d287 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Tue, 20 Feb 2024 14:39:09 -0800 Subject: [PATCH 20/73] Simplify Bitrise call --- .../run-bitrise-e2e-smoke.ts | 34 +++++++------------ 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts index 244d694acaa..ff8354b9062 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts @@ -31,37 +31,29 @@ async function main(): Promise { const octokit: InstanceType = getOctokit(githubToken); const data = { - hook_info: { - type: 'bitrise', - build_trigger_token: process.env.BITRISE_BUILD_TRIGGER_TOKEN, - }, build_params: { branch: process.env.GITHUB_HEAD_REF, pipeline_id: e2ePipeline, + environments: [ + { + mapped_to: 'GITHUB_PR_NUMBER', + value: pullRequestNumber, + is_expand: true, + }, + ], commit_message: `Triggered by (${workflowName}) workflow in ${pullRequestLink}`, - // environments: [ - // { - // mapped_to: 'GITHUB_PR_NUMBER', - // value: pullRequestNumber, - // is_expand: true, - // }, - // ], + }, + hook_info: { + type: 'bitrise', + build_trigger_token: process.env.BITRISE_BUILD_TRIGGER_TOKEN, }, triggered_by: workflowName, }; - const bitriseProjectUrl = `https://app.bitrise.io/app/${process.env.BITRISE_APP_ID}`; + const bitriseProjectUrl = `https://app.bitrise.io/app/${process.env.BITRISE_APP_ID}/build/start.json`; // Start Bitrise build. - const bitriseBuildResponse = await axios.post( - `${bitriseProjectUrl}/build/start.json`, - data, - { - headers: { - 'Content-Type': 'application/json', - }, - }, - ); + const bitriseBuildResponse = await axios.post(bitriseProjectUrl, data); if (!bitriseBuildResponse.data.build_slug) { core.setFailed(`Bitrise build slug not found`); From 762d1da06038b3568cd54a647c94a1600b696008 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Tue, 20 Feb 2024 14:42:40 -0800 Subject: [PATCH 21/73] Remove env vars --- .../run-bitrise-e2e-smoke.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts index ff8354b9062..bba092b1b50 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts @@ -34,13 +34,13 @@ async function main(): Promise { build_params: { branch: process.env.GITHUB_HEAD_REF, pipeline_id: e2ePipeline, - environments: [ - { - mapped_to: 'GITHUB_PR_NUMBER', - value: pullRequestNumber, - is_expand: true, - }, - ], + // environments: [ + // { + // mapped_to: 'GITHUB_PR_NUMBER', + // value: pullRequestNumber, + // is_expand: true, + // }, + // ], commit_message: `Triggered by (${workflowName}) workflow in ${pullRequestLink}`, }, hook_info: { From ee261d3a1888728a6fb14d586ad38a0fd3b1464b Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Tue, 20 Feb 2024 14:48:19 -0800 Subject: [PATCH 22/73] Specify application json --- .../run-bitrise-e2e-smoke.ts | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts index bba092b1b50..8de12634a2e 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts @@ -34,13 +34,13 @@ async function main(): Promise { build_params: { branch: process.env.GITHUB_HEAD_REF, pipeline_id: e2ePipeline, - // environments: [ - // { - // mapped_to: 'GITHUB_PR_NUMBER', - // value: pullRequestNumber, - // is_expand: true, - // }, - // ], + environments: [ + { + mapped_to: 'GITHUB_PR_NUMBER', + value: pullRequestNumber, + is_expand: true, + }, + ], commit_message: `Triggered by (${workflowName}) workflow in ${pullRequestLink}`, }, hook_info: { @@ -53,7 +53,11 @@ async function main(): Promise { const bitriseProjectUrl = `https://app.bitrise.io/app/${process.env.BITRISE_APP_ID}/build/start.json`; // Start Bitrise build. - const bitriseBuildResponse = await axios.post(bitriseProjectUrl, data); + const bitriseBuildResponse = await axios.post(bitriseProjectUrl, data, { + headers: { + 'Content-Type': 'application/json', + }, + }); if (!bitriseBuildResponse.data.build_slug) { core.setFailed(`Bitrise build slug not found`); From 2a27413036243615d94daa91e316ffd4b1d390d7 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Tue, 20 Feb 2024 15:00:07 -0800 Subject: [PATCH 23/73] Pass env vars as strings --- .../scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts index 8de12634a2e..c08f43edcfb 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts @@ -37,7 +37,7 @@ async function main(): Promise { environments: [ { mapped_to: 'GITHUB_PR_NUMBER', - value: pullRequestNumber, + value: `${pullRequestNumber}`, is_expand: true, }, ], From de695962e4417819020eb9e2916eed085d560ce8 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Tue, 20 Feb 2024 15:13:06 -0800 Subject: [PATCH 24/73] Adjust bitrise message --- .../check-bitrise-status.ts | 26 +++++++++++++------ bitrise.yml | 2 +- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts b/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts index d2946848999..3a10a68789f 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts @@ -24,23 +24,33 @@ async function main(): Promise { // Check if the "Run Smoke E2E" label is applied const { owner, repo, number: issue_number } = context.issue; const octokit: InstanceType = getOctokit(githubToken); - const { data: labels } = await octokit.rest.issues.listLabelsOnIssue({ owner, repo, issue_number }); - const hasSmokeTestLabel = labels.some(label => label.name === e2eLabel); + const { data: labels } = await octokit.rest.issues.listLabelsOnIssue({ + owner, + repo, + issue_number, + }); + const hasSmokeTestLabel = labels.some((label) => label.name === e2eLabel); if (!hasSmokeTestLabel) { - console.log(`"${e2eLabel}" label not applied. Skipping Bitrise status check.`) + console.log( + `"${e2eLabel}" label not applied. Skipping Bitrise status check.`, + ); return; } // Check if the "Bitrise build passed!" comment is posted - const { data: comments } = await octokit.rest.issues.listComments({ owner, repo, issue_number }); - const isBitriseSuccessStatus = comments.some(comment => { - return (comment.body || '').trim() === "Bitrise build passed!" + const { data: comments } = await octokit.rest.issues.listComments({ + owner, + repo, + issue_number, + }); + const isBitriseSuccessStatus = comments.some((comment) => { + return comment.body?.includes('Bitrise E2E smoke tests passed!'); }); if (!isBitriseSuccessStatus) { - core.setFailed("Bitrise has not passed yet."); + core.setFailed('Bitrise has not passed yet.'); } - console.log("Bitrise build has passed!") + console.log('Bitrise build has passed!'); } diff --git a/bitrise.yml b/bitrise.yml index 88437554b15..0a1336073bb 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -273,7 +273,7 @@ workflows: inputs: - personal_access_token: '$GITHUB_ACCESS_TOKEN' - body: |- - Bitrise build passed! + Bitrise E2E smoke tests passed ✅: "${BITRISE_BUILD_URL}" - repository_url: '$GIT_REPOSITORY_URL' - issue_number: '$GITHUB_PR_NUMBER' - api_base_url: 'https://api.github.com' From 42638960b650ac21e6aeceb9aa7335245ca3d7ff Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Tue, 20 Feb 2024 15:26:20 -0800 Subject: [PATCH 25/73] Refine messages --- .../scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts | 5 +++-- bitrise.yml | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts index c08f43edcfb..a2755402208 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts @@ -50,10 +50,11 @@ async function main(): Promise { triggered_by: workflowName, }; - const bitriseProjectUrl = `https://app.bitrise.io/app/${process.env.BITRISE_APP_ID}/build/start.json`; + const bitriseProjectUrl = `https://app.bitrise.io/app/${process.env.BITRISE_APP_ID}`; + const bitriseBuildStartUrl = `${bitriseProjectUrl}/build/start.json`; // Start Bitrise build. - const bitriseBuildResponse = await axios.post(bitriseProjectUrl, data, { + const bitriseBuildResponse = await axios.post(bitriseBuildStartUrl, data, { headers: { 'Content-Type': 'application/json', }, diff --git a/bitrise.yml b/bitrise.yml index 0a1336073bb..97cb6ee3270 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -273,7 +273,7 @@ workflows: inputs: - personal_access_token: '$GITHUB_ACCESS_TOKEN' - body: |- - Bitrise E2E smoke tests passed ✅: "${BITRISE_BUILD_URL}" + Bitrise E2E smoke tests passed ✅: ${BITRISE_BUILD_URL} - repository_url: '$GIT_REPOSITORY_URL' - issue_number: '$GITHUB_PR_NUMBER' - api_base_url: 'https://api.github.com' From bb48a45c2d7b3eff81a767eb07349146430d4ec6 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Tue, 20 Feb 2024 15:46:34 -0800 Subject: [PATCH 26/73] Log comment body --- .github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts b/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts index 3a10a68789f..048397c7b50 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts @@ -45,6 +45,7 @@ async function main(): Promise { issue_number, }); const isBitriseSuccessStatus = comments.some((comment) => { + console.log('COMMENT', comment.body); return comment.body?.includes('Bitrise E2E smoke tests passed!'); }); From 04563cae8996a39c59b0289b80f8858697696623 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Tue, 20 Feb 2024 15:54:06 -0800 Subject: [PATCH 27/73] Provide logs --- .../check-bitrise-e2e-smoke/check-bitrise-status.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts b/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts index 048397c7b50..c2a45c44d5e 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts @@ -45,8 +45,11 @@ async function main(): Promise { issue_number, }); const isBitriseSuccessStatus = comments.some((comment) => { - console.log('COMMENT', comment.body); - return comment.body?.includes('Bitrise E2E smoke tests passed!'); + const includesPass = comment.body?.includes( + 'Bitrise E2E smoke tests passed!', + ); + console.log('COMMENT', comment.body, includesPass); + return includesPass; }); if (!isBitriseSuccessStatus) { From 40f86012a46bb09ffd06da49bca6afb2ca726f39 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Tue, 20 Feb 2024 15:59:15 -0800 Subject: [PATCH 28/73] Fix typo --- .../scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts b/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts index c2a45c44d5e..f15e34e7cef 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts @@ -46,9 +46,8 @@ async function main(): Promise { }); const isBitriseSuccessStatus = comments.some((comment) => { const includesPass = comment.body?.includes( - 'Bitrise E2E smoke tests passed!', + 'Bitrise E2E smoke tests passed', ); - console.log('COMMENT', comment.body, includesPass); return includesPass; }); From 01bc82397e00d5585872bd7d759c82a52bf9acc4 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Wed, 21 Feb 2024 16:11:15 -0800 Subject: [PATCH 29/73] Update action triggers --- .github/workflows/check-bitrise-status.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-bitrise-status.yml b/.github/workflows/check-bitrise-status.yml index b8f5a46dfe0..9a1b464654c 100644 --- a/.github/workflows/check-bitrise-status.yml +++ b/.github/workflows/check-bitrise-status.yml @@ -4,7 +4,7 @@ on: issue_comment: types: [created] pull_request: - types: [labeled, unlabeled] + types: [opened, reopened, labeled, unlabeled] env: E2E_LABEL: 'Run Smoke E2E' From 544fa8f805c8fc9da66db4f3f7e8531554a756a4 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Wed, 21 Feb 2024 17:22:21 -0800 Subject: [PATCH 30/73] Conditionally run comment step --- .../run-bitrise-e2e-smoke.ts | 5 ++ bitrise.yml | 49 ++++++++++--------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts index a2755402208..b7efae19268 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts @@ -40,6 +40,11 @@ async function main(): Promise { value: `${pullRequestNumber}`, is_expand: true, }, + { + mapped_to: 'TRIGGERED_BY_LABEL', + value: `true`, + is_expand: true, + }, ], commit_message: `Triggered by (${workflowName}) workflow in ${pullRequestLink}`, }, diff --git a/bitrise.yml b/bitrise.yml index 97cb6ee3270..8872506b6b3 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -51,8 +51,8 @@ pipelines: #PR_e2e_verfication (build ios & android), run iOS (smoke), emulator Android pr_smoke_e2e_pipeline: stages: - # - build_smoke_e2e_ios_android_stage: {} - # - run_smoke_e2e_ios_android_stage: {} + - build_smoke_e2e_ios_android_stage: {} + - run_smoke_e2e_ios_android_stage: {} - notify: {} # Pipeline for Flask create_flask_release_builds_pipeline: @@ -147,7 +147,7 @@ stages: notify: workflows: - - notify_success_on_slack: {} + - notify_success: {} release_notify: workflows: - release_announcing_stores: {} @@ -265,11 +265,12 @@ workflows: machine_type_id: standard # Send a Slack message when workflow succeeds - notify_success_on_slack: - # before_run: - # - _get_workflow_info + notify_success: + before_run: + - _get_workflow_info steps: - comment-on-github-pull-request@0: + run_if: '{{getenv "TRIGGERED_BY_LABEL" | eq "true"}}' inputs: - personal_access_token: '$GITHUB_ACCESS_TOKEN' - body: |- @@ -277,24 +278,24 @@ workflows: - repository_url: '$GIT_REPOSITORY_URL' - issue_number: '$GITHUB_PR_NUMBER' - api_base_url: 'https://api.github.com' - # - slack@3: - # inputs: - # - text: '${BITRISE_APP_TITLE} ${BITRISEIO_PIPELINE_TITLE} workflow notification' - # - pretext: ':large_green_circle: *${BITRISEIO_PIPELINE_TITLE} succeeded!*' - # - title: 'Commit #$COMMIT_SHORT_HASH $BRANCH_HEIGHT' - # - title_link: https://github.com/${BITRISEIO_GIT_REPOSITORY_OWNER}/${BITRISEIO_GIT_REPOSITORY_SLUG}/commit/${COMMIT_SHORT_HASH} - # - message: ${BITRISE_GIT_MESSAGE} - # - fields: | - # Branch|${BITRISE_GIT_BRANCH} - # Workflow|${BITRISEIO_PIPELINE_TITLE} - # Trigger|${WORKFLOW_TRIGGER} - # Build|${BITRISE_BUILD_NUMBER} - # - buttons: | - # View app|${BITRISE_APP_URL} - # View build|${BITRISEIO_PIPELINE_BUILD_URL} - # View commit|https://github.com/${BITRISEIO_GIT_REPOSITORY_OWNER}/${BITRISEIO_GIT_REPOSITORY_SLUG}/commit/${COMMIT_SHORT_HASH} - # - footer: 'Bitrise ${BITRISEIO_PIPELINE_TITLE} workflow notification' - # - webhook_url: https://hooks.slack.com/services/${MM_SLACK_TOKEN}/${MM_SLACK_SECRET}/${MM_SLACK_ROOM} + - slack@3: + inputs: + - text: '${BITRISE_APP_TITLE} ${BITRISEIO_PIPELINE_TITLE} workflow notification' + - pretext: ':large_green_circle: *${BITRISEIO_PIPELINE_TITLE} succeeded!*' + - title: 'Commit #$COMMIT_SHORT_HASH $BRANCH_HEIGHT' + - title_link: https://github.com/${BITRISEIO_GIT_REPOSITORY_OWNER}/${BITRISEIO_GIT_REPOSITORY_SLUG}/commit/${COMMIT_SHORT_HASH} + - message: ${BITRISE_GIT_MESSAGE} + - fields: | + Branch|${BITRISE_GIT_BRANCH} + Workflow|${BITRISEIO_PIPELINE_TITLE} + Trigger|${WORKFLOW_TRIGGER} + Build|${BITRISE_BUILD_NUMBER} + - buttons: | + View app|${BITRISE_APP_URL} + View build|${BITRISEIO_PIPELINE_BUILD_URL} + View commit|https://github.com/${BITRISEIO_GIT_REPOSITORY_OWNER}/${BITRISEIO_GIT_REPOSITORY_SLUG}/commit/${COMMIT_SHORT_HASH} + - footer: 'Bitrise ${BITRISEIO_PIPELINE_TITLE} workflow notification' + - webhook_url: https://hooks.slack.com/services/${MM_SLACK_TOKEN}/${MM_SLACK_SECRET}/${MM_SLACK_ROOM} # Send a Slack message when workflow fails _notify_failure_on_slack: From 0d63325ee3b94475bae46cda3f1d72c462286cf3 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Wed, 21 Feb 2024 22:16:54 -0800 Subject: [PATCH 31/73] Try setting pipeline build url --- bitrise.yml | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/bitrise.yml b/bitrise.yml index 8872506b6b3..87371e3eecd 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -51,8 +51,9 @@ pipelines: #PR_e2e_verfication (build ios & android), run iOS (smoke), emulator Android pr_smoke_e2e_pipeline: stages: - - build_smoke_e2e_ios_android_stage: {} - - run_smoke_e2e_ios_android_stage: {} + - set_build_variables: {} + # - build_smoke_e2e_ios_android_stage: {} + # - run_smoke_e2e_ios_android_stage: {} - notify: {} # Pipeline for Flask create_flask_release_builds_pipeline: @@ -144,7 +145,9 @@ stages: run_e2e_android_stage: workflows: - android_e2e_test: {} - + set_build_variables: + workflows: + - set_build_url_env_var: {} notify: workflows: - notify_success: {} @@ -264,6 +267,19 @@ workflows: stack: linux-docker-android-20.04 machine_type_id: standard + set_build_url_env_var: + steps: + - script@1: + title: Add pipeline build url as env var + inputs: + - content: |- + envman add --key BITRISE_PIPELINE_BUILD_URL --value "${BITRISE_BUILD_URL}" + - share-pipeline-variable@1: + title: Persist pipeline build url env var + inputs: + - variables: |- + BITRISE_PIPELINE_BUILD_URL + # Send a Slack message when workflow succeeds notify_success: before_run: @@ -274,7 +290,7 @@ workflows: inputs: - personal_access_token: '$GITHUB_ACCESS_TOKEN' - body: |- - Bitrise E2E smoke tests passed ✅: ${BITRISE_BUILD_URL} + Bitrise E2E smoke tests passed ✅: ${BITRISE_PIPELINE_BUILD_URL} - repository_url: '$GIT_REPOSITORY_URL' - issue_number: '$GITHUB_PR_NUMBER' - api_base_url: 'https://api.github.com' From f0be5e19b162f420d5c2ce4d7d542f75e56df508 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Wed, 21 Feb 2024 22:33:32 -0800 Subject: [PATCH 32/73] Use pipeline build url --- bitrise.yml | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/bitrise.yml b/bitrise.yml index 87371e3eecd..85ab948765d 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -51,7 +51,6 @@ pipelines: #PR_e2e_verfication (build ios & android), run iOS (smoke), emulator Android pr_smoke_e2e_pipeline: stages: - - set_build_variables: {} # - build_smoke_e2e_ios_android_stage: {} # - run_smoke_e2e_ios_android_stage: {} - notify: {} @@ -267,19 +266,6 @@ workflows: stack: linux-docker-android-20.04 machine_type_id: standard - set_build_url_env_var: - steps: - - script@1: - title: Add pipeline build url as env var - inputs: - - content: |- - envman add --key BITRISE_PIPELINE_BUILD_URL --value "${BITRISE_BUILD_URL}" - - share-pipeline-variable@1: - title: Persist pipeline build url env var - inputs: - - variables: |- - BITRISE_PIPELINE_BUILD_URL - # Send a Slack message when workflow succeeds notify_success: before_run: @@ -290,7 +276,7 @@ workflows: inputs: - personal_access_token: '$GITHUB_ACCESS_TOKEN' - body: |- - Bitrise E2E smoke tests passed ✅: ${BITRISE_PIPELINE_BUILD_URL} + Bitrise E2E smoke tests passed ✅: ${BITRISEIO_PIPELINE_BUILD_URL} - repository_url: '$GIT_REPOSITORY_URL' - issue_number: '$GITHUB_PR_NUMBER' - api_base_url: 'https://api.github.com' From ca0729372b0fd8392e92cf97f2cb1159cc1a29b3 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Wed, 21 Feb 2024 22:40:19 -0800 Subject: [PATCH 33/73] Update comment --- .../check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts index b7efae19268..0471c9cb601 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts @@ -16,6 +16,7 @@ async function main(): Promise { const pullRequestNumber = context.issue.number; const repoOwner = context.repo.owner; const repo = context.repo.repo; + const commitHash = context.sha.slice(0, 6); const pullRequestLink = `https://github.com/MetaMask/metamask-mobile/pull/${pullRequestNumber}`; if (!githubToken) { @@ -45,6 +46,11 @@ async function main(): Promise { value: `true`, is_expand: true, }, + { + mapped_to: 'GITHUB_PR_HASH', + value: `${commitHash}`, + is_expand: true, + }, ], commit_message: `Triggered by (${workflowName}) workflow in ${pullRequestLink}`, }, @@ -71,7 +77,7 @@ async function main(): Promise { } const buildLink = `${bitriseProjectUrl}/pipelines/${bitriseBuildResponse.data.build_slug}`; - const message = `E2E test started on Bitrise: ${buildLink}\nYou can also kick off another Bitrise E2E smoke test by removing and re-applying the (${e2eLabel}) label`; + const message = `E2E test started on Bitrise for commit hash ${commitHash}: ${buildLink}\nYou can also kick off another Bitrise E2E smoke test by removing and re-applying the (${e2eLabel}) label`; if (bitriseBuildResponse.status === 201) { console.log(message); From 2068fa4346a7303d4fa93bc34a0f1518d5b78460 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Wed, 21 Feb 2024 22:43:21 -0800 Subject: [PATCH 34/73] Remove unused workflow --- bitrise.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/bitrise.yml b/bitrise.yml index 85ab948765d..793f71242a7 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -144,9 +144,6 @@ stages: run_e2e_android_stage: workflows: - android_e2e_test: {} - set_build_variables: - workflows: - - set_build_url_env_var: {} notify: workflows: - notify_success: {} From 4be9a61300691e9b429c5599a99c0a6b4668cb47 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Wed, 21 Feb 2024 22:49:19 -0800 Subject: [PATCH 35/73] Update message format --- .../scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts | 2 +- bitrise.yml | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts index 0471c9cb601..00e591980bb 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts @@ -77,7 +77,7 @@ async function main(): Promise { } const buildLink = `${bitriseProjectUrl}/pipelines/${bitriseBuildResponse.data.build_slug}`; - const message = `E2E test started on Bitrise for commit hash ${commitHash}: ${buildLink}\nYou can also kick off another Bitrise E2E smoke test by removing and re-applying the (${e2eLabel}) label`; + const message = `E2E test started on Bitrise\n\nCommit hash: ${commitHash}\nBuild link: ${buildLink}\n\nYou can also kick off another Bitrise E2E smoke test by removing and re-applying the (${e2eLabel}) label`; if (bitriseBuildResponse.status === 201) { console.log(message); diff --git a/bitrise.yml b/bitrise.yml index 793f71242a7..2a8d1969a5b 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -273,7 +273,10 @@ workflows: inputs: - personal_access_token: '$GITHUB_ACCESS_TOKEN' - body: |- - Bitrise E2E smoke tests passed ✅: ${BITRISEIO_PIPELINE_BUILD_URL} + Bitrise E2E smoke tests passed ✅ + + Commit hash: ${GITHUB_PR_HASH} + Build link: ${BITRISEIO_PIPELINE_BUILD_URL} - repository_url: '$GIT_REPOSITORY_URL' - issue_number: '$GITHUB_PR_NUMBER' - api_base_url: 'https://api.github.com' From 64c57ebb62872f8e2963dfbad65495555cf3cfcc Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Wed, 21 Feb 2024 23:11:16 -0800 Subject: [PATCH 36/73] Add comment tag to replace comment --- .../scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts | 2 +- bitrise.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts index 00e591980bb..b1a6bf143b7 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts @@ -77,7 +77,7 @@ async function main(): Promise { } const buildLink = `${bitriseProjectUrl}/pipelines/${bitriseBuildResponse.data.build_slug}`; - const message = `E2E test started on Bitrise\n\nCommit hash: ${commitHash}\nBuild link: ${buildLink}\n\nYou can also kick off another Bitrise E2E smoke test by removing and re-applying the (${e2eLabel}) label`; + const message = `E2E test started on Bitrise...\n\nCommit hash: ${commitHash}\nBuild link: ${buildLink}\n\nYou can also kick off another Bitrise E2E smoke test by removing and re-applying the (${e2eLabel}) label\n\nComment tag: ${commitHash}`; if (bitriseBuildResponse.status === 201) { console.log(message); diff --git a/bitrise.yml b/bitrise.yml index 2a8d1969a5b..179b4d6ddb2 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -280,6 +280,7 @@ workflows: - repository_url: '$GIT_REPOSITORY_URL' - issue_number: '$GITHUB_PR_NUMBER' - api_base_url: 'https://api.github.com' + - comment_tag: '$GITHUB_PR_HASH' - slack@3: inputs: - text: '${BITRISE_APP_TITLE} ${BITRISEIO_PIPELINE_TITLE} workflow notification' From 99d2c65c3731be8304c50522a0cb336a108801a0 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Wed, 21 Feb 2024 23:20:57 -0800 Subject: [PATCH 37/73] Add tag syntax --- .../scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts index b1a6bf143b7..71c827056bc 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts @@ -77,7 +77,7 @@ async function main(): Promise { } const buildLink = `${bitriseProjectUrl}/pipelines/${bitriseBuildResponse.data.build_slug}`; - const message = `E2E test started on Bitrise...\n\nCommit hash: ${commitHash}\nBuild link: ${buildLink}\n\nYou can also kick off another Bitrise E2E smoke test by removing and re-applying the (${e2eLabel}) label\n\nComment tag: ${commitHash}`; + const message = `E2E test started on Bitrise...\n\nCommit hash: ${commitHash}\nBuild link: ${buildLink}\n\nYou can also kick off another Bitrise E2E smoke test by removing and re-applying the (${e2eLabel}) label\n\n`; if (bitriseBuildResponse.status === 201) { console.log(message); From bbd9e229db01a724ab2b7d218f187bd79c1c357d Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Wed, 21 Feb 2024 23:26:58 -0800 Subject: [PATCH 38/73] Fix comment tag --- bitrise.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitrise.yml b/bitrise.yml index 179b4d6ddb2..9d2bce63b60 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -280,7 +280,7 @@ workflows: - repository_url: '$GIT_REPOSITORY_URL' - issue_number: '$GITHUB_PR_NUMBER' - api_base_url: 'https://api.github.com' - - comment_tag: '$GITHUB_PR_HASH' + - update_comment_tag: '$GITHUB_PR_HASH' - slack@3: inputs: - text: '${BITRISE_APP_TITLE} ${BITRISEIO_PIPELINE_TITLE} workflow notification' From eed8755b37e92e946177ba61ef9a57c4fa16603c Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Thu, 22 Feb 2024 00:02:41 -0800 Subject: [PATCH 39/73] Format bitrise message --- .../scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts | 4 ++-- bitrise.yml | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts index 71c827056bc..e373f3c21c3 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts @@ -16,7 +16,7 @@ async function main(): Promise { const pullRequestNumber = context.issue.number; const repoOwner = context.repo.owner; const repo = context.repo.repo; - const commitHash = context.sha.slice(0, 6); + const commitHash = context.sha; const pullRequestLink = `https://github.com/MetaMask/metamask-mobile/pull/${pullRequestNumber}`; if (!githubToken) { @@ -77,7 +77,7 @@ async function main(): Promise { } const buildLink = `${bitriseProjectUrl}/pipelines/${bitriseBuildResponse.data.build_slug}`; - const message = `E2E test started on Bitrise...\n\nCommit hash: ${commitHash}\nBuild link: ${buildLink}\n\nYou can also kick off another Bitrise E2E smoke test by removing and re-applying the (${e2eLabel}) label\n\n`; + const message = `## [https://bitrise.io/](https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/8351b42f-c87f-496e-a4a4-387e248037ea) **Bitrise**\n\n🔄🔄🔄 \`${e2ePipeline}\` pipeline started on Bitrise...\n\nCommit hash: ${commitHash}\nBuild link: ${buildLink}\n\n>[!NOTE]\n>- This comment will auto-update when build succeeds\n>- You can also kick off another Bitrise E2E smoke test by removing and re-applying the \`Run Smoke E2E\` label\n\n`; if (bitriseBuildResponse.status === 201) { console.log(message); diff --git a/bitrise.yml b/bitrise.yml index 9d2bce63b60..795a3de4fd6 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -273,7 +273,9 @@ workflows: inputs: - personal_access_token: '$GITHUB_ACCESS_TOKEN' - body: |- - Bitrise E2E smoke tests passed ✅ + ## [https://bitrise.io/](https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/8351b42f-c87f-496e-a4a4-387e248037ea) **Bitrise** + + ✅✅✅ Bitrise E2E smoke tests passed! ✅✅✅ Commit hash: ${GITHUB_PR_HASH} Build link: ${BITRISEIO_PIPELINE_BUILD_URL} From 22ad086994aa5eb0156c5972b481d723218915d3 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Thu, 22 Feb 2024 00:21:08 -0800 Subject: [PATCH 40/73] Refine messages --- .../scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts | 2 +- bitrise.yml | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts index e373f3c21c3..7fa7da1e82a 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts @@ -77,7 +77,7 @@ async function main(): Promise { } const buildLink = `${bitriseProjectUrl}/pipelines/${bitriseBuildResponse.data.build_slug}`; - const message = `## [https://bitrise.io/](https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/8351b42f-c87f-496e-a4a4-387e248037ea) **Bitrise**\n\n🔄🔄🔄 \`${e2ePipeline}\` pipeline started on Bitrise...\n\nCommit hash: ${commitHash}\nBuild link: ${buildLink}\n\n>[!NOTE]\n>- This comment will auto-update when build succeeds\n>- You can also kick off another Bitrise E2E smoke test by removing and re-applying the \`Run Smoke E2E\` label\n\n`; + const message = `## [https://bitrise.io/](https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/8351b42f-c87f-496e-a4a4-387e248037ea) **Bitrise**\n\n🔄🔄🔄 \`${e2ePipeline}\` pipeline started on Bitrise...\n\nCommit hash: ${commitHash}\nBuild link: ${buildLink}\n\n>[!NOTE]\n>- This comment will auto-update when build succeeds\n>- You can kick off another \`${e2ePipeline}\` build on Bitrise by removing and re-applying the \`Run Smoke E2E\` label on the pull request\n\n`; if (bitriseBuildResponse.status === 201) { console.log(message); diff --git a/bitrise.yml b/bitrise.yml index 795a3de4fd6..4e1d5ea9307 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -275,10 +275,13 @@ workflows: - body: |- ## [https://bitrise.io/](https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/8351b42f-c87f-496e-a4a4-387e248037ea) **Bitrise** - ✅✅✅ Bitrise E2E smoke tests passed! ✅✅✅ + ✅✅✅ Pipeline `${BITRISEIO_PIPELINE_TITLE}` passed on Bitrise! ✅✅✅ Commit hash: ${GITHUB_PR_HASH} Build link: ${BITRISEIO_PIPELINE_BUILD_URL} + + >[!NOTE] + >- You can kick off another `${BITRISEIO_PIPELINE_TITLE}` build on Bitrise by removing and re-applying the `Run Smoke E2E` label on the pull request - repository_url: '$GIT_REPOSITORY_URL' - issue_number: '$GITHUB_PR_NUMBER' - api_base_url: 'https://api.github.com' From 7c72e6a3c8a9b027946fe0a7da9dabb943131fd4 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Thu, 22 Feb 2024 00:27:26 -0800 Subject: [PATCH 41/73] Refine bitrise message --- .../scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts | 2 +- bitrise.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts index 7fa7da1e82a..2732bf18fcc 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts @@ -77,7 +77,7 @@ async function main(): Promise { } const buildLink = `${bitriseProjectUrl}/pipelines/${bitriseBuildResponse.data.build_slug}`; - const message = `## [https://bitrise.io/](https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/8351b42f-c87f-496e-a4a4-387e248037ea) **Bitrise**\n\n🔄🔄🔄 \`${e2ePipeline}\` pipeline started on Bitrise...\n\nCommit hash: ${commitHash}\nBuild link: ${buildLink}\n\n>[!NOTE]\n>- This comment will auto-update when build succeeds\n>- You can kick off another \`${e2ePipeline}\` build on Bitrise by removing and re-applying the \`Run Smoke E2E\` label on the pull request\n\n`; + const message = `## [https://bitrise.io/](https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/8351b42f-c87f-496e-a4a4-387e248037ea) **Bitrise**\n\n🔄🔄🔄 \`${e2ePipeline}\` pipeline started on Bitrise...🔄🔄🔄\n\nCommit hash: ${commitHash}\nBuild link: ${buildLink}\n\n>[!NOTE]\n>- This comment will auto-update when build succeeds\n>- You can kick off another \`${e2ePipeline}\` build on Bitrise by removing and re-applying the \`Run Smoke E2E\` label on the pull request\n\n`; if (bitriseBuildResponse.status === 201) { console.log(message); diff --git a/bitrise.yml b/bitrise.yml index 4e1d5ea9307..26f90125b33 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -275,7 +275,7 @@ workflows: - body: |- ## [https://bitrise.io/](https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/8351b42f-c87f-496e-a4a4-387e248037ea) **Bitrise** - ✅✅✅ Pipeline `${BITRISEIO_PIPELINE_TITLE}` passed on Bitrise! ✅✅✅ + ✅✅✅ `${BITRISEIO_PIPELINE_TITLE}` pipeline passed on Bitrise! ✅✅✅ Commit hash: ${GITHUB_PR_HASH} Build link: ${BITRISEIO_PIPELINE_BUILD_URL} From 24e13b98b37eb682076efce9ea4aa43de6620424 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Thu, 22 Feb 2024 00:38:50 -0800 Subject: [PATCH 42/73] Change comment trigger to edit --- .../scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts | 4 +--- .github/workflows/check-bitrise-status.yml | 2 +- bitrise.yml | 1 + 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts b/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts index f15e34e7cef..6ed468961ff 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts +++ b/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts @@ -45,9 +45,7 @@ async function main(): Promise { issue_number, }); const isBitriseSuccessStatus = comments.some((comment) => { - const includesPass = comment.body?.includes( - 'Bitrise E2E smoke tests passed', - ); + const includesPass = comment.body?.includes('pipeline passed on Bitrise'); return includesPass; }); diff --git a/.github/workflows/check-bitrise-status.yml b/.github/workflows/check-bitrise-status.yml index 9a1b464654c..d96a1fdce8a 100644 --- a/.github/workflows/check-bitrise-status.yml +++ b/.github/workflows/check-bitrise-status.yml @@ -2,7 +2,7 @@ name: Check Bitrise Status on: issue_comment: - types: [created] + types: [edited] pull_request: types: [opened, reopened, labeled, unlabeled] diff --git a/bitrise.yml b/bitrise.yml index 26f90125b33..c7107b7e4f9 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -268,6 +268,7 @@ workflows: before_run: - _get_workflow_info steps: + # Update Bitrise comment in PR with success status - comment-on-github-pull-request@0: run_if: '{{getenv "TRIGGERED_BY_LABEL" | eq "true"}}' inputs: From 9d75bcfd2bb6463b6d794293a7d2667f6d1361d5 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Thu, 22 Feb 2024 00:42:11 -0800 Subject: [PATCH 43/73] Update trigger --- .github/workflows/check-bitrise-status.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-bitrise-status.yml b/.github/workflows/check-bitrise-status.yml index d96a1fdce8a..294413905b7 100644 --- a/.github/workflows/check-bitrise-status.yml +++ b/.github/workflows/check-bitrise-status.yml @@ -2,7 +2,7 @@ name: Check Bitrise Status on: issue_comment: - types: [edited] + types: [edited, deleted] pull_request: types: [opened, reopened, labeled, unlabeled] From 0c4f9311237b4524abe77bb7a6c1006940a42102 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Thu, 22 Feb 2024 14:38:29 -0800 Subject: [PATCH 44/73] Rename bitrise action files --- .../check-bitrise-e2e-status.ts} | 0 .../detect-e2e-label.ts} | 0 .../run-bitrise-e2e-tests.ts} | 2 +- ...status.yml => check-bitrise-e2e-status.yml} | 8 ++++---- ...e2e-smoke.yml => run-bitrise-e2e-tests.yml} | 18 +++++++++--------- package.json | 6 +++--- 6 files changed, 17 insertions(+), 17 deletions(-) rename .github/scripts/{check-bitrise-e2e-smoke/check-bitrise-status.ts => bitrise/check-bitrise-e2e-status.ts} (100%) rename .github/scripts/{check-bitrise-e2e-smoke/check-e2e-smoke-trigger.ts => bitrise/detect-e2e-label.ts} (100%) rename .github/scripts/{check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts => bitrise/run-bitrise-e2e-tests.ts} (97%) rename .github/workflows/{check-bitrise-status.yml => check-bitrise-e2e-status.yml} (82%) rename .github/workflows/{check-bitrise-e2e-smoke.yml => run-bitrise-e2e-tests.yml} (69%) diff --git a/.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts b/.github/scripts/bitrise/check-bitrise-e2e-status.ts similarity index 100% rename from .github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts rename to .github/scripts/bitrise/check-bitrise-e2e-status.ts diff --git a/.github/scripts/check-bitrise-e2e-smoke/check-e2e-smoke-trigger.ts b/.github/scripts/bitrise/detect-e2e-label.ts similarity index 100% rename from .github/scripts/check-bitrise-e2e-smoke/check-e2e-smoke-trigger.ts rename to .github/scripts/bitrise/detect-e2e-label.ts diff --git a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts b/.github/scripts/bitrise/run-bitrise-e2e-tests.ts similarity index 97% rename from .github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts rename to .github/scripts/bitrise/run-bitrise-e2e-tests.ts index 2732bf18fcc..69b8032e279 100644 --- a/.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts +++ b/.github/scripts/bitrise/run-bitrise-e2e-tests.ts @@ -77,7 +77,7 @@ async function main(): Promise { } const buildLink = `${bitriseProjectUrl}/pipelines/${bitriseBuildResponse.data.build_slug}`; - const message = `## [https://bitrise.io/](https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/8351b42f-c87f-496e-a4a4-387e248037ea) **Bitrise**\n\n🔄🔄🔄 \`${e2ePipeline}\` pipeline started on Bitrise...🔄🔄🔄\n\nCommit hash: ${commitHash}\nBuild link: ${buildLink}\n\n>[!NOTE]\n>- This comment will auto-update when build succeeds\n>- You can kick off another \`${e2ePipeline}\` build on Bitrise by removing and re-applying the \`Run Smoke E2E\` label on the pull request\n\n`; + const message = `## [https://bitrise.io/](https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/8351b42f-c87f-496e-a4a4-387e248037ea) **Bitrise**\n\n🔄🔄🔄 \`${e2ePipeline}\` pipeline started on Bitrise...🔄🔄🔄\n\nCommit hash: ${commitHash}\nBuild link: ${buildLink}\n\n>[!NOTE]\n>- This comment will auto-update when build succeeds\n>- You can kick off another \`${e2ePipeline}\` build on Bitrise by removing and re-applying the \`${e2eLabel}\` label on the pull request\n\n`; if (bitriseBuildResponse.status === 201) { console.log(message); diff --git a/.github/workflows/check-bitrise-status.yml b/.github/workflows/check-bitrise-e2e-status.yml similarity index 82% rename from .github/workflows/check-bitrise-status.yml rename to .github/workflows/check-bitrise-e2e-status.yml index 294413905b7..b0138734f33 100644 --- a/.github/workflows/check-bitrise-status.yml +++ b/.github/workflows/check-bitrise-e2e-status.yml @@ -1,4 +1,4 @@ -name: Check Bitrise Status +name: Check Bitrise E2E Status on: issue_comment: @@ -10,7 +10,7 @@ env: E2E_LABEL: 'Run Smoke E2E' jobs: - check-bitrise-e2e-smoke: + check-bitrise-e2e-status: runs-on: ubuntu-latest if: ${{ github.event.issue.pull_request || github.event_name == 'pull_request' }} permissions: @@ -29,7 +29,7 @@ jobs: - name: Install dependencies run: yarn --immutable - - name: Check Bitrise Status + - name: Check Bitrise E2E Status env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: yarn run check-bitrise-status + run: yarn run check-bitrise-e2e-status diff --git a/.github/workflows/check-bitrise-e2e-smoke.yml b/.github/workflows/run-bitrise-e2e-tests.yml similarity index 69% rename from .github/workflows/check-bitrise-e2e-smoke.yml rename to .github/workflows/run-bitrise-e2e-tests.yml index afe8a7a1eb0..3f2cae0c923 100644 --- a/.github/workflows/check-bitrise-e2e-smoke.yml +++ b/.github/workflows/run-bitrise-e2e-tests.yml @@ -1,4 +1,4 @@ -name: Check Bitrise E2E Smoke Tests +name: Run Bitrise E2E Tests on: pull_request: @@ -7,10 +7,10 @@ on: env: E2E_LABEL: 'Run Smoke E2E' E2E_PIPELINE: 'pr_smoke_e2e_pipeline' - WORKFLOW_NAME: 'check-bitrise-e2e-smoke' + WORKFLOW_NAME: 'run-bitrise-e2e-tests' jobs: - check-bitrise-e2e-smoke: + run-bitrise-e2e-tests: runs-on: ubuntu-latest permissions: pull-requests: write @@ -31,16 +31,16 @@ jobs: - name: Install dependencies run: yarn --immutable - - name: Check E2E trigger - id: check-trigger + - name: Detect if E2E label exists + id: detect-e2e-label-id env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: yarn run check-e2e-smoke-trigger + run: yarn run detect-e2e-label - - name: Run Bitrise E2E - if: steps.check-trigger.outputs.shouldTriggerE2E == 'true' + - name: Run Bitrise E2E tests + if: steps.detect-e2e-label-id.outputs.shouldTriggerE2E == 'true' env: BITRISE_BUILD_TRIGGER_TOKEN: ${{ secrets.BITRISE_BUILD_TRIGGER_TOKEN }} BITRISE_APP_ID: 'be69d4368ee7e86d' GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: yarn run run-bitrise-e2e-smoke + run: yarn run run-bitrise-e2e-tests diff --git a/package.json b/package.json index 46351268ee5..28b28b5daec 100644 --- a/package.json +++ b/package.json @@ -86,9 +86,9 @@ "deduplicate": "yarn yarn-deduplicate && yarn install", "create-release": "./scripts/set-versions.sh && yarn update-changelog", "add-release-label-to-pr-and-linked-issues": "ts-node ./.github/scripts/add-release-label-to-pr-and-linked-issues.ts", - "check-e2e-smoke-trigger": "ts-node ./.github/scripts/check-bitrise-e2e-smoke/check-e2e-smoke-trigger.ts", - "check-bitrise-status": "ts-node ./.github/scripts/check-bitrise-e2e-smoke/check-bitrise-status.ts", - "run-bitrise-e2e-smoke": "ts-node ./.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts", + "run-bitrise-e2e-tests": "ts-node ./.github/scripts/bitrise/run-bitrise-e2e-tests.ts", + "detect-e2e-label": "ts-node ./.github/scripts/bitrise/detect-e2e-label.ts", + "check-bitrise-e2e-status": "ts-node ./.github/scripts/bitrise/check-bitrise-e2e-status.ts", "check-pr-has-required-labels": "ts-node ./.github/scripts/check-pr-has-required-labels.ts", "close-release-bug-report-issue": "ts-node ./.github/scripts/close-release-bug-report-issue.ts", "check-template-and-add-labels": "ts-node ./.github/scripts/check-template-and-add-labels.ts", From 65c12c55c3780f653143d65dec9ff731fb8e1e10 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Thu, 22 Feb 2024 18:10:44 -0800 Subject: [PATCH 45/73] Fix hardcoded build link --- .github/scripts/bitrise/run-bitrise-e2e-tests.ts | 2 +- bitrise.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/bitrise/run-bitrise-e2e-tests.ts b/.github/scripts/bitrise/run-bitrise-e2e-tests.ts index 69b8032e279..2a881287bdb 100644 --- a/.github/scripts/bitrise/run-bitrise-e2e-tests.ts +++ b/.github/scripts/bitrise/run-bitrise-e2e-tests.ts @@ -77,7 +77,7 @@ async function main(): Promise { } const buildLink = `${bitriseProjectUrl}/pipelines/${bitriseBuildResponse.data.build_slug}`; - const message = `## [https://bitrise.io/](https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/8351b42f-c87f-496e-a4a4-387e248037ea) **Bitrise**\n\n🔄🔄🔄 \`${e2ePipeline}\` pipeline started on Bitrise...🔄🔄🔄\n\nCommit hash: ${commitHash}\nBuild link: ${buildLink}\n\n>[!NOTE]\n>- This comment will auto-update when build succeeds\n>- You can kick off another \`${e2ePipeline}\` build on Bitrise by removing and re-applying the \`${e2eLabel}\` label on the pull request\n\n`; + const message = `## [https://bitrise.io/](${buildLink}) **Bitrise**\n\n🔄🔄🔄 \`${e2ePipeline}\` pipeline started on Bitrise...🔄🔄🔄\n\nCommit hash: ${commitHash}\nBuild link: ${buildLink}\n\n>[!NOTE]\n>- This comment will auto-update when build succeeds\n>- You can kick off another \`${e2ePipeline}\` build on Bitrise by removing and re-applying the \`${e2eLabel}\` label on the pull request\n\n`; if (bitriseBuildResponse.status === 201) { console.log(message); diff --git a/bitrise.yml b/bitrise.yml index c7107b7e4f9..c5550a2f548 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -274,7 +274,7 @@ workflows: inputs: - personal_access_token: '$GITHUB_ACCESS_TOKEN' - body: |- - ## [https://bitrise.io/](https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/8351b42f-c87f-496e-a4a4-387e248037ea) **Bitrise** + ## [https://bitrise.io/](${BITRISEIO_PIPELINE_BUILD_URL}) **Bitrise** ✅✅✅ `${BITRISEIO_PIPELINE_TITLE}` pipeline passed on Bitrise! ✅✅✅ From a57dc62d20cec65f44743082d211f0f72e820306 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Thu, 22 Feb 2024 18:24:16 -0800 Subject: [PATCH 46/73] Post fail comment to PR if step failure --- bitrise.yml | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/bitrise.yml b/bitrise.yml index c5550a2f548..eba7c2a1ce6 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -51,8 +51,8 @@ pipelines: #PR_e2e_verfication (build ios & android), run iOS (smoke), emulator Android pr_smoke_e2e_pipeline: stages: - # - build_smoke_e2e_ios_android_stage: {} - # - run_smoke_e2e_ios_android_stage: {} + - build_smoke_e2e_ios_android_stage: {} + - run_smoke_e2e_ios_android_stage: {} - notify: {} # Pipeline for Flask create_flask_release_builds_pipeline: @@ -307,10 +307,29 @@ workflows: - webhook_url: https://hooks.slack.com/services/${MM_SLACK_TOKEN}/${MM_SLACK_SECRET}/${MM_SLACK_ROOM} # Send a Slack message when workflow fails - _notify_failure_on_slack: + notify_failure: before_run: - _get_workflow_info steps: + # Update Bitrise comment in PR with success status + - comment-on-github-pull-request@0: + run_if: '{{getenv "TRIGGERED_BY_LABEL" | eq "true"}}' + inputs: + - personal_access_token: '$GITHUB_ACCESS_TOKEN' + - body: |- + ## [https://bitrise.io/](${BITRISEIO_PIPELINE_BUILD_URL}) **Bitrise** + + ❌❌❌ `${BITRISEIO_PIPELINE_TITLE}` pipeline failed on Bitrise! ❌❌❌ + + Commit hash: ${GITHUB_PR_HASH} + Build link: ${BITRISEIO_PIPELINE_BUILD_URL} + + >[!NOTE] + >- You can kick off another `${BITRISEIO_PIPELINE_TITLE}` build on Bitrise by removing and re-applying the `Run Smoke E2E` label on the pull request + - repository_url: '$GIT_REPOSITORY_URL' + - issue_number: '$GITHUB_PR_NUMBER' + - api_base_url: 'https://api.github.com' + - update_comment_tag: '$GITHUB_PR_HASH' - slack@3: is_always_run: true run_if: .IsBuildFailed @@ -443,7 +462,7 @@ workflows: - code_setup - e2e_setup after_run: - - _notify_failure_on_slack + - notify_failure steps: - restore-gradle-cache@2: {} - install-missing-android-tools@3: @@ -519,7 +538,7 @@ workflows: - prep_environment - e2e_setup after_run: - - _notify_failure_on_slack + - notify_failure steps: - restore-gradle-cache@2: {} - restore-cache@2: @@ -599,7 +618,7 @@ workflows: - code_setup - e2e_setup after_run: - - _notify_failure_on_slack + - notify_failure steps: - certificate-and-profile-installer@1: {} - set-xcode-build-number@1: @@ -679,7 +698,7 @@ workflows: - prep_environment - e2e_setup after_run: - - _notify_failure_on_slack + - notify_failure steps: - restore-cache@2: title: Restore cache build @@ -767,7 +786,7 @@ workflows: before_run: - code_setup after_run: - - _notify_failure_on_slack + - notify_failure steps: - change-android-versioncode-and-versionname@1: inputs: @@ -843,7 +862,7 @@ workflows: - code_setup after_run: - _upload_apk_to_browserstack - - _notify_failure_on_slack + - notify_failure steps: - change-android-versioncode-and-versionname@1: inputs: @@ -951,7 +970,7 @@ workflows: before_run: - code_setup after_run: - - _notify_failure_on_slack + - notify_failure steps: - script@1: title: Run Android E2E tests on Browserstack @@ -1004,7 +1023,7 @@ workflows: before_run: - code_setup after_run: - - _notify_failure_on_slack + - notify_failure steps: - certificate-and-profile-installer@1: {} - set-xcode-build-number@1: @@ -1044,7 +1063,7 @@ workflows: - code_setup after_run: - _upload_ipa_to_browserstack - - _notify_failure_on_slack + - notify_failure steps: - certificate-and-profile-installer@1: {} - set-xcode-build-number@1: @@ -1108,7 +1127,7 @@ workflows: before_run: - code_setup after_run: - - _notify_failure_on_slack + - notify_failure steps: - certificate-and-profile-installer@1: {} - set-xcode-build-number@1: @@ -1148,7 +1167,7 @@ workflows: before_run: - code_setup after_run: - - _notify_failure_on_slack + - notify_failure steps: - change-android-versioncode-and-versionname@1: inputs: From cca817c14e2e33265e6803964eb1b7c5a9e646eb Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Thu, 22 Feb 2024 20:07:38 -0800 Subject: [PATCH 47/73] Fix build failure condition --- bitrise.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bitrise.yml b/bitrise.yml index eba7c2a1ce6..9305ccda490 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -313,7 +313,8 @@ workflows: steps: # Update Bitrise comment in PR with success status - comment-on-github-pull-request@0: - run_if: '{{getenv "TRIGGERED_BY_LABEL" | eq "true"}}' + run_if: |- + bash -c '[[ "$(getenv "TRIGGERED_BY_LABEL")" == "true" && $BITRISE_BUILD_STATUS == 1 ]]' inputs: - personal_access_token: '$GITHUB_ACCESS_TOKEN' - body: |- From 29c0a151b080d7f4e41ea23c6518a2b5a555092f Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Thu, 22 Feb 2024 21:22:02 -0800 Subject: [PATCH 48/73] Add failure condition step --- .github/scripts/bitrise/run-bitrise-e2e-tests.ts | 2 +- bitrise.yml | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/scripts/bitrise/run-bitrise-e2e-tests.ts b/.github/scripts/bitrise/run-bitrise-e2e-tests.ts index 2a881287bdb..3211b3a09cd 100644 --- a/.github/scripts/bitrise/run-bitrise-e2e-tests.ts +++ b/.github/scripts/bitrise/run-bitrise-e2e-tests.ts @@ -42,7 +42,7 @@ async function main(): Promise { is_expand: true, }, { - mapped_to: 'TRIGGERED_BY_LABEL', + mapped_to: 'TRIGGERED_BY_PR_LABEL', value: `true`, is_expand: true, }, diff --git a/bitrise.yml b/bitrise.yml index 9305ccda490..41764fa0942 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -311,10 +311,19 @@ workflows: before_run: - _get_workflow_info steps: - # Update Bitrise comment in PR with success status + - script@1: + title: Check if PR comment should be updated + inputs: + - content: |- + #!/usr/bin/env bash + if [[ "$(getenv "TRIGGERED_BY_PR_LABEL")" == "true" && $BITRISE_BUILD_STATUS == 1 ]]; then + envman add --key SHOULD_UPDATE_PR_COMMENT --value "true" + else + envman add --key SHOULD_UPDATE_PR_COMMENT --value "false" + fi + # Update Bitrise comment in PR with failure status - comment-on-github-pull-request@0: - run_if: |- - bash -c '[[ "$(getenv "TRIGGERED_BY_LABEL")" == "true" && $BITRISE_BUILD_STATUS == 1 ]]' + run_if: '{{getenv "SHOULD_UPDATE_PR_COMMENT" | eq "true"}}' inputs: - personal_access_token: '$GITHUB_ACCESS_TOKEN' - body: |- From a147f8dc3afd6f565a8c4ae59d584a48095a709b Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Thu, 22 Feb 2024 22:00:46 -0800 Subject: [PATCH 49/73] Get latest PR commit hash --- .github/scripts/bitrise/run-bitrise-e2e-tests.ts | 13 ++++++++++--- bitrise.yml | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/scripts/bitrise/run-bitrise-e2e-tests.ts b/.github/scripts/bitrise/run-bitrise-e2e-tests.ts index 3211b3a09cd..fbd66e91c16 100644 --- a/.github/scripts/bitrise/run-bitrise-e2e-tests.ts +++ b/.github/scripts/bitrise/run-bitrise-e2e-tests.ts @@ -16,7 +16,6 @@ async function main(): Promise { const pullRequestNumber = context.issue.number; const repoOwner = context.repo.owner; const repo = context.repo.repo; - const commitHash = context.sha; const pullRequestLink = `https://github.com/MetaMask/metamask-mobile/pull/${pullRequestNumber}`; if (!githubToken) { @@ -31,6 +30,14 @@ async function main(): Promise { const octokit: InstanceType = getOctokit(githubToken); + const pullRequestResponse = await octokit.rest.pulls.get({ + owner: repoOwner, + repo, + pull_number: pullRequestNumber, + }); + + const latestCommitHash = pullRequestResponse.data.head.sha; + const data = { build_params: { branch: process.env.GITHUB_HEAD_REF, @@ -48,7 +55,7 @@ async function main(): Promise { }, { mapped_to: 'GITHUB_PR_HASH', - value: `${commitHash}`, + value: `${latestCommitHash}`, is_expand: true, }, ], @@ -77,7 +84,7 @@ async function main(): Promise { } const buildLink = `${bitriseProjectUrl}/pipelines/${bitriseBuildResponse.data.build_slug}`; - const message = `## [https://bitrise.io/](${buildLink}) **Bitrise**\n\n🔄🔄🔄 \`${e2ePipeline}\` pipeline started on Bitrise...🔄🔄🔄\n\nCommit hash: ${commitHash}\nBuild link: ${buildLink}\n\n>[!NOTE]\n>- This comment will auto-update when build succeeds\n>- You can kick off another \`${e2ePipeline}\` build on Bitrise by removing and re-applying the \`${e2eLabel}\` label on the pull request\n\n`; + const message = `## [https://bitrise.io/](${buildLink}) **Bitrise**\n\n🔄🔄🔄 \`${e2ePipeline}\` pipeline started on Bitrise...🔄🔄🔄\n\nCommit hash: ${latestCommitHash}\nBuild link: ${buildLink}\n\n>[!NOTE]\n>- This comment will auto-update when build succeeds\n>- You can kick off another \`${e2ePipeline}\` build on Bitrise by removing and re-applying the \`${e2eLabel}\` label on the pull request\n\n`; if (bitriseBuildResponse.status === 201) { console.log(message); diff --git a/bitrise.yml b/bitrise.yml index 41764fa0942..d5e4bddaf81 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -270,7 +270,7 @@ workflows: steps: # Update Bitrise comment in PR with success status - comment-on-github-pull-request@0: - run_if: '{{getenv "TRIGGERED_BY_LABEL" | eq "true"}}' + run_if: '{{getenv "TRIGGERED_BY_PR_LABEL" | eq "true"}}' inputs: - personal_access_token: '$GITHUB_ACCESS_TOKEN' - body: |- From 1e22620ba51f611ff3391fb74a43a06a01716384 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Thu, 22 Feb 2024 22:44:44 -0800 Subject: [PATCH 50/73] Force fail --- bitrise.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bitrise.yml b/bitrise.yml index d5e4bddaf81..d26ac26fbad 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -732,7 +732,8 @@ workflows: inputs: - content: |- #!/usr/bin/env bash - if [ -n "$TEST_SUITE_FOLDER" ]; then + break here + if _SUITE_FOLDER" ]; then echo "TEST_SUITE_FOLDER value is: $TEST_SUITE_FOLDER" fi if [ "$TEST_SUITE" = "Regression" ]; then From 955a913b0f0d614a45b6bc02776dedf0f665f3a5 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Fri, 23 Feb 2024 00:11:37 -0800 Subject: [PATCH 51/73] Always run notify --- bitrise.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bitrise.yml b/bitrise.yml index d26ac26fbad..8cf3a1eed0e 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -270,6 +270,7 @@ workflows: steps: # Update Bitrise comment in PR with success status - comment-on-github-pull-request@0: + is_always_run: true run_if: '{{getenv "TRIGGERED_BY_PR_LABEL" | eq "true"}}' inputs: - personal_access_token: '$GITHUB_ACCESS_TOKEN' @@ -312,6 +313,7 @@ workflows: - _get_workflow_info steps: - script@1: + is_always_run: true title: Check if PR comment should be updated inputs: - content: |- @@ -323,6 +325,7 @@ workflows: fi # Update Bitrise comment in PR with failure status - comment-on-github-pull-request@0: + is_always_run: true run_if: '{{getenv "SHOULD_UPDATE_PR_COMMENT" | eq "true"}}' inputs: - personal_access_token: '$GITHUB_ACCESS_TOKEN' From 5d3d7f9f64e59c5ef6923d2cc5f126d68c909f68 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Fri, 23 Feb 2024 10:10:32 -0800 Subject: [PATCH 52/73] Fix comment step logic --- bitrise.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitrise.yml b/bitrise.yml index 8cf3a1eed0e..808225703d1 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -318,7 +318,7 @@ workflows: inputs: - content: |- #!/usr/bin/env bash - if [[ "$(getenv "TRIGGERED_BY_PR_LABEL")" == "true" && $BITRISE_BUILD_STATUS == 1 ]]; then + if [[ "$TRIGGERED_BY_PR_LABEL" == "true" && $BITRISE_BUILD_STATUS == 1 ]]; then envman add --key SHOULD_UPDATE_PR_COMMENT --value "true" else envman add --key SHOULD_UPDATE_PR_COMMENT --value "false" From 035bc60b5f9b31bc6e46085f646c693208ef9619 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Fri, 23 Feb 2024 12:42:53 -0800 Subject: [PATCH 53/73] Revert "Force fail" This reverts commit 1e22620ba51f611ff3391fb74a43a06a01716384. --- bitrise.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bitrise.yml b/bitrise.yml index 808225703d1..ede3d546b79 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -735,8 +735,7 @@ workflows: inputs: - content: |- #!/usr/bin/env bash - break here - if _SUITE_FOLDER" ]; then + if [ -n "$TEST_SUITE_FOLDER" ]; then echo "TEST_SUITE_FOLDER value is: $TEST_SUITE_FOLDER" fi if [ "$TEST_SUITE" = "Regression" ]; then From 9bc30e3bb6f0ced1c879416db6b8a560048f8e86 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Fri, 23 Feb 2024 16:10:03 -0800 Subject: [PATCH 54/73] Add bitrise tags to comments --- .../bitrise/check-bitrise-e2e-status.ts | 33 +++++++++++++++---- .../scripts/bitrise/run-bitrise-e2e-tests.ts | 6 ++-- bitrise.yml | 14 +++++--- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/.github/scripts/bitrise/check-bitrise-e2e-status.ts b/.github/scripts/bitrise/check-bitrise-e2e-status.ts index 6ed468961ff..941132da490 100644 --- a/.github/scripts/bitrise/check-bitrise-e2e-status.ts +++ b/.github/scripts/bitrise/check-bitrise-e2e-status.ts @@ -44,14 +44,33 @@ async function main(): Promise { repo, issue_number, }); - const isBitriseSuccessStatus = comments.some((comment) => { - const includesPass = comment.body?.includes('pipeline passed on Bitrise'); - return includesPass; - }); - if (!isBitriseSuccessStatus) { - core.setFailed('Bitrise has not passed yet.'); + const bitriseTag = ''; + const bitrisePendingTag = ''; + const bitriseSuccessTag = ''; + const bitriseFailTag = ''; + + const bitriseComments = comments.filter((comment) => + comment.body?.includes(bitriseTag), + ); + + if (bitriseComments.length === 0) { + core.setFailed('Bitrise build comment does not exist.'); } - console.log('Bitrise build has passed!'); + const bitriseComment = + bitriseComments[bitriseComments.length - 1]?.body || ''; + + if (bitriseComment.includes(bitrisePendingTag)) { + core.setFailed('Bitrise build is pending.'); + return; + } else if (bitriseComment.includes(bitriseFailTag)) { + core.setFailed('Bitrise build has failed.'); + return; + } else if (bitriseComment.includes(bitriseSuccessTag)) { + console.log('Bitrise build has passed.'); + } else { + core.setFailed('Could not detect Bitrise build status.'); + return; + } } diff --git a/.github/scripts/bitrise/run-bitrise-e2e-tests.ts b/.github/scripts/bitrise/run-bitrise-e2e-tests.ts index fbd66e91c16..b6851d78f7e 100644 --- a/.github/scripts/bitrise/run-bitrise-e2e-tests.ts +++ b/.github/scripts/bitrise/run-bitrise-e2e-tests.ts @@ -35,7 +35,7 @@ async function main(): Promise { repo, pull_number: pullRequestNumber, }); - + const latestCommitHash = pullRequestResponse.data.head.sha; const data = { @@ -83,8 +83,10 @@ async function main(): Promise { process.exit(1); } + const bitriseTag = ''; + const bitrisePendingTag = ''; const buildLink = `${bitriseProjectUrl}/pipelines/${bitriseBuildResponse.data.build_slug}`; - const message = `## [https://bitrise.io/](${buildLink}) **Bitrise**\n\n🔄🔄🔄 \`${e2ePipeline}\` pipeline started on Bitrise...🔄🔄🔄\n\nCommit hash: ${latestCommitHash}\nBuild link: ${buildLink}\n\n>[!NOTE]\n>- This comment will auto-update when build succeeds\n>- You can kick off another \`${e2ePipeline}\` build on Bitrise by removing and re-applying the \`${e2eLabel}\` label on the pull request\n\n`; + const message = `## [https://bitrise.io/](${buildLink}) **Bitrise**\n\n🔄🔄🔄 \`${e2ePipeline}\` started on Bitrise...🔄🔄🔄\n\nCommit hash: ${latestCommitHash}\nBuild link: ${buildLink}\n\n>[!NOTE]\n>- This comment will auto-update when build completes\n>- You can kick off another \`${e2ePipeline}\` on Bitrise by removing and re-applying the \`${e2eLabel}\` label on the pull request\n${bitriseTag}\n${bitrisePendingTag}\n\n`; if (bitriseBuildResponse.status === 201) { console.log(message); diff --git a/bitrise.yml b/bitrise.yml index ede3d546b79..6f9aea5affc 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -277,13 +277,16 @@ workflows: - body: |- ## [https://bitrise.io/](${BITRISEIO_PIPELINE_BUILD_URL}) **Bitrise** - ✅✅✅ `${BITRISEIO_PIPELINE_TITLE}` pipeline passed on Bitrise! ✅✅✅ + ✅✅✅ `${BITRISEIO_PIPELINE_TITLE}` passed on Bitrise! ✅✅✅ Commit hash: ${GITHUB_PR_HASH} Build link: ${BITRISEIO_PIPELINE_BUILD_URL} >[!NOTE] - >- You can kick off another `${BITRISEIO_PIPELINE_TITLE}` build on Bitrise by removing and re-applying the `Run Smoke E2E` label on the pull request + >- You can kick off another `${BITRISEIO_PIPELINE_TITLE}` on Bitrise by removing and re-applying the `Run Smoke E2E` label on the pull request + + + - repository_url: '$GIT_REPOSITORY_URL' - issue_number: '$GITHUB_PR_NUMBER' - api_base_url: 'https://api.github.com' @@ -332,13 +335,16 @@ workflows: - body: |- ## [https://bitrise.io/](${BITRISEIO_PIPELINE_BUILD_URL}) **Bitrise** - ❌❌❌ `${BITRISEIO_PIPELINE_TITLE}` pipeline failed on Bitrise! ❌❌❌ + ❌❌❌ `${BITRISEIO_PIPELINE_TITLE}` failed on Bitrise! ❌❌❌ Commit hash: ${GITHUB_PR_HASH} Build link: ${BITRISEIO_PIPELINE_BUILD_URL} >[!NOTE] - >- You can kick off another `${BITRISEIO_PIPELINE_TITLE}` build on Bitrise by removing and re-applying the `Run Smoke E2E` label on the pull request + >- You can kick off another `${BITRISEIO_PIPELINE_TITLE}` on Bitrise by removing and re-applying the `Run Smoke E2E` label on the pull request + + + - repository_url: '$GIT_REPOSITORY_URL' - issue_number: '$GITHUB_PR_NUMBER' - api_base_url: 'https://api.github.com' From 159874e81f5334bbe62eadcfdf1e2085cd6e050c Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Fri, 23 Feb 2024 16:11:13 -0800 Subject: [PATCH 55/73] Force fail --- bitrise.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bitrise.yml b/bitrise.yml index 6f9aea5affc..436136a7ac6 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -741,9 +741,7 @@ workflows: inputs: - content: |- #!/usr/bin/env bash - if [ -n "$TEST_SUITE_FOLDER" ]; then - echo "TEST_SUITE_FOLDER value is: $TEST_SUITE_FOLDER" - fi + if [ -n "$TESfi if [ "$TEST_SUITE" = "Regression" ]; then TEST_SUITE="Regression" else From cc1f64fe07a6794f4124ebe8a45cac2516a3ac2b Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Fri, 23 Feb 2024 17:25:54 -0800 Subject: [PATCH 56/73] Revert "Force fail" This reverts commit 159874e81f5334bbe62eadcfdf1e2085cd6e050c. --- bitrise.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bitrise.yml b/bitrise.yml index 436136a7ac6..6f9aea5affc 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -741,7 +741,9 @@ workflows: inputs: - content: |- #!/usr/bin/env bash - if [ -n "$TESfi + if [ -n "$TEST_SUITE_FOLDER" ]; then + echo "TEST_SUITE_FOLDER value is: $TEST_SUITE_FOLDER" + fi if [ "$TEST_SUITE" = "Regression" ]; then TEST_SUITE="Regression" else From 8b19e9e1f91bff02841fae831c32e823033de82a Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Sat, 24 Feb 2024 17:35:46 -0800 Subject: [PATCH 57/73] Edit existing Bitrise comment --- .../bitrise/check-bitrise-e2e-status.ts | 10 ++-- .../scripts/bitrise/run-bitrise-e2e-tests.ts | 52 +++++++++++++++---- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/.github/scripts/bitrise/check-bitrise-e2e-status.ts b/.github/scripts/bitrise/check-bitrise-e2e-status.ts index 941132da490..d68d7776038 100644 --- a/.github/scripts/bitrise/check-bitrise-e2e-status.ts +++ b/.github/scripts/bitrise/check-bitrise-e2e-status.ts @@ -38,7 +38,6 @@ async function main(): Promise { return; } - // Check if the "Bitrise build passed!" comment is posted const { data: comments } = await octokit.rest.issues.listComments({ owner, repo, @@ -58,16 +57,17 @@ async function main(): Promise { core.setFailed('Bitrise build comment does not exist.'); } - const bitriseComment = + const lastBitriseComment = bitriseComments[bitriseComments.length - 1]?.body || ''; - if (bitriseComment.includes(bitrisePendingTag)) { + // Check Bitrise comment status + if (lastBitriseComment.includes(bitrisePendingTag)) { core.setFailed('Bitrise build is pending.'); return; - } else if (bitriseComment.includes(bitriseFailTag)) { + } else if (lastBitriseComment.includes(bitriseFailTag)) { core.setFailed('Bitrise build has failed.'); return; - } else if (bitriseComment.includes(bitriseSuccessTag)) { + } else if (lastBitriseComment.includes(bitriseSuccessTag)) { console.log('Bitrise build has passed.'); } else { core.setFailed('Could not detect Bitrise build status.'); diff --git a/.github/scripts/bitrise/run-bitrise-e2e-tests.ts b/.github/scripts/bitrise/run-bitrise-e2e-tests.ts index b6851d78f7e..84a4d7f76c7 100644 --- a/.github/scripts/bitrise/run-bitrise-e2e-tests.ts +++ b/.github/scripts/bitrise/run-bitrise-e2e-tests.ts @@ -85,8 +85,9 @@ async function main(): Promise { const bitriseTag = ''; const bitrisePendingTag = ''; + const latestCommitTag = ``; const buildLink = `${bitriseProjectUrl}/pipelines/${bitriseBuildResponse.data.build_slug}`; - const message = `## [https://bitrise.io/](${buildLink}) **Bitrise**\n\n🔄🔄🔄 \`${e2ePipeline}\` started on Bitrise...🔄🔄🔄\n\nCommit hash: ${latestCommitHash}\nBuild link: ${buildLink}\n\n>[!NOTE]\n>- This comment will auto-update when build completes\n>- You can kick off another \`${e2ePipeline}\` on Bitrise by removing and re-applying the \`${e2eLabel}\` label on the pull request\n${bitriseTag}\n${bitrisePendingTag}\n\n`; + const message = `## [https://bitrise.io/](${buildLink}) **Bitrise**\n\n🔄🔄🔄 \`${e2ePipeline}\` started on Bitrise...🔄🔄🔄\n\nCommit hash: ${latestCommitHash}\nBuild link: ${buildLink}\n\n>[!NOTE]\n>- This comment will auto-update when build completes\n>- You can kick off another \`${e2ePipeline}\` on Bitrise by removing and re-applying the \`${e2eLabel}\` label on the pull request\n${bitriseTag}\n${bitrisePendingTag}\n\n${latestCommitTag}`; if (bitriseBuildResponse.status === 201) { console.log(message); @@ -113,20 +114,51 @@ async function main(): Promise { process.exit(1); } - // Post build link in PR comments. - const postCommentResponse = await octokit.rest.issues.createComment({ + // Look for existing Bitrise comment. + const { data: comments } = await octokit.rest.issues.listComments({ owner: repoOwner, repo, issue_number: pullRequestNumber, - body: message, }); - if (postCommentResponse.status === 201) { - console.log(`Posting comment in pull request ${pullRequestLink}`); + const bitriseComment = comments.find(({ body }) => + body?.includes(latestCommitTag), + ); + + // Existing comment exists for commit hash. Update comment with pending status. + if (bitriseComment) { + const updateCommentResponse = await octokit.rest.issues.updateComment({ + owner: repoOwner, + repo, + issue_number: pullRequestNumber, + body: message, + comment_id: bitriseComment.id, + }); + + if (updateCommentResponse.status === 200) { + console.log(`Updating comment in pull request ${pullRequestLink}`); + } else { + core.setFailed( + `Update comment request returned with status code ${updateCommentResponse.status}`, + ); + process.exit(1); + } } else { - core.setFailed( - `Post comment request returned with status code ${postCommentResponse.status}`, - ); - process.exit(1); + // Post new Bitrise comment in PR. + const postCommentResponse = await octokit.rest.issues.createComment({ + owner: repoOwner, + repo, + issue_number: pullRequestNumber, + body: message, + }); + + if (postCommentResponse.status === 201) { + console.log(`Posting comment in pull request ${pullRequestLink}`); + } else { + core.setFailed( + `Post comment request returned with status code ${postCommentResponse.status}`, + ); + process.exit(1); + } } } From a4cab3000b0b69a84a1925fbadcfaf647a4bac7b Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Sat, 24 Feb 2024 17:45:04 -0800 Subject: [PATCH 58/73] Add synchronize condition to check bitrise status --- .github/workflows/check-bitrise-e2e-status.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-bitrise-e2e-status.yml b/.github/workflows/check-bitrise-e2e-status.yml index b0138734f33..43ecf651a7e 100644 --- a/.github/workflows/check-bitrise-e2e-status.yml +++ b/.github/workflows/check-bitrise-e2e-status.yml @@ -4,7 +4,7 @@ on: issue_comment: types: [edited, deleted] pull_request: - types: [opened, reopened, labeled, unlabeled] + types: [opened, reopened, labeled, unlabeled, synchronized] env: E2E_LABEL: 'Run Smoke E2E' From f77947deaee405e59e94c87fac173eca231c19e5 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Sat, 24 Feb 2024 17:46:34 -0800 Subject: [PATCH 59/73] Add synchronize condition to check bitrise status --- .github/workflows/check-bitrise-e2e-status.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-bitrise-e2e-status.yml b/.github/workflows/check-bitrise-e2e-status.yml index 43ecf651a7e..6e6f401cd60 100644 --- a/.github/workflows/check-bitrise-e2e-status.yml +++ b/.github/workflows/check-bitrise-e2e-status.yml @@ -4,7 +4,7 @@ on: issue_comment: types: [edited, deleted] pull_request: - types: [opened, reopened, labeled, unlabeled, synchronized] + types: [opened, reopened, labeled, unlabeled, synchronize] env: E2E_LABEL: 'Run Smoke E2E' From a96e9289bed728e5667bf0234fe3004685c6bb4a Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Sat, 24 Feb 2024 18:02:36 -0800 Subject: [PATCH 60/73] Consolidate message for pending and failed Bitrise comment --- .../scripts/bitrise/check-bitrise-e2e-status.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/scripts/bitrise/check-bitrise-e2e-status.ts b/.github/scripts/bitrise/check-bitrise-e2e-status.ts index d68d7776038..36ec647cea5 100644 --- a/.github/scripts/bitrise/check-bitrise-e2e-status.ts +++ b/.github/scripts/bitrise/check-bitrise-e2e-status.ts @@ -55,22 +55,24 @@ async function main(): Promise { if (bitriseComments.length === 0) { core.setFailed('Bitrise build comment does not exist.'); + process.exit(1); } const lastBitriseComment = bitriseComments[bitriseComments.length - 1]?.body || ''; // Check Bitrise comment status - if (lastBitriseComment.includes(bitrisePendingTag)) { - core.setFailed('Bitrise build is pending.'); - return; - } else if (lastBitriseComment.includes(bitriseFailTag)) { - core.setFailed('Bitrise build has failed.'); - return; + if ( + lastBitriseComment.includes(bitrisePendingTag) || + lastBitriseComment.includes(bitriseFailTag) + ) { + core.setFailed('Did not detect pass status in last Bitrise comment.'); + process.exit(1); } else if (lastBitriseComment.includes(bitriseSuccessTag)) { console.log('Bitrise build has passed.'); + return; } else { core.setFailed('Could not detect Bitrise build status.'); - return; + process.exit(1); } } From 7795e34329568bccad2e9b1f2b3e9d6032554daf Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Sun, 25 Feb 2024 18:04:19 -0800 Subject: [PATCH 61/73] Create scripts types file --- .github/scripts/scripts.types.ts | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .github/scripts/scripts.types.ts diff --git a/.github/scripts/scripts.types.ts b/.github/scripts/scripts.types.ts new file mode 100644 index 00000000000..74e1896729a --- /dev/null +++ b/.github/scripts/scripts.types.ts @@ -0,0 +1,8 @@ +/** + * Pull request trigger types that we use in our scripts + * Expose more types as needed + */ +export enum PullRequestTriggerType { + ReadyForReview = 'ready_for_review', + Labeled = 'labeled', +} From 0b511ff82ebdaf3db8fb587ed126ac98339766d1 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Sun, 25 Feb 2024 18:05:09 -0800 Subject: [PATCH 62/73] Clean up logs --- .github/scripts/bitrise/detect-e2e-label.ts | 8 ++------ .github/scripts/bitrise/run-bitrise-e2e-tests.ts | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/scripts/bitrise/detect-e2e-label.ts b/.github/scripts/bitrise/detect-e2e-label.ts index 34c80eb7506..fb310eb68ee 100644 --- a/.github/scripts/bitrise/detect-e2e-label.ts +++ b/.github/scripts/bitrise/detect-e2e-label.ts @@ -1,11 +1,7 @@ import * as core from '@actions/core'; import { context, getOctokit } from '@actions/github'; import { GitHub } from '@actions/github/lib/utils'; - -enum PullRequestTriggerType { - ReadyForReview = 'ready_for_review', - Labeled = 'labeled', -} +import { PullRequestTriggerType } from '../scripts.types'; main().catch((error: Error): void => { console.error(error); @@ -78,5 +74,5 @@ async function main(): Promise { } // Set the output for the next step to use. - core.setOutput("shouldTriggerE2E", shouldTriggerE2E); + core.setOutput('shouldTriggerE2E', shouldTriggerE2E); } diff --git a/.github/scripts/bitrise/run-bitrise-e2e-tests.ts b/.github/scripts/bitrise/run-bitrise-e2e-tests.ts index 84a4d7f76c7..57ebf39a101 100644 --- a/.github/scripts/bitrise/run-bitrise-e2e-tests.ts +++ b/.github/scripts/bitrise/run-bitrise-e2e-tests.ts @@ -90,7 +90,7 @@ async function main(): Promise { const message = `## [https://bitrise.io/](${buildLink}) **Bitrise**\n\n🔄🔄🔄 \`${e2ePipeline}\` started on Bitrise...🔄🔄🔄\n\nCommit hash: ${latestCommitHash}\nBuild link: ${buildLink}\n\n>[!NOTE]\n>- This comment will auto-update when build completes\n>- You can kick off another \`${e2ePipeline}\` on Bitrise by removing and re-applying the \`${e2eLabel}\` label on the pull request\n${bitriseTag}\n${bitrisePendingTag}\n\n${latestCommitTag}`; if (bitriseBuildResponse.status === 201) { - console.log(message); + console.log(`Started Bitrise build at ${buildLink}`); } else { core.setFailed( `Bitrise build request returned with status code ${bitriseBuildResponse.status}`, From fed8ff6d944a69957400ea0ad516cda269787b35 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Sun, 25 Feb 2024 18:05:51 -0800 Subject: [PATCH 63/73] Verify last commit has passing e2e comment --- .../bitrise/check-bitrise-e2e-status.ts | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/.github/scripts/bitrise/check-bitrise-e2e-status.ts b/.github/scripts/bitrise/check-bitrise-e2e-status.ts index 36ec647cea5..1b478c2ea1e 100644 --- a/.github/scripts/bitrise/check-bitrise-e2e-status.ts +++ b/.github/scripts/bitrise/check-bitrise-e2e-status.ts @@ -21,7 +21,7 @@ async function main(): Promise { process.exit(1); } - // Check if the "Run Smoke E2E" label is applied + // Check if the e2e smoke label is applied const { owner, repo, number: issue_number } = context.issue; const octokit: InstanceType = getOctokit(githubToken); const { data: labels } = await octokit.rest.issues.listLabelsOnIssue({ @@ -31,6 +31,7 @@ async function main(): Promise { }); const hasSmokeTestLabel = labels.some((label) => label.name === e2eLabel); + // Pass check since e2e smoke label is not applied if (!hasSmokeTestLabel) { console.log( `"${e2eLabel}" label not applied. Skipping Bitrise status check.`, @@ -38,37 +39,50 @@ async function main(): Promise { return; } + // Get comments from PR const { data: comments } = await octokit.rest.issues.listComments({ owner, repo, issue_number, }); + // Get latest commit hash + const pullRequestResponse = await octokit.rest.pulls.get({ + owner, + repo, + pull_number: issue_number, + }); + const latestCommitHash = pullRequestResponse.data.head.sha; + + // Define Bitrise comment tags const bitriseTag = ''; const bitrisePendingTag = ''; const bitriseSuccessTag = ''; const bitriseFailTag = ''; + const latestCommitTag = ``; - const bitriseComments = comments.filter((comment) => - comment.body?.includes(bitriseTag), + // Find Bitrise comment + const bitriseComment = comments.find( + ({ body }) => body?.includes(bitriseTag) && body?.includes(latestCommitTag), ); - if (bitriseComments.length === 0) { - core.setFailed('Bitrise build comment does not exist.'); + // Bitrise comment doesn't exist + if (!bitriseComment) { + core.setFailed( + `Bitrise build status comment for commit ${latestCommitHash} does not exist.`, + ); process.exit(1); } - const lastBitriseComment = - bitriseComments[bitriseComments.length - 1]?.body || ''; - - // Check Bitrise comment status + // Check Bitrise build status from comment + const bitriseCommentBody = bitriseComment.body || ''; if ( - lastBitriseComment.includes(bitrisePendingTag) || - lastBitriseComment.includes(bitriseFailTag) + bitriseCommentBody.includes(bitrisePendingTag) || + bitriseCommentBody.includes(bitriseFailTag) ) { core.setFailed('Did not detect pass status in last Bitrise comment.'); process.exit(1); - } else if (lastBitriseComment.includes(bitriseSuccessTag)) { + } else if (bitriseCommentBody.includes(bitriseSuccessTag)) { console.log('Bitrise build has passed.'); return; } else { From 20d5c2d5646f99927a19864362dcb27804ca3a38 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Sun, 25 Feb 2024 19:06:50 -0800 Subject: [PATCH 64/73] Update fail message --- .github/scripts/bitrise/check-bitrise-e2e-status.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/bitrise/check-bitrise-e2e-status.ts b/.github/scripts/bitrise/check-bitrise-e2e-status.ts index 1b478c2ea1e..3ad72adf8b5 100644 --- a/.github/scripts/bitrise/check-bitrise-e2e-status.ts +++ b/.github/scripts/bitrise/check-bitrise-e2e-status.ts @@ -69,7 +69,7 @@ async function main(): Promise { // Bitrise comment doesn't exist if (!bitriseComment) { core.setFailed( - `Bitrise build status comment for commit ${latestCommitHash} does not exist.`, + `Bitrise build status comment for commit ${latestCommitHash} does not exist. Remove and re-apply the "${e2eLabel} label to trigger an E2E smoke test on Bitrise for the latest commit."`, ); process.exit(1); } From 9baf7a5ca33e701ba9563f11b15e29a09495136c Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Sun, 25 Feb 2024 19:09:13 -0800 Subject: [PATCH 65/73] Update fail message --- .github/scripts/bitrise/check-bitrise-e2e-status.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/scripts/bitrise/check-bitrise-e2e-status.ts b/.github/scripts/bitrise/check-bitrise-e2e-status.ts index 3ad72adf8b5..745deb428dc 100644 --- a/.github/scripts/bitrise/check-bitrise-e2e-status.ts +++ b/.github/scripts/bitrise/check-bitrise-e2e-status.ts @@ -69,7 +69,7 @@ async function main(): Promise { // Bitrise comment doesn't exist if (!bitriseComment) { core.setFailed( - `Bitrise build status comment for commit ${latestCommitHash} does not exist. Remove and re-apply the "${e2eLabel} label to trigger an E2E smoke test on Bitrise for the latest commit."`, + `Bitrise build status comment for commit ${latestCommitHash} does not exist. Remove and re-apply the "${e2eLabel} label to trigger a E2E smoke test on Bitrise for the latest commit."`, ); process.exit(1); } @@ -83,7 +83,9 @@ async function main(): Promise { core.setFailed('Did not detect pass status in last Bitrise comment.'); process.exit(1); } else if (bitriseCommentBody.includes(bitriseSuccessTag)) { - console.log('Bitrise build has passed.'); + console.log( + `Bitrise build status comment for commit ${latestCommitHash} has passed.`, + ); return; } else { core.setFailed('Could not detect Bitrise build status.'); From 949a2ea9bff60dcd81743a708b2d3ee382848d2a Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Sun, 25 Feb 2024 19:19:33 -0800 Subject: [PATCH 66/73] Consolidate logs --- .../scripts/bitrise/check-bitrise-e2e-status.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/scripts/bitrise/check-bitrise-e2e-status.ts b/.github/scripts/bitrise/check-bitrise-e2e-status.ts index 745deb428dc..6a5e0f49a7b 100644 --- a/.github/scripts/bitrise/check-bitrise-e2e-status.ts +++ b/.github/scripts/bitrise/check-bitrise-e2e-status.ts @@ -66,10 +66,12 @@ async function main(): Promise { ({ body }) => body?.includes(bitriseTag) && body?.includes(latestCommitTag), ); + const bitriseCommentPrefix = `Bitrise build status comment for commit ${latestCommitHash}`; + // Bitrise comment doesn't exist if (!bitriseComment) { core.setFailed( - `Bitrise build status comment for commit ${latestCommitHash} does not exist. Remove and re-apply the "${e2eLabel} label to trigger a E2E smoke test on Bitrise for the latest commit."`, + `${bitriseCommentPrefix} does not exist. Remove and re-apply the "${e2eLabel}" label to trigger a E2E smoke test on Bitrise.`, ); process.exit(1); } @@ -80,15 +82,15 @@ async function main(): Promise { bitriseCommentBody.includes(bitrisePendingTag) || bitriseCommentBody.includes(bitriseFailTag) ) { - core.setFailed('Did not detect pass status in last Bitrise comment.'); + core.setFailed(`${bitriseCommentPrefix} is not yet passed.`); process.exit(1); } else if (bitriseCommentBody.includes(bitriseSuccessTag)) { - console.log( - `Bitrise build status comment for commit ${latestCommitHash} has passed.`, - ); + console.log(`${bitriseCommentPrefix} has passed.`); return; } else { - core.setFailed('Could not detect Bitrise build status.'); + core.setFailed( + `${bitriseCommentPrefix} does not contain any build status. Please verify that the build status tag exists in the comment body.`, + ); process.exit(1); } } From f0058136bd787c2de29df7353c1a11e305148ff6 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Mon, 26 Feb 2024 18:18:53 -0800 Subject: [PATCH 67/73] Filter out commit that merges from main --- .../bitrise/check-bitrise-e2e-status.ts | 48 +++++++++++++++---- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/.github/scripts/bitrise/check-bitrise-e2e-status.ts b/.github/scripts/bitrise/check-bitrise-e2e-status.ts index 6a5e0f49a7b..7df3a470781 100644 --- a/.github/scripts/bitrise/check-bitrise-e2e-status.ts +++ b/.github/scripts/bitrise/check-bitrise-e2e-status.ts @@ -10,6 +10,7 @@ main().catch((error: Error): void => { async function main(): Promise { const githubToken = process.env.GITHUB_TOKEN; const e2eLabel = process.env.E2E_LABEL; + const removeAndApplyInstructions = `Remove and re-apply the "${e2eLabel}" label to trigger a E2E smoke test on Bitrise.`; if (!githubToken) { core.setFailed('GITHUB_TOKEN not found'); @@ -21,14 +22,18 @@ async function main(): Promise { process.exit(1); } - // Check if the e2e smoke label is applied const { owner, repo, number: issue_number } = context.issue; const octokit: InstanceType = getOctokit(githubToken); - const { data: labels } = await octokit.rest.issues.listLabelsOnIssue({ + + // Get PR information + const { data: prData } = await octokit.rest.pulls.get({ owner, repo, - issue_number, + pull_number: issue_number, }); + + // Check if the e2e smoke label is applied + const labels = prData.labels; const hasSmokeTestLabel = labels.some((label) => label.name === e2eLabel); // Pass check since e2e smoke label is not applied @@ -39,39 +44,64 @@ async function main(): Promise { return; } + // Get last 10 commits + const numberOfCommitsToCheck = 10; // Consider commits older than 10 commits ago invalidated + const numberOfCommits = prData.commits; + const commitPage = Math.ceil(numberOfCommits / numberOfCommitsToCheck); + + // Get last 30 comments + const numberOfCommentsToCheck = 30; // Consider comments older than 30 comments ago invalidated + const numberOfComments = prData.comments; + const commentPage = Math.ceil(numberOfComments / numberOfCommentsToCheck); + // Get comments from PR const { data: comments } = await octokit.rest.issues.listComments({ owner, repo, issue_number, + page: commentPage, + per_page: numberOfCommentsToCheck, }); - // Get latest commit hash - const pullRequestResponse = await octokit.rest.pulls.get({ + // Get latest commit hash that excludes merges from main + const { data: commits } = await octokit.rest.pulls.listCommits({ owner, repo, pull_number: issue_number, + page: commitPage, + per_page: numberOfCommitsToCheck, }); - const latestCommitHash = pullRequestResponse.data.head.sha; + const mergeFromMainCommitMessagePrefix = `Merge branch 'main' into`; + const nonMergeFromMainCommits = commits.filter( + (commit) => + !commit.commit.message.includes(mergeFromMainCommitMessagePrefix), + ); + const commitHashToCheck = + nonMergeFromMainCommits[nonMergeFromMainCommits.length - 1]?.sha; + + if (!commitHashToCheck) { + core.setFailed(`Commits are invalidated. ${removeAndApplyInstructions}`); + process.exit(1); + } // Define Bitrise comment tags const bitriseTag = ''; const bitrisePendingTag = ''; const bitriseSuccessTag = ''; const bitriseFailTag = ''; - const latestCommitTag = ``; + const latestCommitTag = ``; // Find Bitrise comment const bitriseComment = comments.find( ({ body }) => body?.includes(bitriseTag) && body?.includes(latestCommitTag), ); - const bitriseCommentPrefix = `Bitrise build status comment for commit ${latestCommitHash}`; + const bitriseCommentPrefix = `Bitrise build status comment for commit ${commitHashToCheck}`; // Bitrise comment doesn't exist if (!bitriseComment) { core.setFailed( - `${bitriseCommentPrefix} does not exist. Remove and re-apply the "${e2eLabel}" label to trigger a E2E smoke test on Bitrise.`, + `${bitriseCommentPrefix} does not exist. ${removeAndApplyInstructions}`, ); process.exit(1); } From 5bbfe6157bb1fc05f7b75151666f024c5352411f Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Mon, 26 Feb 2024 20:11:16 -0800 Subject: [PATCH 68/73] Add comments --- .github/scripts/bitrise/run-bitrise-e2e-tests.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/scripts/bitrise/run-bitrise-e2e-tests.ts b/.github/scripts/bitrise/run-bitrise-e2e-tests.ts index 57ebf39a101..684af157dc9 100644 --- a/.github/scripts/bitrise/run-bitrise-e2e-tests.ts +++ b/.github/scripts/bitrise/run-bitrise-e2e-tests.ts @@ -30,6 +30,7 @@ async function main(): Promise { const octokit: InstanceType = getOctokit(githubToken); + // Get the latest commit hash const pullRequestResponse = await octokit.rest.pulls.get({ owner: repoOwner, repo, @@ -38,6 +39,7 @@ async function main(): Promise { const latestCommitHash = pullRequestResponse.data.head.sha; + // Configure Bitrise configuration for API call const data = { build_params: { branch: process.env.GITHUB_HEAD_REF, From 0e7eaa82a9e77e778e298a46d1069b6d503b6849 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Tue, 27 Feb 2024 22:59:48 -0800 Subject: [PATCH 69/73] Enable test runs on merge from main commits --- .../bitrise/check-bitrise-e2e-status.ts | 152 +++++++++++------- 1 file changed, 97 insertions(+), 55 deletions(-) diff --git a/.github/scripts/bitrise/check-bitrise-e2e-status.ts b/.github/scripts/bitrise/check-bitrise-e2e-status.ts index 7df3a470781..75f401a76a6 100644 --- a/.github/scripts/bitrise/check-bitrise-e2e-status.ts +++ b/.github/scripts/bitrise/check-bitrise-e2e-status.ts @@ -11,6 +11,7 @@ async function main(): Promise { const githubToken = process.env.GITHUB_TOKEN; const e2eLabel = process.env.E2E_LABEL; const removeAndApplyInstructions = `Remove and re-apply the "${e2eLabel}" label to trigger a E2E smoke test on Bitrise.`; + const mergeFromMainCommitMessagePrefix = `Merge branch 'main' into`; if (!githubToken) { core.setFailed('GITHUB_TOKEN not found'); @@ -44,82 +45,123 @@ async function main(): Promise { return; } - // Get last 10 commits - const numberOfCommitsToCheck = 10; // Consider commits older than 10 commits ago invalidated - const numberOfCommits = prData.commits; - const commitPage = Math.ceil(numberOfCommits / numberOfCommitsToCheck); - - // Get last 30 comments - const numberOfCommentsToCheck = 30; // Consider comments older than 30 comments ago invalidated - const numberOfComments = prData.comments; - const commentPage = Math.ceil(numberOfComments / numberOfCommentsToCheck); - - // Get comments from PR - const { data: comments } = await octokit.rest.issues.listComments({ - owner, - repo, - issue_number, - page: commentPage, - per_page: numberOfCommentsToCheck, - }); - - // Get latest commit hash that excludes merges from main - const { data: commits } = await octokit.rest.pulls.listCommits({ - owner, - repo, - pull_number: issue_number, - page: commitPage, - per_page: numberOfCommitsToCheck, - }); - const mergeFromMainCommitMessagePrefix = `Merge branch 'main' into`; - const nonMergeFromMainCommits = commits.filter( - (commit) => - !commit.commit.message.includes(mergeFromMainCommitMessagePrefix), - ); - const commitHashToCheck = - nonMergeFromMainCommits[nonMergeFromMainCommits.length - 1]?.sha; - - if (!commitHashToCheck) { - core.setFailed(`Commits are invalidated. ${removeAndApplyInstructions}`); - process.exit(1); - } - // Define Bitrise comment tags const bitriseTag = ''; const bitrisePendingTag = ''; const bitriseSuccessTag = ''; const bitriseFailTag = ''; - const latestCommitTag = ``; - // Find Bitrise comment - const bitriseComment = comments.find( - ({ body }) => body?.includes(bitriseTag) && body?.includes(latestCommitTag), + // Get at least the last 30 comments + const numberOfTotalComments = prData.comments; + const numberOfCommentsToCheck = 30; + const lastCommentPage = Math.ceil( + numberOfTotalComments / numberOfCommentsToCheck, ); + const { data: latestCommentBatch } = await octokit.rest.issues.listComments({ + owner, + repo, + issue_number: issue_number, + page: lastCommentPage, + per_page: numberOfCommentsToCheck, + }); + let comments = [...latestCommentBatch]; + if ( + numberOfTotalComments % numberOfCommentsToCheck !== 0 && + lastCommentPage > 1 + ) { + // Also fetch previous 30 comments + const { data: previousCommentBatch } = + await octokit.rest.issues.listComments({ + owner, + repo, + issue_number: issue_number, + page: lastCommentPage - 1, + per_page: numberOfCommentsToCheck, + }); + comments = [...previousCommentBatch, ...comments]; + } - const bitriseCommentPrefix = `Bitrise build status comment for commit ${commitHashToCheck}`; + const bitriseComment = comments + .toReversed() + .find(({ body }) => body?.includes(bitriseTag)); // Bitrise comment doesn't exist if (!bitriseComment) { core.setFailed( - `${bitriseCommentPrefix} does not exist. ${removeAndApplyInstructions}`, + `No Bitrise build status comment found. ${removeAndApplyInstructions}`, ); process.exit(1); } - // Check Bitrise build status from comment + // This regex matches a 40-character hexadecimal string enclosed within + const commitTagRegex = //i; const bitriseCommentBody = bitriseComment.body || ''; + const hashMatch = bitriseCommentBody.match(commitTagRegex); + const bitriseCommentCommitHash = + hashMatch && hashMatch[1] ? hashMatch[1] : ''; + + // Get at least the last 10 commits + const numberOfTotalCommits = prData.commits; + const numberOfCommitsToCheck = 10; + const lastCommitPage = Math.ceil( + numberOfTotalCommits / numberOfCommitsToCheck, + ); + const { data: latestCommitBatch } = await octokit.rest.pulls.listCommits({ + owner, + repo, + pull_number: issue_number, + page: lastCommitPage, + per_page: numberOfCommitsToCheck, + }); + let commits = [...latestCommitBatch]; if ( - bitriseCommentBody.includes(bitrisePendingTag) || - bitriseCommentBody.includes(bitriseFailTag) + numberOfTotalCommits % numberOfCommitsToCheck !== 0 && + lastCommitPage > 1 ) { - core.setFailed(`${bitriseCommentPrefix} is not yet passed.`); - process.exit(1); - } else if (bitriseCommentBody.includes(bitriseSuccessTag)) { - console.log(`${bitriseCommentPrefix} has passed.`); - return; + // Also fetch previous 10 commits + const { data: previousCommitBatch } = await octokit.rest.pulls.listCommits({ + owner, + repo, + pull_number: issue_number, + page: lastCommitPage - 1, + per_page: numberOfCommitsToCheck, + }); + commits = [...previousCommitBatch, ...commits]; + } + + // Relevant hashes include both merge from main commits and the last non-merge from main commit + const relevantCommitHashes: string[] = []; + for (const commit of commits.toReversed()) { + const commitMessage = commit.commit.message; + relevantCommitHashes.push(commit.sha); + if (!commitMessage.includes(mergeFromMainCommitMessagePrefix)) { + break; + } + } + + // Check if Bitrise comment hash matches any of the relevant commit hashes + if (relevantCommitHashes.includes(bitriseCommentCommitHash)) { + // Check Bitrise build status from comment + const bitriseCommentPrefix = `Bitrise build status comment for commit ${bitriseCommentCommitHash}`; + if ( + bitriseCommentBody.includes(bitrisePendingTag) || + bitriseCommentBody.includes(bitriseFailTag) + ) { + core.setFailed(`${bitriseCommentPrefix} is not yet passed.`); + process.exit(1); + } else if (bitriseCommentBody.includes(bitriseSuccessTag)) { + console.log(`${bitriseCommentPrefix} has passed.`); + return; + } else { + core.setFailed( + `${bitriseCommentPrefix} does not contain any build status. Please verify that the build status tag exists in the comment body.`, + ); + process.exit(1); + } } else { + // No build comment found for relevant commits core.setFailed( - `${bitriseCommentPrefix} does not contain any build status. Please verify that the build status tag exists in the comment body.`, + `No Bitrise build comment exists for latest commits. ${removeAndApplyInstructions}`, ); process.exit(1); } From cb67272919a61922c44d4e5d7cc590a5a96f02e1 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Tue, 27 Feb 2024 23:02:40 -0800 Subject: [PATCH 70/73] Fix reverse --- .github/scripts/bitrise/check-bitrise-e2e-status.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/bitrise/check-bitrise-e2e-status.ts b/.github/scripts/bitrise/check-bitrise-e2e-status.ts index 75f401a76a6..c5e0e00633a 100644 --- a/.github/scripts/bitrise/check-bitrise-e2e-status.ts +++ b/.github/scripts/bitrise/check-bitrise-e2e-status.ts @@ -82,7 +82,7 @@ async function main(): Promise { } const bitriseComment = comments - .toReversed() + .reverse() .find(({ body }) => body?.includes(bitriseTag)); // Bitrise comment doesn't exist @@ -131,7 +131,7 @@ async function main(): Promise { // Relevant hashes include both merge from main commits and the last non-merge from main commit const relevantCommitHashes: string[] = []; - for (const commit of commits.toReversed()) { + for (const commit of commits.reverse()) { const commitMessage = commit.commit.message; relevantCommitHashes.push(commit.sha); if (!commitMessage.includes(mergeFromMainCommitMessagePrefix)) { From e8e538af527a94feb9adafb7b2982960232fe85a Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Wed, 28 Feb 2024 12:21:25 -0800 Subject: [PATCH 71/73] Check latest commit on label added --- .../scripts/bitrise/check-bitrise-e2e-status.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/scripts/bitrise/check-bitrise-e2e-status.ts b/.github/scripts/bitrise/check-bitrise-e2e-status.ts index c5e0e00633a..caa3fc32fbc 100644 --- a/.github/scripts/bitrise/check-bitrise-e2e-status.ts +++ b/.github/scripts/bitrise/check-bitrise-e2e-status.ts @@ -1,6 +1,7 @@ import * as core from '@actions/core'; import { context, getOctokit } from '@actions/github'; import { GitHub } from '@actions/github/lib/utils'; +import { PullRequestTriggerType } from '../scripts.types'; main().catch((error: Error): void => { console.error(error); @@ -10,6 +11,7 @@ main().catch((error: Error): void => { async function main(): Promise { const githubToken = process.env.GITHUB_TOKEN; const e2eLabel = process.env.E2E_LABEL; + const triggerAction = context.payload.action as PullRequestTriggerType; const removeAndApplyInstructions = `Remove and re-apply the "${e2eLabel}" label to trigger a E2E smoke test on Bitrise.`; const mergeFromMainCommitMessagePrefix = `Merge branch 'main' into`; @@ -97,8 +99,7 @@ async function main(): Promise { const commitTagRegex = //i; const bitriseCommentBody = bitriseComment.body || ''; const hashMatch = bitriseCommentBody.match(commitTagRegex); - const bitriseCommentCommitHash = - hashMatch && hashMatch[1] ? hashMatch[1] : ''; + let bitriseCommentCommitHash = hashMatch && hashMatch[1] ? hashMatch[1] : ''; // Get at least the last 10 commits const numberOfTotalCommits = prData.commits; @@ -139,6 +140,15 @@ async function main(): Promise { } } + console.log('relevantCommitHashes', relevantCommitHashes); + + if (triggerAction === PullRequestTriggerType.Labeled) { + // A Bitrise build was triggered for the last commit + bitriseCommentCommitHash = relevantCommitHashes[0]; + } + + console.log('bitriseCommentCommitHash', bitriseCommentCommitHash); + // Check if Bitrise comment hash matches any of the relevant commit hashes if (relevantCommitHashes.includes(bitriseCommentCommitHash)) { // Check Bitrise build status from comment From 6036a02aeb0fd3a03e79f17d7634eaba15e68150 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Wed, 28 Feb 2024 12:40:11 -0800 Subject: [PATCH 72/73] Clean up check conditions --- .github/scripts/bitrise/check-bitrise-e2e-status.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/scripts/bitrise/check-bitrise-e2e-status.ts b/.github/scripts/bitrise/check-bitrise-e2e-status.ts index caa3fc32fbc..1c5841ed7e0 100644 --- a/.github/scripts/bitrise/check-bitrise-e2e-status.ts +++ b/.github/scripts/bitrise/check-bitrise-e2e-status.ts @@ -96,8 +96,8 @@ async function main(): Promise { } // This regex matches a 40-character hexadecimal string enclosed within + let bitriseCommentBody = bitriseComment.body || ''; const commitTagRegex = //i; - const bitriseCommentBody = bitriseComment.body || ''; const hashMatch = bitriseCommentBody.match(commitTagRegex); let bitriseCommentCommitHash = hashMatch && hashMatch[1] ? hashMatch[1] : ''; @@ -145,6 +145,7 @@ async function main(): Promise { if (triggerAction === PullRequestTriggerType.Labeled) { // A Bitrise build was triggered for the last commit bitriseCommentCommitHash = relevantCommitHashes[0]; + bitriseCommentBody = bitrisePendingTag; } console.log('bitriseCommentCommitHash', bitriseCommentCommitHash); @@ -153,11 +154,11 @@ async function main(): Promise { if (relevantCommitHashes.includes(bitriseCommentCommitHash)) { // Check Bitrise build status from comment const bitriseCommentPrefix = `Bitrise build status comment for commit ${bitriseCommentCommitHash}`; - if ( - bitriseCommentBody.includes(bitrisePendingTag) || - bitriseCommentBody.includes(bitriseFailTag) - ) { - core.setFailed(`${bitriseCommentPrefix} is not yet passed.`); + if (bitriseCommentBody.includes(bitrisePendingTag)) { + core.setFailed(`${bitriseCommentPrefix} is pending.`); + process.exit(1); + } else if (bitriseCommentBody.includes(bitriseFailTag)) { + core.setFailed(`${bitriseCommentPrefix} has failed.`); process.exit(1); } else if (bitriseCommentBody.includes(bitriseSuccessTag)) { console.log(`${bitriseCommentPrefix} has passed.`); From d249cee8a9b80ac0cd0368f2dec4d89aa68803af Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Wed, 28 Feb 2024 13:58:14 -0800 Subject: [PATCH 73/73] Remove console logs --- .github/scripts/bitrise/check-bitrise-e2e-status.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/scripts/bitrise/check-bitrise-e2e-status.ts b/.github/scripts/bitrise/check-bitrise-e2e-status.ts index 1c5841ed7e0..7e1926b3ebb 100644 --- a/.github/scripts/bitrise/check-bitrise-e2e-status.ts +++ b/.github/scripts/bitrise/check-bitrise-e2e-status.ts @@ -140,16 +140,12 @@ async function main(): Promise { } } - console.log('relevantCommitHashes', relevantCommitHashes); - if (triggerAction === PullRequestTriggerType.Labeled) { // A Bitrise build was triggered for the last commit bitriseCommentCommitHash = relevantCommitHashes[0]; bitriseCommentBody = bitrisePendingTag; } - console.log('bitriseCommentCommitHash', bitriseCommentCommitHash); - // Check if Bitrise comment hash matches any of the relevant commit hashes if (relevantCommitHashes.includes(bitriseCommentCommitHash)) { // Check Bitrise build status from comment