From 073b6a0e4e290aee5397296c88d775d5f11c4ed1 Mon Sep 17 00:00:00 2001 From: Devon Powell Date: Wed, 27 Nov 2024 13:02:13 -0500 Subject: [PATCH] Don't open a PR for bot related changes, just push --- .github/workflows/ci.yml | 51 +++++++++++++++++++++++++++++++++++----- src/report.js | 13 ++++------ 2 files changed, 50 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6c13b2e..b98eb8c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,6 +49,8 @@ jobs: steps: - name: Checkout uses: Brightspace/third-party-actions@actions/checkout + with: + token: ${{github.actor == 'd2l-github-action-tokens[bot]' && secrets.PR_MANAGE_TOKEN || github.token}} - name: Set up node uses: Brightspace/third-party-actions@actions/setup-node with: @@ -58,9 +60,10 @@ jobs: run: npm ci - name: Build run: npm run build - - name: Handle changes + - name: Handle changes (pull request) uses: Brightspace/third-party-actions@peter-evans/create-pull-request - id: changes + if: github.actor != 'd2l-github-action-tokens[bot]' + id: changes-pr with: commit-message: Update Build base: ${{github.event.pull_request.head.ref}} @@ -71,21 +74,57 @@ jobs: draft: true add-paths: dist/* - name: Leave comment - if: steps.changes.outputs.pull-request-operation == 'created' + if: > + github.actor != 'd2l-github-action-tokens[bot]' && + steps.changes-pr.outputs.pull-request-operation == 'created' uses: BrightspaceUI/actions/comment-on-pr@main with: message: > New build required - pull request - #${{steps.changes.outputs.pull-request-number}} has been opened with + #${{steps.changes-pr.outputs.pull-request-number}} has been opened with new built files. post-mode: hide-previous - name: Report status if: > - steps.changes.outputs.pull-request-operation == 'created' || - steps.changes.outputs.pull-request-operation == 'updated' + github.actor != 'd2l-github-action-tokens[bot]' && + ( + steps.changes-pr.outputs.pull-request-operation == 'created' || + steps.changes-pr.outputs.pull-request-operation == 'updated' + ) uses: Brightspace/third-party-actions@actions/github-script with: script: core.setFailed('Build changes detected') + - name: Handle changes (push) + id: changes-push + if: github.actor == 'd2l-github-action-tokens[bot]' + run: | + set +e + git diff --exit-code --name-only 'dist/*' + RESULT="$?" + set -e + if [[ "$RESULT" -eq 0 ]]; then + echo "No changes detected" + echo "exist=false" >> $GITHUB_OUTPUT + exit 0 + fi + echo "exist=true" >> $GITHUB_OUTPUT + git stash + git fetch -n origin "$GITHUB_HEAD_REF" + git checkout "$GITHUB_HEAD_REF" + git stash pop + git add 'dist/*' + git config user.name github-actions[bot] + git config user.email 41898282+github-actions[bot]@users.noreply.github.com + git commit -m 'Update Build' + git push -f "https://$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY" "$GITHUB_HEAD_REF" + env: + GITHUB_TOKEN: ${{secrets.PR_MANAGE_TOKEN}} + - name: Approve + if: steps.changes-push.outputs.exist == 'true' + run: gh pr review --approve "$PULL_REQUEST_NUMBER" + env: + PULL_REQUEST_NUMBER: ${{github.event.number}} + GITHUB_TOKEN: ${{github.token}} test: name: Test timeout-minutes: 5 diff --git a/src/report.js b/src/report.js index f887c3d..24e0d5e 100644 --- a/src/report.js +++ b/src/report.js @@ -94,11 +94,8 @@ const makeDetailRecord = (detail) => { location, retries, timeout, - duration: { - total, - final - }, status, + duration: { total, final }, browser, type, experience, @@ -187,7 +184,7 @@ const makeDetailWriteRequests = (report) => { return writeRequests; }; -const assumeRole = async(region, credentials, arn, sessionName, duration, tags) => { +const assumeRole = async (region, credentials, arn, sessionName, duration, tags) => { const client = new STSClient({ region, credentials }); const command = new AssumeRoleCommand({ RoleArn: arn, @@ -205,7 +202,7 @@ const assumeRole = async(region, credentials, arn, sessionName, duration, tags) }; }; -const writeTimestream = async(region, credentials, requests) => { +const writeTimestream = async (region, credentials, requests) => { const client = new TimestreamWriteClient({ credentials, region }); for (const request of requests) { @@ -215,7 +212,7 @@ const writeTimestream = async(region, credentials, requests) => { } }; -const finalize = async(logger, context, inputs) => { +const finalize = async (logger, context, inputs) => { logger.startGroup('Finalize test report'); const { reportPath, injectGitHubContext, lmsBuildNumber, lmsInstanceUrl, debug } = inputs; @@ -273,7 +270,7 @@ const finalize = async(logger, context, inputs) => { return report; }; -const submit = async(logger, context, inputs, report) => { +const submit = async (logger, context, inputs, report) => { logger.startGroup('Submit report'); logger.info('Generate summary write request');