-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ci: Create github action for triggering Bitrise E2E builds based on label #7339
Merged
+256
−0
Merged
Changes from all commits
Commits
Show all changes
86 commits
Select commit
Hold shift + click to select a range
0f72d3e
Create github action for triggering Bitrise E2E builds based on label
Cal-L 30699ac
Remove -L
Cal-L 89252de
Fix string
Cal-L 9f0f615
Update format
Cal-L 1acc611
Remove unrelated workflows
Cal-L 571302d
Remove PR id
Cal-L a9fcef0
Add back PR ID
Cal-L 748323a
Fix workflow
Cal-L 3202a66
Simplify Bitrise command
Cal-L f4bd209
Remove extra comma
Cal-L e54d17e
Revert "Remove unrelated workflows"
Cal-L 63c33ab
Merge branch 'main' of https://github.com/MetaMask/metamask-mobile in…
Cal-L 07c1e7f
Comment out label triggered workflow
Cal-L 2dcf209
Add Bitrise trigger map for commits
Cal-L f444328
Add extra space
Cal-L 48c6cd8
Change trigger to push
Cal-L a2d0682
PR into feature branch
Cal-L fe16292
Remove trigger map
Cal-L 4b89c04
Log values
Cal-L 039d1d8
Change to main branch
Cal-L 63c2650
Revert ios_e2e_test
Cal-L 2fd06fa
Reduce logic for testing
Cal-L c7a2369
Create tag whenever label is applied
Cal-L 864cb96
Kick off Bitrise build for PR label
Cal-L 42b8a04
Rename context
Cal-L bde6989
Split out script
Cal-L 1201f45
Add missing yarn command
Cal-L 4ba4478
Install yarn
Cal-L df8a4b9
Install deps
Cal-L 098b870
Fix RUN E2E label name
Cal-L 5f7e4e9
Rename action
Cal-L 623acf7
Fix label name
Cal-L c13ccb0
Fetch using public api
Cal-L 8b26e4f
Add axios
Cal-L 7a25d2c
Try creating a tag using github actions account
Cal-L 1d895ea
Trigger Bitrise build in script
Cal-L f1eb0d2
Pass missing env vars
Cal-L 7787f7f
Log build url
Cal-L ca6e07d
Log build id
Cal-L a051705
Post comment
Cal-L 2552de4
Allow write permissions
Cal-L 7724400
Try to update PR status
Cal-L f71778c
Readd token
Cal-L 2e3fa57
Add write status permissions
Cal-L e1d590b
Just post comment for now
Cal-L 949942d
Change workflow names
Cal-L f6de803
Add logs
Cal-L 78b87c2
Provide PR link in logs
Cal-L 52ab76f
Re-enable workflows
Cal-L 382c913
Provide Bitrise with commit message
Cal-L c82d20a
Fix formatting
Cal-L 9ba8f7d
Fix commit key
Cal-L cd1b0ea
Merge branch 'main' of https://github.com/MetaMask/metamask-mobile in…
Cal-L 99ac0f9
Undo workflow changes
Cal-L ba206a3
Remove unused code
Cal-L ffe0862
Remove more unused code
Cal-L 29db28d
Check for label first
Cal-L 907ae44
Test fail scenario
Cal-L ec03cc2
Fix comments error
Cal-L 3c29a4d
Conditionally run run-bitrise-e2e job
Cal-L 50a4f6f
Fix reference error
Cal-L b2a32b9
Check boolean
Cal-L a856f0e
Set output of label step
Cal-L 3d31699
Try moving things around
Cal-L abba06d
Create env vars
Cal-L c79e28e
Improve logs
Cal-L 17dd38d
Merge branch 'main' of https://github.com/MetaMask/metamask-mobile in…
Cal-L d12e5e2
Merge branch 'main' of https://github.com/MetaMask/metamask-mobile in…
Cal-L 1f0a6d8
Format run-bitrise-e2e
Cal-L 5abaf37
Create add-e2e-label workflow for opening and
Cal-L a1eeb45
Fix trigger name
Cal-L 3636a1a
No need to remove label that doesn't exist
Cal-L b4d22d7
Type Error
Cal-L 9697de6
Merge triggers since API added labels do not seem to trigger trigger
Cal-L 84db312
Fix typo
Cal-L 58d7f37
Rename files
Cal-L ecbe017
Conditionally run the last step
Cal-L 71f694d
Fix path
Cal-L e75b0d9
Fix typo
Cal-L 4feb455
Simplify bitrise run step
Cal-L ed26bf0
Add reopened trigger
Cal-L e4659ac
Handle reopened scenario
Cal-L bd24991
Unlock comment
Cal-L fe0bb10
Merge branch 'main' of https://github.com/MetaMask/metamask-mobile in…
Cal-L 34fa593
Add instructions to re-build Bitrise E2E smoke tests
Cal-L 59409c1
Update workflow name
Cal-L File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
.github/scripts/check-bitrise-e2e-smoke/check-e2e-smoke-trigger.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import * as core from '@actions/core'; | ||
import { context, getOctokit } from '@actions/github'; | ||
import { GitHub } from '@actions/github/lib/utils'; | ||
|
||
enum PullRequestTriggerType { | ||
Opened = 'opened', | ||
Reopened = 'reopened', | ||
ReadyForReview = 'ready_for_review', | ||
Labeled = 'labeled', | ||
} | ||
|
||
main().catch((error: Error): void => { | ||
console.error(error); | ||
process.exit(1); | ||
}); | ||
|
||
async function main(): Promise<void> { | ||
const githubToken = process.env.GITHUB_TOKEN; | ||
const e2eLabel = process.env.E2E_LABEL; | ||
const triggerAction = context.payload.action as PullRequestTriggerType; | ||
const pullRequestLink = `https://github.com/MetaMask/metamask-mobile/pull/${context.issue.number}`; | ||
let shouldTriggerE2E = false; | ||
|
||
if (!githubToken) { | ||
core.setFailed('GITHUB_TOKEN not found'); | ||
process.exit(1); | ||
} | ||
|
||
if (!e2eLabel) { | ||
core.setFailed('E2E_LABEL not found'); | ||
process.exit(1); | ||
} | ||
|
||
console.log(`Workflow triggered by the event (${triggerAction})`); | ||
|
||
switch (triggerAction) { | ||
case PullRequestTriggerType.Opened: | ||
shouldTriggerE2E = !context.payload.pull_request?.draft; | ||
if (!shouldTriggerE2E) { | ||
console.log(`Skipping E2E smoke since opened PR is in draft.`); | ||
} else { | ||
console.log(`Starting E2E smoke since opened PR is ready for review.`); | ||
} | ||
break; | ||
case PullRequestTriggerType.Reopened: | ||
shouldTriggerE2E = !context.payload.pull_request?.draft; | ||
if (!shouldTriggerE2E) { | ||
console.log(`Skipping E2E smoke since reopened PR is in draft.`); | ||
} else { | ||
console.log(`Starting E2E smoke since reopened PR is ready for review.`); | ||
} | ||
break; | ||
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<typeof GitHub> = 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) { | ||
console.log(`Error occured when applying label: ${error}`); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
// Set the output for the next step to use. | ||
core.setOutput("shouldTriggerE2E", shouldTriggerE2E); | ||
} |
108 changes: 108 additions & 0 deletions
108
.github/scripts/check-bitrise-e2e-smoke/run-bitrise-e2e-smoke.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import * as core from '@actions/core'; | ||
import { context, getOctokit } from '@actions/github'; | ||
import { GitHub } from '@actions/github/lib/utils'; | ||
import axios from 'axios'; | ||
|
||
main().catch((error: Error): void => { | ||
console.error(error); | ||
process.exit(1); | ||
}); | ||
|
||
async function main(): Promise<void> { | ||
const e2eLabel = process.env.E2E_LABEL; | ||
const githubToken = process.env.GITHUB_TOKEN; | ||
const e2ePipeline = process.env.E2E_PIPELINE; | ||
const workflowName = process.env.WORKFLOW_NAME; | ||
const pullRequestNumber = context.issue.number; | ||
const repoOwner = context.repo.owner; | ||
const repo = context.repo.repo; | ||
const pullRequestLink = `https://github.com/MetaMask/metamask-mobile/pull/${pullRequestNumber}`; | ||
|
||
if (!githubToken) { | ||
core.setFailed('GITHUB_TOKEN not found'); | ||
process.exit(1); | ||
} | ||
|
||
if (!e2ePipeline) { | ||
core.setFailed('E2E_PIPELINE not found'); | ||
process.exit(1); | ||
} | ||
|
||
const octokit: InstanceType<typeof GitHub> = 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, | ||
commit_message: `Triggered by (${workflowName}) workflow in ${pullRequestLink}`, | ||
}, | ||
triggered_by: workflowName, | ||
}; | ||
|
||
const bitriseProjectUrl = `https://app.bitrise.io/app/${process.env.BITRISE_APP_ID}`; | ||
|
||
// Start Bitrise build. | ||
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`); | ||
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`; | ||
|
||
if (bitriseBuildResponse.status === 201) { | ||
console.log(message); | ||
} else { | ||
core.setFailed( | ||
`Bitrise build request returned with status code ${bitriseBuildResponse.status}`, | ||
); | ||
process.exit(1); | ||
} | ||
|
||
// Reopen conversation in case it's locked | ||
const unlockConvoResponse = await octokit.rest.issues.unlock({ | ||
owner: repoOwner, | ||
repo, | ||
issue_number: pullRequestNumber, | ||
}); | ||
|
||
if (unlockConvoResponse.status === 204) { | ||
console.log(`Unlocked conversation for PR ${pullRequestLink}`); | ||
} else { | ||
core.setFailed( | ||
`Unlock conversation request returned with status code ${unlockConvoResponse.status}`, | ||
); | ||
process.exit(1); | ||
} | ||
|
||
// Post build link in PR comments. | ||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Check Bitrise E2E Smoke Tests | ||
|
||
on: | ||
pull_request: | ||
types: [opened, reopened, ready_for_review, labeled] | ||
|
||
env: | ||
E2E_LABEL: 'Run Smoke E2E' | ||
E2E_PIPELINE: 'pr_smoke_e2e_pipeline' | ||
WORKFLOW_NAME: 'check-bitrise-e2e-smoke' | ||
|
||
jobs: | ||
check-bitrise-e2e-smoke: | ||
runs-on: ubuntu-latest | ||
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 Axios | ||
run: yarn add axios | ||
|
||
- name: Install dependencies | ||
run: yarn --immutable | ||
|
||
- name: Check E2E trigger | ||
id: check-trigger | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: yarn run check-e2e-smoke-trigger | ||
|
||
- name: Run Bitrise E2E | ||
if: steps.check-trigger.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update this to setFailed instead