From 847a717664ca043b6ab96e295dd4cdffe8ad5b2e Mon Sep 17 00:00:00 2001 From: rory Date: Fri, 1 Dec 2023 09:26:59 -0800 Subject: [PATCH 1/5] Get rid of 1-step composite actions and bump aws-actions/configure-aws-credentials to v4 --- .../configureAwsCredentials/action.yml | 25 ----------------- .github/workflows/e2ePerformanceTests.yml | 8 +++--- .github/workflows/platformDeploy.yml | 9 +++--- .github/workflows/testBuild.yml | 28 +++++++++++-------- 4 files changed, 25 insertions(+), 45 deletions(-) delete mode 100644 .github/actions/composite/configureAwsCredentials/action.yml diff --git a/.github/actions/composite/configureAwsCredentials/action.yml b/.github/actions/composite/configureAwsCredentials/action.yml deleted file mode 100644 index f092478962c8..000000000000 --- a/.github/actions/composite/configureAwsCredentials/action.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: 'Configure AWS Credentials' -description: 'Configures AWS credentials for the workflow' - -inputs: - AWS_ACCESS_KEY_ID: - description: 'Access Key to AWS' - required: true - AWS_SECRET_ACCESS_KEY: - description: 'Secret Access Key to AWS' - required: true - AWS_REGION: - description: 'Region for AWS' - required: true - default: 'us-east-1' - -runs: - using: composite - steps: - - name: Configure AWS Credentials - # Version: 1.5.5 - uses: aws-actions/configure-aws-credentials@e97d7fbc8e0e5af69631c13daa0f4b5a8d88165b - with: - aws-access-key-id: ${{ inputs.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ inputs.AWS_SECRET_ACCESS_KEY }} - aws-region: ${{ inputs.AWS_REGION }} diff --git a/.github/workflows/e2ePerformanceTests.yml b/.github/workflows/e2ePerformanceTests.yml index 92b4e52c159c..09113bdcc548 100644 --- a/.github/workflows/e2ePerformanceTests.yml +++ b/.github/workflows/e2ePerformanceTests.yml @@ -190,11 +190,11 @@ jobs: run: zip -qr App.zip ./zip - name: Configure AWS Credentials - uses: ./.github/actions/composite/configureAwsCredentials + uses: aws-actions/configure-aws-credentials@v4 with: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - AWS_REGION: us-west-2 + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-west-1 - name: Schedule AWS Device Farm test run on main branch uses: realm/aws-devicefarm/test-application@7b9a91236c456c97e28d384c9e476035d5ea686b diff --git a/.github/workflows/platformDeploy.yml b/.github/workflows/platformDeploy.yml index bf27006e34a2..853f6e20ebf2 100644 --- a/.github/workflows/platformDeploy.yml +++ b/.github/workflows/platformDeploy.yml @@ -61,7 +61,7 @@ jobs: with: distribution: 'oracle' java-version: '17' - + - name: Setup Ruby uses: ruby/setup-ruby@a05e47355e80e57b9a67566a813648fa67d92011 with: @@ -298,10 +298,11 @@ jobs: run: pip3 install cloudflare - name: Configure AWS Credentials - uses: ./.github/actions/composite/configureAwsCredentials + uses: aws-actions/configure-aws-credentials@v4 with: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 - name: Build web for production if: ${{ fromJSON(env.SHOULD_DEPLOY_PRODUCTION) }} diff --git a/.github/workflows/testBuild.yml b/.github/workflows/testBuild.yml index 94a51a2d11bd..e2ea29b5210b 100644 --- a/.github/workflows/testBuild.yml +++ b/.github/workflows/testBuild.yml @@ -107,10 +107,11 @@ jobs: LARGE_SECRET_PASSPHRASE: ${{ secrets.LARGE_SECRET_PASSPHRASE }} - name: Configure AWS Credentials - uses: ./.github/actions/composite/configureAwsCredentials + uses: aws-actions/configure-aws-credentials@v4 with: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 - name: Configure MapBox SDK run: ./scripts/setup-mapbox-sdk.sh ${{ secrets.MAPBOX_SDK_DOWNLOAD_TOKEN }} @@ -197,10 +198,11 @@ jobs: LARGE_SECRET_PASSPHRASE: ${{ secrets.LARGE_SECRET_PASSPHRASE }} - name: Configure AWS Credentials - uses: ./.github/actions/composite/configureAwsCredentials + uses: aws-actions/configure-aws-credentials@v4 with: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 - name: Run Fastlane run: bundle exec fastlane ios build_internal @@ -244,10 +246,11 @@ jobs: DEVELOPER_ID_SECRET_PASSPHRASE: ${{ secrets.DEVELOPER_ID_SECRET_PASSPHRASE }} - name: Configure AWS Credentials - uses: ./.github/actions/composite/configureAwsCredentials + uses: aws-actions/configure-aws-credentials@v4 with: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 - name: Build desktop app for testing run: npm run desktop-build-adhoc @@ -282,10 +285,11 @@ jobs: uses: ./.github/actions/composite/setupNode - name: Configure AWS Credentials - uses: ./.github/actions/composite/configureAwsCredentials + uses: aws-actions/configure-aws-credentials@v4 with: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 - name: Build web for testing run: npm run build-adhoc From a5a17db95d2210795c03ccf344a3cce431dc9aa3 Mon Sep 17 00:00:00 2001 From: rory Date: Fri, 1 Dec 2023 09:41:01 -0800 Subject: [PATCH 2/5] Update postTestBuildComment action to include a link to the workflow run --- .../javascript/postTestBuildComment/index.js | 7 ++++++- .../postTestBuildComment/postTestBuildComment.js | 7 ++++++- tests/unit/postTestBuildComment.js | 13 ++++++++++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.github/actions/javascript/postTestBuildComment/index.js b/.github/actions/javascript/postTestBuildComment/index.js index 2c0fa6726ede..b344ac60ca19 100644 --- a/.github/actions/javascript/postTestBuildComment/index.js +++ b/.github/actions/javascript/postTestBuildComment/index.js @@ -42,7 +42,12 @@ function getTestBuildMessage() { | ${androidQRCode} | ${iOSQRCode} | | Desktop :computer: | Web :spider_web: | | ${desktopLink} | ${webLink} | -| ${desktopQRCode} | ${webQRCode} |`; +| ${desktopQRCode} | ${webQRCode} | + +--- + +:eyes: [View the workflow run that generated this build](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}) :eyes: +`; return message; } diff --git a/.github/actions/javascript/postTestBuildComment/postTestBuildComment.js b/.github/actions/javascript/postTestBuildComment/postTestBuildComment.js index 4bb43f6e5900..48f0f39f16fe 100644 --- a/.github/actions/javascript/postTestBuildComment/postTestBuildComment.js +++ b/.github/actions/javascript/postTestBuildComment/postTestBuildComment.js @@ -33,7 +33,12 @@ function getTestBuildMessage() { | ${androidQRCode} | ${iOSQRCode} | | Desktop :computer: | Web :spider_web: | | ${desktopLink} | ${webLink} | -| ${desktopQRCode} | ${webQRCode} |`; +| ${desktopQRCode} | ${webQRCode} | + +--- + +:eyes: [View the workflow run that generated this build](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}) :eyes: +`; return message; } diff --git a/tests/unit/postTestBuildComment.js b/tests/unit/postTestBuildComment.js index fb1d1572dc34..a64f03389052 100644 --- a/tests/unit/postTestBuildComment.js +++ b/tests/unit/postTestBuildComment.js @@ -9,8 +9,10 @@ const mockCreateComment = jest.fn(); jest.mock('@actions/github', () => ({ context: { repo: { - repo: 'repo', + owner: 'Expensify', + repo: 'App', }, + runId: 1234, }, })); @@ -33,7 +35,12 @@ const message = `:test_tube::test_tube: Use the links below to test this adhoc b | ${androidQRCode} | ${iOSQRCode} | | Desktop :computer: | Web :spider_web: | | ${desktopLink} | ${webLink} | -| ${desktopQRCode} | ${webQRCode} |`; +| ${desktopQRCode} | ${webQRCode} | + +--- + +:eyes: [View the workflow run that generated this build](https://github.com/Expensify/App/actions/runs/1234) :eyes: +`; describe('Post test build comments action tests', () => { beforeAll(() => { @@ -55,6 +62,6 @@ describe('Post test build comments action tests', () => { GithubUtils.createComment.mockResolvedValue(true); ghAction(); expect(GithubUtils.createComment).toBeCalledTimes(1); - expect(GithubUtils.createComment).toBeCalledWith('repo', 12, message); + expect(GithubUtils.createComment).toBeCalledWith('App', 12, message); }); }); From fd0b3062a4f88a7eafca82a2629b8efbc446c912 Mon Sep 17 00:00:00 2001 From: rory Date: Fri, 1 Dec 2023 10:41:41 -0800 Subject: [PATCH 3/5] Update workflow_tests --- .../assertions/platformDeployAssertions.js | 5 +++-- .../assertions/testBuildAssertions.js | 20 +++++++++++-------- workflow_tests/mocks/platformDeployMocks.js | 5 +++-- workflow_tests/mocks/testBuildMocks.js | 8 ++++---- workflow_tests/testBuild.test.js | 2 +- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/workflow_tests/assertions/platformDeployAssertions.js b/workflow_tests/assertions/platformDeployAssertions.js index 458899581687..3aa00da33cf5 100644 --- a/workflow_tests/assertions/platformDeployAssertions.js +++ b/workflow_tests/assertions/platformDeployAssertions.js @@ -243,8 +243,9 @@ const assertWebJobExecuted = (workflowResult, didExecute = true, isProduction = utils.createStepAssertion('Setup Node', true, null, 'WEB', 'Setting up Node'), utils.createStepAssertion('Setup Cloudflare CLI', true, null, 'WEB', 'Setting up Cloudflare CLI'), utils.createStepAssertion('Configure AWS Credentials', true, null, 'WEB', 'Configuring AWS credentials', [ - {key: 'AWS_ACCESS_KEY_ID', value: '***'}, - {key: 'AWS_SECRET_ACCESS_KEY', value: '***'}, + {key: 'aws-access-key-id', value: '***'}, + {key: 'aws-secret-access-key', value: '***'}, + {key: 'aws-region', value: 'us-east-1'}, ]), ]; if (isProduction) { diff --git a/workflow_tests/assertions/testBuildAssertions.js b/workflow_tests/assertions/testBuildAssertions.js index 781e6bac20a2..17cb671492a7 100644 --- a/workflow_tests/assertions/testBuildAssertions.js +++ b/workflow_tests/assertions/testBuildAssertions.js @@ -93,8 +93,9 @@ const assertAndroidJobExecuted = (workflowResult, ref = '', didExecute = true, f 'ANDROID', 'Configure AWS Credentials', [ - {key: 'AWS_ACCESS_KEY_ID', value: '***'}, - {key: 'AWS_SECRET_ACCESS_KEY', value: '***'}, + {key: 'aws-access-key-id', value: '***'}, + {key: 'aws-secret-access-key', value: '***'}, + {key: 'aws-region', value: 'us-east-1'}, ], [], ), @@ -194,8 +195,9 @@ const assertIOSJobExecuted = (workflowResult, ref = '', didExecute = true, fails 'IOS', 'Configure AWS Credentials', [ - {key: 'AWS_ACCESS_KEY_ID', value: '***'}, - {key: 'AWS_SECRET_ACCESS_KEY', value: '***'}, + {key: 'aws-access-key-id', value: '***'}, + {key: 'aws-secret-access-key', value: '***'}, + {key: 'aws-region', value: 'us-east-1'}, ], [], ), @@ -266,8 +268,9 @@ const assertDesktopJobExecuted = (workflowResult, ref = '', didExecute = true, f 'DESKTOP', 'Configure AWS Credentials', [ - {key: 'AWS_ACCESS_KEY_ID', value: '***'}, - {key: 'AWS_SECRET_ACCESS_KEY', value: '***'}, + {key: 'aws-access-key-id', value: '***'}, + {key: 'aws-secret-access-key', value: '***'}, + {key: 'aws-region', value: 'us-east-1'}, ], [], ), @@ -319,8 +322,9 @@ const assertWebJobExecuted = (workflowResult, ref = '', didExecute = true, fails 'WEB', 'Configure AWS Credentials', [ - {key: 'AWS_ACCESS_KEY_ID', value: '***'}, - {key: 'AWS_SECRET_ACCESS_KEY', value: '***'}, + {key: 'aws-access-key-id', value: '***'}, + {key: 'aws-secret-access-key', value: '***'}, + {key: 'aws-region', value: 'us-east-1'}, ], [], ), diff --git a/workflow_tests/mocks/platformDeployMocks.js b/workflow_tests/mocks/platformDeployMocks.js index 0d75a5fd74ee..3a5fe639952d 100644 --- a/workflow_tests/mocks/platformDeployMocks.js +++ b/workflow_tests/mocks/platformDeployMocks.js @@ -176,8 +176,9 @@ const PLATFORM_DEPLOY__WEB__CHECKOUT__STEP_MOCK = utils.createMockStep('Checkout const PLATFORM_DEPLOY__WEB__SETUP_NODE__STEP_MOCK = utils.createMockStep('Setup Node', 'Setting up Node', 'WEB'); const PLATFORM_DEPLOY__WEB__CLOUDFLARE__STEP_MOCK = utils.createMockStep('Setup Cloudflare CLI', 'Setting up Cloudflare CLI', 'WEB'); const PLATFORM_DEPLOY__WEB__AWS_CREDENTIALS__STEP_MOCK = utils.createMockStep('Configure AWS Credentials', 'Configuring AWS credentials', 'WEB', [ - 'AWS_ACCESS_KEY_ID', - 'AWS_SECRET_ACCESS_KEY', + 'aws-access-key-id', + 'aws-secret-access-key', + 'aws-region', ]); const PLATFORM_DEPLOY__WEB__BUILD_PRODUCTION__STEP_MOCK = utils.createMockStep('Build web for production', 'Building web for production', 'WEB'); const PLATFORM_DEPLOY__WEB__BUILD_STAGING__STEP_MOCK = utils.createMockStep('Build web for staging', 'Building web for staging', 'WEB'); diff --git a/workflow_tests/mocks/testBuildMocks.js b/workflow_tests/mocks/testBuildMocks.js index d7ae9abdb8e7..b1999b0a6fb6 100644 --- a/workflow_tests/mocks/testBuildMocks.js +++ b/workflow_tests/mocks/testBuildMocks.js @@ -70,7 +70,7 @@ const TESTBUILD__ANDROID__CONFIGURE_AWS_CREDENTIALS__STEP_MOCK = utils.createMoc 'Configure AWS Credentials', 'Configure AWS Credentials', 'ANDROID', - ['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY'], + ['aws-access-key-id', 'aws-secret-access-key', 'aws-region'], [], ); const TESTBUILD__ANDROID__CONFIGURE_MAPBOX_SDK__STEP_MOCK = utils.createMockStep('Configure MapBox SDK', 'Configure MapBox SDK', 'ANDROID'); @@ -122,7 +122,7 @@ const TESTBUILD__IOS__CONFIGURE_AWS_CREDENTIALS__STEP_MOCK = utils.createMockSte 'Configure AWS Credentials', 'Configure AWS Credentials', 'IOS', - ['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY'], + ['aws-access-key-id', 'aws-secret-access-key', 'aws-region'], [], ); const TESTBUILD__IOS__RUN_FASTLANE__STEP_MOCK = utils.createMockStep('Run Fastlane', 'Run Fastlane', 'IOS', [], ['S3_ACCESS_KEY', 'S3_SECRET_ACCESS_KEY', 'S3_BUCKET', 'S3_REGION']); @@ -165,7 +165,7 @@ const TESTBUILD__DESKTOP__CONFIGURE_AWS_CREDENTIALS__STEP_MOCK = utils.createMoc 'Configure AWS Credentials', 'Configure AWS Credentials', 'DESKTOP', - ['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY'], + ['aws-access-key-id', 'aws-secret-access-key', 'aws-region'], [], ); const TESTBUILD__DESKTOP__BUILD_DESKTOP_APP_FOR_TESTING__STEP_MOCK = utils.createMockStep( @@ -198,7 +198,7 @@ const TESTBUILD__WEB__CONFIGURE_AWS_CREDENTIALS__STEP_MOCK = utils.createMockSte 'Configure AWS Credentials', 'Configure AWS Credentials', 'WEB', - ['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY'], + ['aws-access-key-id', 'aws-secret-access-key', 'aws-region'], [], ); const TESTBUILD__WEB__BUILD_WEB_FOR_TESTING__STEP_MOCK = utils.createMockStep('Build web for testing', 'Build web for testing', 'WEB', [], []); diff --git a/workflow_tests/testBuild.test.js b/workflow_tests/testBuild.test.js index f50032f0c54a..371759607ed5 100644 --- a/workflow_tests/testBuild.test.js +++ b/workflow_tests/testBuild.test.js @@ -313,7 +313,7 @@ describe('test workflow testBuild', () => { 'Configure AWS Credentials', 'Configure AWS Credentials', 'WEB', - ['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY'], + ['aws-access-key-id', 'aws-secret-access-key', 'aws-region'], [], {}, {}, From 2db492d3af6515152fe13e110e76d778addfd2ee Mon Sep 17 00:00:00 2001 From: rory Date: Fri, 1 Dec 2023 12:25:26 -0800 Subject: [PATCH 4/5] Remove community maintain-one-comment action --- .../postTestBuildComment.js | 46 +++++++++++++++---- .github/libs/GithubUtils.js | 14 ++++++ .github/workflows/testBuild.yml | 12 +---- tests/unit/postTestBuildComment.js | 31 ++++++++++++- .../assertions/testBuildAssertions.js | 14 ------ workflow_tests/mocks/testBuildMocks.js | 8 ---- 6 files changed, 80 insertions(+), 45 deletions(-) diff --git a/.github/actions/javascript/postTestBuildComment/postTestBuildComment.js b/.github/actions/javascript/postTestBuildComment/postTestBuildComment.js index 48f0f39f16fe..35bb44428fdf 100644 --- a/.github/actions/javascript/postTestBuildComment/postTestBuildComment.js +++ b/.github/actions/javascript/postTestBuildComment/postTestBuildComment.js @@ -1,5 +1,7 @@ +const _ = require('underscore'); const core = require('@actions/core'); const {context} = require('@actions/github'); +const CONST = require('../../../libs/CONST'); const GithubUtils = require('../../../libs/GithubUtils'); /** @@ -50,20 +52,44 @@ function getTestBuildMessage() { * @param {String} message * @returns {Promise} */ -function commentPR(PR, message) { +async function commentPR(PR, message) { console.log(`Posting test build comment on #${PR}`); - return GithubUtils.createComment(context.repo.repo, PR, message) - .then(() => console.log(`Comment created on #${PR} successfully 🎉`)) - .catch((err) => { - console.log(`Unable to write comment on #${PR} 😞`); - core.setFailed(err.message); - }); + try { + await GithubUtils.createComment(context.repo.repo, PR, message); + console.log(`Comment created on #${PR} successfully 🎉`); + } catch (err) { + console.log(`Unable to write comment on #${PR} 😞`); + core.setFailed(err.message); + } } -const run = function () { +async function run() { const PR_NUMBER = core.getInput('PR_NUMBER', {required: true}); - return commentPR(PR_NUMBER, getTestBuildMessage()).then(() => Promise.resolve()); -}; + const comments = await GithubUtils.paginate( + GithubUtils.octokit.issues.listComments, + { + owner: CONST.GITHUB_OWNER, + repo: CONST.APP_REPO, + issue_number: PR_NUMBER, + per_page: 100, + }, + (response) => response.data, + ); + const testBuildComment = _.find(comments, (comment) => comment.body.startsWith(':test_tube::test_tube: Use the links below to test this adhoc build')); + if (testBuildComment) { + console.log('Found previous build comment, hiding it', testBuildComment); + await GithubUtils.graphql(` + mutation { + minimizeComment(input: {classifier: OUTDATED, subjectId: "${testBuildComment.node_id}"}) { + minimizedComment { + minimizedReason + } + } + } + `); + } + await commentPR(PR_NUMBER, getTestBuildMessage()); +} if (require.main === module) { run(); diff --git a/.github/libs/GithubUtils.js b/.github/libs/GithubUtils.js index 1381d694f000..787fc604c3cc 100644 --- a/.github/libs/GithubUtils.js +++ b/.github/libs/GithubUtils.js @@ -66,6 +66,20 @@ class GithubUtils { return this.internalOctokit.rest; } + /** + * Get the graphql instance from internal octokit. + * @readonly + * @static + * @memberof GithubUtils + */ + static get graphql() { + if (this.internalOctokit) { + return this.internalOctokit.graphql; + } + this.initOctokit(); + return this.internalOctokit.graphql; + } + /** * Either give an existing instance of Octokit paginate or create a new one * diff --git a/.github/workflows/testBuild.yml b/.github/workflows/testBuild.yml index e2ea29b5210b..196d7115bfc4 100644 --- a/.github/workflows/testBuild.yml +++ b/.github/workflows/testBuild.yml @@ -341,22 +341,12 @@ jobs: ios_path=$(echo "$content_ios" | jq -r '.html_path') echo "ios_path=$ios_path" >> "$GITHUB_OUTPUT" - # This step removes previous comments with links connected to the PR - - name: maintain-comment - uses: actions-cool/maintain-one-comment@de04bd2a3750d86b324829a3ff34d47e48e16f4b - if: ${{ fromJSON(needs.validateActor.outputs.READY_TO_BUILD) }} - with: - token: ${{ secrets.OS_BOTIFY_TOKEN }} - body-include: 'Use the links below to test this adhoc build in Android, iOS, Desktop, and Web. Happy testing!' - number: ${{ github.event.number || github.event.inputs.PULL_REQUEST_NUMBER }} - delete: true - - name: Publish links to apps for download if: ${{ fromJSON(needs.validateActor.outputs.READY_TO_BUILD) }} uses: ./.github/actions/javascript/postTestBuildComment with: PR_NUMBER: ${{ env.PULL_REQUEST_NUMBER }} - GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }} + GITHUB_TOKEN: ${{ github.token }} ANDROID: ${{ needs.android.result }} DESKTOP: ${{ needs.desktop.result }} IOS: ${{ needs.iOS.result }} diff --git a/tests/unit/postTestBuildComment.js b/tests/unit/postTestBuildComment.js index a64f03389052..50389808b77d 100644 --- a/tests/unit/postTestBuildComment.js +++ b/tests/unit/postTestBuildComment.js @@ -5,6 +5,15 @@ const GithubUtils = require('../../.github/libs/GithubUtils'); const mockGetInput = jest.fn(); const mockCreateComment = jest.fn(); +const mockListComments = jest.fn(); +const mockGraphql = jest.fn(); +jest.spyOn(GithubUtils, 'octokit', 'get').mockReturnValue({ + issues: { + listComments: mockListComments, + }, +}); +jest.spyOn(GithubUtils, 'paginate', 'get').mockReturnValue((endpoint, params) => endpoint(params).then(({data}) => data)); +jest.spyOn(GithubUtils, 'graphql', 'get').mockReturnValue(mockGraphql); jest.mock('@actions/github', () => ({ context: { @@ -49,7 +58,7 @@ describe('Post test build comments action tests', () => { GithubUtils.createComment = mockCreateComment; }); - test('Test GH action', () => { + test('Test GH action', async () => { when(core.getInput).calledWith('PR_NUMBER', {required: true}).mockReturnValue(12); when(core.getInput).calledWith('ANDROID', {required: true}).mockReturnValue('success'); when(core.getInput).calledWith('IOS', {required: true}).mockReturnValue('success'); @@ -60,7 +69,25 @@ describe('Post test build comments action tests', () => { when(core.getInput).calledWith('WEB_LINK').mockReturnValue('https://expensify.app/WEB_LINK'); when(core.getInput).calledWith('DESKTOP_LINK').mockReturnValue('https://expensify.app/DESKTOP_LINK'); GithubUtils.createComment.mockResolvedValue(true); - ghAction(); + mockListComments.mockResolvedValue({ + data: [ + { + body: ':test_tube::test_tube: Use the links below to test this adhoc build on Android, iOS, Desktop, and Web. Happy testing!', + node_id: 'IC_abcd', + }, + ], + }); + await ghAction(); + expect(mockGraphql).toBeCalledTimes(1); + expect(mockGraphql).toBeCalledWith(` + mutation { + minimizeComment(input: {classifier: OUTDATED, subjectId: "IC_abcd"}) { + minimizedComment { + minimizedReason + } + } + } + `); expect(GithubUtils.createComment).toBeCalledTimes(1); expect(GithubUtils.createComment).toBeCalledWith('App', 12, message); }); diff --git a/workflow_tests/assertions/testBuildAssertions.js b/workflow_tests/assertions/testBuildAssertions.js index 17cb671492a7..06f8ae617509 100644 --- a/workflow_tests/assertions/testBuildAssertions.js +++ b/workflow_tests/assertions/testBuildAssertions.js @@ -373,20 +373,6 @@ const assertPostGithubCommentJobExecuted = ( steps.push(utils.createStepAssertion('Read JSONs with iOS paths', true, null, 'POSTGITHUBCOMMENT', 'Read JSONs with iOS paths', [], [])); } steps.push( - utils.createStepAssertion( - 'maintain-comment', - true, - null, - 'POSTGITHUBCOMMENT', - 'maintain-comment', - [ - {key: 'token', value: '***'}, - {key: 'body-include', value: 'Use the links below to test this adhoc build in Android, iOS, Desktop, and Web. Happy testing!'}, - {key: 'number', value: pullRequestNumber}, - {key: 'delete', value: true}, - ], - [], - ), utils.createStepAssertion( 'Publish links to apps for download', true, diff --git a/workflow_tests/mocks/testBuildMocks.js b/workflow_tests/mocks/testBuildMocks.js index b1999b0a6fb6..270f8b5d8a06 100644 --- a/workflow_tests/mocks/testBuildMocks.js +++ b/workflow_tests/mocks/testBuildMocks.js @@ -228,13 +228,6 @@ const TESTBUILD__POSTGITHUBCOMMENT__READ_JSONS_WITH_ANDROID_PATHS__STEP_MOCK = u const TESTBUILD__POSTGITHUBCOMMENT__READ_JSONS_WITH_IOS_PATHS__STEP_MOCK = utils.createMockStep('Read JSONs with iOS paths', 'Read JSONs with iOS paths', 'POSTGITHUBCOMMENT', [], [], { ios_path: 'http://dummy.ios.link', }); -const TESTBUILD__POSTGITHUBCOMMENT__MAINTAIN_COMMENT__STEP_MOCK = utils.createMockStep( - 'maintain-comment', - 'maintain-comment', - 'POSTGITHUBCOMMENT', - ['token', 'body-include', 'number', 'delete'], - [], -); const TESTBUILD__POSTGITHUBCOMMENT__PUBLISH_LINKS_TO_APPS_FOR_DOWNLOAD__STEP_MOCK = utils.createMockStep( 'Publish links to apps for download', 'Publish links to apps for download', @@ -247,7 +240,6 @@ const TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS = [ TESTBUILD__POSTGITHUBCOMMENT__DOWNLOAD_ARTIFACT__STEP_MOCK, TESTBUILD__POSTGITHUBCOMMENT__READ_JSONS_WITH_ANDROID_PATHS__STEP_MOCK, TESTBUILD__POSTGITHUBCOMMENT__READ_JSONS_WITH_IOS_PATHS__STEP_MOCK, - TESTBUILD__POSTGITHUBCOMMENT__MAINTAIN_COMMENT__STEP_MOCK, TESTBUILD__POSTGITHUBCOMMENT__PUBLISH_LINKS_TO_APPS_FOR_DOWNLOAD__STEP_MOCK, ]; From de167c72493968340c430f27a39d8625e714a7fe Mon Sep 17 00:00:00 2001 From: rory Date: Fri, 22 Dec 2023 15:39:33 -0800 Subject: [PATCH 5/5] Rebuild gh actions --- .../javascript/authorChecklist/index.js | 14 +++++ .../javascript/awaitStagingDeploys/index.js | 14 +++++ .../javascript/checkDeployBlockers/index.js | 14 +++++ .../createOrUpdateStagingDeploy/index.js | 14 +++++ .../getDeployPullRequestList/index.js | 14 +++++ .../javascript/getPullRequestDetails/index.js | 14 +++++ .../javascript/getReleaseBody/index.js | 14 +++++ .../javascript/isStagingDeployLocked/index.js | 14 +++++ .../markPullRequestsAsDeployed/index.js | 14 +++++ .../javascript/postTestBuildComment/index.js | 60 +++++++++++++++---- .../reopenIssueWithComment/index.js | 14 +++++ .../javascript/reviewerChecklist/index.js | 14 +++++ .../javascript/verifySignedCommits/index.js | 14 +++++ 13 files changed, 218 insertions(+), 10 deletions(-) diff --git a/.github/actions/javascript/authorChecklist/index.js b/.github/actions/javascript/authorChecklist/index.js index bdb2b5b329d1..44d3f203f786 100644 --- a/.github/actions/javascript/authorChecklist/index.js +++ b/.github/actions/javascript/authorChecklist/index.js @@ -99,6 +99,20 @@ class GithubUtils { return this.internalOctokit.rest; } + /** + * Get the graphql instance from internal octokit. + * @readonly + * @static + * @memberof GithubUtils + */ + static get graphql() { + if (this.internalOctokit) { + return this.internalOctokit.graphql; + } + this.initOctokit(); + return this.internalOctokit.graphql; + } + /** * Either give an existing instance of Octokit paginate or create a new one * diff --git a/.github/actions/javascript/awaitStagingDeploys/index.js b/.github/actions/javascript/awaitStagingDeploys/index.js index 08468d9a06a5..82f6b770624b 100644 --- a/.github/actions/javascript/awaitStagingDeploys/index.js +++ b/.github/actions/javascript/awaitStagingDeploys/index.js @@ -211,6 +211,20 @@ class GithubUtils { return this.internalOctokit.rest; } + /** + * Get the graphql instance from internal octokit. + * @readonly + * @static + * @memberof GithubUtils + */ + static get graphql() { + if (this.internalOctokit) { + return this.internalOctokit.graphql; + } + this.initOctokit(); + return this.internalOctokit.graphql; + } + /** * Either give an existing instance of Octokit paginate or create a new one * diff --git a/.github/actions/javascript/checkDeployBlockers/index.js b/.github/actions/javascript/checkDeployBlockers/index.js index 690018aa9367..60a90dda631b 100644 --- a/.github/actions/javascript/checkDeployBlockers/index.js +++ b/.github/actions/javascript/checkDeployBlockers/index.js @@ -178,6 +178,20 @@ class GithubUtils { return this.internalOctokit.rest; } + /** + * Get the graphql instance from internal octokit. + * @readonly + * @static + * @memberof GithubUtils + */ + static get graphql() { + if (this.internalOctokit) { + return this.internalOctokit.graphql; + } + this.initOctokit(); + return this.internalOctokit.graphql; + } + /** * Either give an existing instance of Octokit paginate or create a new one * diff --git a/.github/actions/javascript/createOrUpdateStagingDeploy/index.js b/.github/actions/javascript/createOrUpdateStagingDeploy/index.js index bf8214759c12..3882af322d64 100644 --- a/.github/actions/javascript/createOrUpdateStagingDeploy/index.js +++ b/.github/actions/javascript/createOrUpdateStagingDeploy/index.js @@ -407,6 +407,20 @@ class GithubUtils { return this.internalOctokit.rest; } + /** + * Get the graphql instance from internal octokit. + * @readonly + * @static + * @memberof GithubUtils + */ + static get graphql() { + if (this.internalOctokit) { + return this.internalOctokit.graphql; + } + this.initOctokit(); + return this.internalOctokit.graphql; + } + /** * Either give an existing instance of Octokit paginate or create a new one * diff --git a/.github/actions/javascript/getDeployPullRequestList/index.js b/.github/actions/javascript/getDeployPullRequestList/index.js index 974824ac4628..741cf116323f 100644 --- a/.github/actions/javascript/getDeployPullRequestList/index.js +++ b/.github/actions/javascript/getDeployPullRequestList/index.js @@ -350,6 +350,20 @@ class GithubUtils { return this.internalOctokit.rest; } + /** + * Get the graphql instance from internal octokit. + * @readonly + * @static + * @memberof GithubUtils + */ + static get graphql() { + if (this.internalOctokit) { + return this.internalOctokit.graphql; + } + this.initOctokit(); + return this.internalOctokit.graphql; + } + /** * Either give an existing instance of Octokit paginate or create a new one * diff --git a/.github/actions/javascript/getPullRequestDetails/index.js b/.github/actions/javascript/getPullRequestDetails/index.js index 3c5bd277a60e..2ce37bdb0d0e 100644 --- a/.github/actions/javascript/getPullRequestDetails/index.js +++ b/.github/actions/javascript/getPullRequestDetails/index.js @@ -145,6 +145,20 @@ class GithubUtils { return this.internalOctokit.rest; } + /** + * Get the graphql instance from internal octokit. + * @readonly + * @static + * @memberof GithubUtils + */ + static get graphql() { + if (this.internalOctokit) { + return this.internalOctokit.graphql; + } + this.initOctokit(); + return this.internalOctokit.graphql; + } + /** * Either give an existing instance of Octokit paginate or create a new one * diff --git a/.github/actions/javascript/getReleaseBody/index.js b/.github/actions/javascript/getReleaseBody/index.js index 9ae04c4ef02a..3656d637370b 100644 --- a/.github/actions/javascript/getReleaseBody/index.js +++ b/.github/actions/javascript/getReleaseBody/index.js @@ -145,6 +145,20 @@ class GithubUtils { return this.internalOctokit.rest; } + /** + * Get the graphql instance from internal octokit. + * @readonly + * @static + * @memberof GithubUtils + */ + static get graphql() { + if (this.internalOctokit) { + return this.internalOctokit.graphql; + } + this.initOctokit(); + return this.internalOctokit.graphql; + } + /** * Either give an existing instance of Octokit paginate or create a new one * diff --git a/.github/actions/javascript/isStagingDeployLocked/index.js b/.github/actions/javascript/isStagingDeployLocked/index.js index fb4cdc1afd40..d7bf3f1a784b 100644 --- a/.github/actions/javascript/isStagingDeployLocked/index.js +++ b/.github/actions/javascript/isStagingDeployLocked/index.js @@ -129,6 +129,20 @@ class GithubUtils { return this.internalOctokit.rest; } + /** + * Get the graphql instance from internal octokit. + * @readonly + * @static + * @memberof GithubUtils + */ + static get graphql() { + if (this.internalOctokit) { + return this.internalOctokit.graphql; + } + this.initOctokit(); + return this.internalOctokit.graphql; + } + /** * Either give an existing instance of Octokit paginate or create a new one * diff --git a/.github/actions/javascript/markPullRequestsAsDeployed/index.js b/.github/actions/javascript/markPullRequestsAsDeployed/index.js index 73a51b622759..3c3f2ed6552f 100644 --- a/.github/actions/javascript/markPullRequestsAsDeployed/index.js +++ b/.github/actions/javascript/markPullRequestsAsDeployed/index.js @@ -294,6 +294,20 @@ class GithubUtils { return this.internalOctokit.rest; } + /** + * Get the graphql instance from internal octokit. + * @readonly + * @static + * @memberof GithubUtils + */ + static get graphql() { + if (this.internalOctokit) { + return this.internalOctokit.graphql; + } + this.initOctokit(); + return this.internalOctokit.graphql; + } + /** * Either give an existing instance of Octokit paginate or create a new one * diff --git a/.github/actions/javascript/postTestBuildComment/index.js b/.github/actions/javascript/postTestBuildComment/index.js index b344ac60ca19..65c45d744c57 100644 --- a/.github/actions/javascript/postTestBuildComment/index.js +++ b/.github/actions/javascript/postTestBuildComment/index.js @@ -7,8 +7,10 @@ /***/ 2052: /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { +const _ = __nccwpck_require__(5067); const core = __nccwpck_require__(2186); const {context} = __nccwpck_require__(5438); +const CONST = __nccwpck_require__(4097); const GithubUtils = __nccwpck_require__(7999); /** @@ -59,20 +61,44 @@ function getTestBuildMessage() { * @param {String} message * @returns {Promise} */ -function commentPR(PR, message) { +async function commentPR(PR, message) { console.log(`Posting test build comment on #${PR}`); - return GithubUtils.createComment(context.repo.repo, PR, message) - .then(() => console.log(`Comment created on #${PR} successfully 🎉`)) - .catch((err) => { - console.log(`Unable to write comment on #${PR} 😞`); - core.setFailed(err.message); - }); + try { + await GithubUtils.createComment(context.repo.repo, PR, message); + console.log(`Comment created on #${PR} successfully 🎉`); + } catch (err) { + console.log(`Unable to write comment on #${PR} 😞`); + core.setFailed(err.message); + } } -const run = function () { +async function run() { const PR_NUMBER = core.getInput('PR_NUMBER', {required: true}); - return commentPR(PR_NUMBER, getTestBuildMessage()).then(() => Promise.resolve()); -}; + const comments = await GithubUtils.paginate( + GithubUtils.octokit.issues.listComments, + { + owner: CONST.GITHUB_OWNER, + repo: CONST.APP_REPO, + issue_number: PR_NUMBER, + per_page: 100, + }, + (response) => response.data, + ); + const testBuildComment = _.find(comments, (comment) => comment.body.startsWith(':test_tube::test_tube: Use the links below to test this adhoc build')); + if (testBuildComment) { + console.log('Found previous build comment, hiding it', testBuildComment); + await GithubUtils.graphql(` + mutation { + minimizeComment(input: {classifier: OUTDATED, subjectId: "${testBuildComment.node_id}"}) { + minimizedComment { + minimizedReason + } + } + } + `); + } + await commentPR(PR_NUMBER, getTestBuildMessage()); +} if (require.main === require.cache[eval('__filename')]) { run(); @@ -178,6 +204,20 @@ class GithubUtils { return this.internalOctokit.rest; } + /** + * Get the graphql instance from internal octokit. + * @readonly + * @static + * @memberof GithubUtils + */ + static get graphql() { + if (this.internalOctokit) { + return this.internalOctokit.graphql; + } + this.initOctokit(); + return this.internalOctokit.graphql; + } + /** * Either give an existing instance of Octokit paginate or create a new one * diff --git a/.github/actions/javascript/reopenIssueWithComment/index.js b/.github/actions/javascript/reopenIssueWithComment/index.js index 39906af7bd05..c7c3b0d23881 100644 --- a/.github/actions/javascript/reopenIssueWithComment/index.js +++ b/.github/actions/javascript/reopenIssueWithComment/index.js @@ -99,6 +99,20 @@ class GithubUtils { return this.internalOctokit.rest; } + /** + * Get the graphql instance from internal octokit. + * @readonly + * @static + * @memberof GithubUtils + */ + static get graphql() { + if (this.internalOctokit) { + return this.internalOctokit.graphql; + } + this.initOctokit(); + return this.internalOctokit.graphql; + } + /** * Either give an existing instance of Octokit paginate or create a new one * diff --git a/.github/actions/javascript/reviewerChecklist/index.js b/.github/actions/javascript/reviewerChecklist/index.js index aebf5205feab..abebb67e8173 100644 --- a/.github/actions/javascript/reviewerChecklist/index.js +++ b/.github/actions/javascript/reviewerChecklist/index.js @@ -99,6 +99,20 @@ class GithubUtils { return this.internalOctokit.rest; } + /** + * Get the graphql instance from internal octokit. + * @readonly + * @static + * @memberof GithubUtils + */ + static get graphql() { + if (this.internalOctokit) { + return this.internalOctokit.graphql; + } + this.initOctokit(); + return this.internalOctokit.graphql; + } + /** * Either give an existing instance of Octokit paginate or create a new one * diff --git a/.github/actions/javascript/verifySignedCommits/index.js b/.github/actions/javascript/verifySignedCommits/index.js index 7f08a5f95790..d4dc6d41f1dc 100644 --- a/.github/actions/javascript/verifySignedCommits/index.js +++ b/.github/actions/javascript/verifySignedCommits/index.js @@ -99,6 +99,20 @@ class GithubUtils { return this.internalOctokit.rest; } + /** + * Get the graphql instance from internal octokit. + * @readonly + * @static + * @memberof GithubUtils + */ + static get graphql() { + if (this.internalOctokit) { + return this.internalOctokit.graphql; + } + this.initOctokit(); + return this.internalOctokit.graphql; + } + /** * Either give an existing instance of Octokit paginate or create a new one *