diff --git a/.github/workflows/pr-automation.yml b/.github/workflows/pr-automation.yml index aaacb5c7a1..1475cf7a9e 100644 --- a/.github/workflows/pr-automation.yml +++ b/.github/workflows/pr-automation.yml @@ -171,22 +171,19 @@ jobs: # In case of a runnable command, update the PR with run details - name: Add test response with link to workflow run - uses: nefrob/pr-description@v1.1.2 + uses: actions/github-script@v7 + env: + NODE_PATH: "${{ github.workspace }}/.github/workflows/scripts" + BODY: | + > [!IMPORTANT] + > 🟣 🟣 🟣 Your tests are running. + > Tests running at: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}> + > Commit: ${{ github.event.pull_request.head.sha }} + > Workflow: `${{ github.workflow }}` + > Tags: `${{ steps.checkAll.outputs.tags }}` with: - content: | - - > [!IMPORTANT] - > 🟣 🟣 🟣 Your tests are running. - > Tests running at: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}> - > Commit: ${{ github.event.pull_request.head.sha }} - > Workflow: `${{ github.workflow }}` - > Tags: `${{ steps.checkAll.outputs.tags }}` - - - - regex: ".*?" - regexFlags: ims - token: ${{ secrets.GITHUB_TOKEN }} + script: | + require("write-cypress-comment.js")({core, context, github}, process.env.BODY) # Call the workflow to run Cypress tests perform-test: diff --git a/.github/workflows/scripts/write-cypress-comment.js b/.github/workflows/scripts/write-cypress-comment.js new file mode 100644 index 0000000000..cf27fc895f --- /dev/null +++ b/.github/workflows/scripts/write-cypress-comment.js @@ -0,0 +1,39 @@ +const HEADER = ''; +const FOOTER = ''; +const PATTERN = new RegExp(HEADER + ".*?" + FOOTER, "ims"); + +module.exports = async function({core, context, github}, note) { + const prNumber = context.payload.pull_request?.number; + + if (!prNumber) { + core.setFailed( + `No open pull request found for ${context.eventName}, ${context.sha}`, + ); + return; + } + + const response = await github.rest.pulls.get({ + ...context.repo, + pull_number: prNumber, + }); + + let body = response?.data?.body; + if (!body) { + core.setFailed(JSON.stringify(response, null, 2)); + return; + } + + note = [HEADER, note, FOOTER].join("\n"); + + if (body.match(PATTERN)) { + body = body.replace(PATTERN, note); + } else { + body += "\n\n" + note + "\n"; + } + + await github.rest.pulls.update({ + ...context.repo, + pull_number: prNumber, + body, + }); +}