From f5e99bce7f3a13ac337114024dbd9021d3b91435 Mon Sep 17 00:00:00 2001 From: Sid Vishnoi <8426945+sidvishnoi@users.noreply.github.com> Date: Wed, 21 Aug 2024 16:31:09 +0530 Subject: [PATCH 01/11] Update .prettierignore --- .prettierignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.prettierignore b/.prettierignore index ab3fc7be..f8d0584d 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,6 +1,6 @@ public -generated dist +dev pnpm-lock.yaml *.svg .gitignore From 43099ba7f3f5325ac776319eeaaee7324ae34785 Mon Sep 17 00:00:00 2001 From: Sid Vishnoi <8426945+sidvishnoi@users.noreply.github.com> Date: Wed, 21 Aug 2024 16:42:07 +0530 Subject: [PATCH 02/11] Update pr-checks.yml --- .github/workflows/pr-checks.yml | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index ee81c342..adc33bfa 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -72,3 +72,38 @@ jobs: - name: Test run: pnpm test:ci + + comment: + name: Add comment with extension preview builds + runs-on: ubuntu-22.04 + needs: [build] + if: github.repository == 'interledger/web-monetization-extension' + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Get workflow artifacts + uses: actions/github-script@v7 + id: get-workflow-artifacts + with: + script: | + const script = require('./.github/actions/get-workflow-artifacts.cjs') + await script({ github, context, core }) + + - name: Find comment + if: ${{ steps.get-workflow-artifacts.outputs.conclusion != 'cancelled' }} + uses: peter-evans/find-comment@v3 + id: find-comment + with: + issue-number: ${{ steps.get-workflow-artifacts.outputs.pr_number }} + comment-author: 'github-actions[bot]' + body-includes: '' + + - name: Add/Update comment + if: ${{ steps.get-workflow-artifacts.outputs.conclusion != 'cancelled' }} + uses: peter-evans/create-or-update-comment@v4 + with: + comment-id: ${{ steps.find-comment.outputs.comment-id }} + issue-number: ${{ steps.get-workflow-artifacts.outputs.pr_number }} + body: ${{ steps.get-workflow-artifacts.outputs.comment_body }} + edit-mode: replace From bd851fa19ae773789ac2c005f46ccb38635bc4f1 Mon Sep 17 00:00:00 2001 From: Sid Vishnoi <8426945+sidvishnoi@users.noreply.github.com> Date: Wed, 21 Aug 2024 16:42:55 +0530 Subject: [PATCH 03/11] Delete .github/workflows/build-previews.yml --- .github/workflows/build-previews.yml | 43 ---------------------------- 1 file changed, 43 deletions(-) delete mode 100644 .github/workflows/build-previews.yml diff --git a/.github/workflows/build-previews.yml b/.github/workflows/build-previews.yml deleted file mode 100644 index 3212ca58..00000000 --- a/.github/workflows/build-previews.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: Build previews - -on: - workflow_run: - types: - - 'completed' - workflows: - - 'PR Checks' - -jobs: - comment: - name: Add comment with extension preview builds - runs-on: ubuntu-22.04 - if: github.repository == 'interledger/web-monetization-extension' - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Get workflow artifacts - uses: actions/github-script@v7 - id: get-workflow-artifacts - with: - script: | - const script = require('./.github/actions/get-workflow-artifacts.cjs') - await script({ github, context, core }) - - - name: Find comment - if: ${{ steps.get-workflow-artifacts.outputs.conclusion != 'cancelled' }} - uses: peter-evans/find-comment@v3 - id: find-comment - with: - issue-number: ${{ steps.get-workflow-artifacts.outputs.pr_number }} - comment-author: 'github-actions[bot]' - body-includes: '' - - - name: Add/Update comment - if: ${{ steps.get-workflow-artifacts.outputs.conclusion != 'cancelled' }} - uses: peter-evans/create-or-update-comment@v4 - with: - comment-id: ${{ steps.find-comment.outputs.comment-id }} - issue-number: ${{ steps.get-workflow-artifacts.outputs.pr_number }} - body: ${{ steps.get-workflow-artifacts.outputs.comment_body }} - edit-mode: replace From 7d4c3589ce7ad632a68cd5fd1c4090ed7d3ed4e5 Mon Sep 17 00:00:00 2001 From: Sid Vishnoi <8426945+sidvishnoi@users.noreply.github.com> Date: Wed, 21 Aug 2024 16:55:23 +0530 Subject: [PATCH 04/11] Update get-workflow-artifacts.cjs --- .github/actions/get-workflow-artifacts.cjs | 25 +++++++++------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/.github/actions/get-workflow-artifacts.cjs b/.github/actions/get-workflow-artifacts.cjs index 6c375e39..7c57daa6 100644 --- a/.github/actions/get-workflow-artifacts.cjs +++ b/.github/actions/get-workflow-artifacts.cjs @@ -47,14 +47,14 @@ function formatBytes(bytes, decimals = 2) { /** @param {import('github-script').AsyncFunctionArguments} AsyncFunctionArguments */ module.exports = async ({ github, context, core }) => { + console.log(JSON.stringify(context, null, 2)) + const { owner, repo } = context.repo const baseUrl = context.payload.repository?.html_url - const suiteId = context.payload.workflow_run.check_suite_id - const runId = context.payload.workflow_run.id - const conclusion = context.payload.workflow_run.conclusion - const sha = context.payload.workflow_run.pull_requests[0].head.sha - const prNumber = context.payload.workflow_run.pull_requests[0].number - const jobLogsUrl = `${baseUrl}/actions/runs/${context.payload.workflow_run.id}` + const runId = context.runId + const sha = context.sha + const prNumber = context.payload.pull_request?.number + const jobLogsUrl = `${baseUrl}/actions/runs/${runId}` const template = await fs.readFile( './.github/actions/templates/build-status.md', 'utf8' @@ -63,22 +63,17 @@ module.exports = async ({ github, context, core }) => { /** @type {string[]} */ const tableRows = [] - core.setOutput('conclusion', conclusion) - - if (conclusion === 'cancelled') { - return - } - const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ owner, repo, run_id: runId }) + console.log(JSON.stringify({ artifacts: artifacts.data.artifacts }, null, 2)) + artifacts.data.artifacts.forEach((artifact) => { const key = /** @type {Browser} */ (artifact.name.split('-')[1]) - ARTIFACTS_DATA[key].url = - `${baseUrl}/suites/${suiteId}/artifacts/${artifact.id}` + ARTIFACTS_DATA[key].url = `${jobLogsUrl}/artifacts/${artifact.id}` ARTIFACTS_DATA[key].size = formatBytes(artifact.size_in_bytes) }) @@ -99,7 +94,7 @@ module.exports = async ({ github, context, core }) => { const tableBody = tableRows.join('') const commentBody = template - .replace(TEMPLATE_VARS.conclusion, conclusion) + .replace(TEMPLATE_VARS.conclusion, 'success') .replace(TEMPLATE_VARS.sha, sha) .replace(TEMPLATE_VARS.jobLogs, `Run #${runId}`) .replace(TEMPLATE_VARS.tableBody, tableBody) From bc70d74626510232eef46516785067266c844cda Mon Sep 17 00:00:00 2001 From: Sid Vishnoi <8426945+sidvishnoi@users.noreply.github.com> Date: Wed, 21 Aug 2024 17:01:21 +0530 Subject: [PATCH 05/11] Update pr-checks.yml --- .github/workflows/pr-checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index adc33bfa..1a9e5dbf 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -1,7 +1,7 @@ name: PR Checks on: - pull_request: + pull_request_target: types: - opened - reopened From 9415b91ff38d15688eacf2c7fdf94f6c5c4011f7 Mon Sep 17 00:00:00 2001 From: Sid Vishnoi <8426945+sidvishnoi@users.noreply.github.com> Date: Wed, 21 Aug 2024 17:11:16 +0530 Subject: [PATCH 06/11] use PAT like before --- .github/workflows/pr-checks.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index 1a9e5dbf..337d0c91 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -1,7 +1,7 @@ name: PR Checks on: - pull_request_target: + pull_request: types: - opened - reopened @@ -96,13 +96,14 @@ jobs: id: find-comment with: issue-number: ${{ steps.get-workflow-artifacts.outputs.pr_number }} - comment-author: 'github-actions[bot]' + comment-author: 'raducristianpopa' body-includes: '' - name: Add/Update comment if: ${{ steps.get-workflow-artifacts.outputs.conclusion != 'cancelled' }} uses: peter-evans/create-or-update-comment@v4 with: + token: ${{ secrets.PAT }} comment-id: ${{ steps.find-comment.outputs.comment-id }} issue-number: ${{ steps.get-workflow-artifacts.outputs.pr_number }} body: ${{ steps.get-workflow-artifacts.outputs.comment_body }} From 68ed7ae44c1a1647321dd257a20b4093b8597a35 Mon Sep 17 00:00:00 2001 From: Sid Vishnoi <8426945+sidvishnoi@users.noreply.github.com> Date: Wed, 21 Aug 2024 17:13:44 +0530 Subject: [PATCH 07/11] Update pr-checks.yml --- .github/workflows/pr-checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index 337d0c91..12443a80 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -1,7 +1,7 @@ name: PR Checks on: - pull_request: + pull_request_target: types: - opened - reopened From df653b0f2c8fe263766d3d00feb1608819f16dc0 Mon Sep 17 00:00:00 2001 From: Sid Vishnoi <8426945+sidvishnoi@users.noreply.github.com> Date: Wed, 21 Aug 2024 17:16:17 +0530 Subject: [PATCH 08/11] Update pr-checks.yml --- .github/workflows/pr-checks.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index 12443a80..00618784 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -1,7 +1,7 @@ name: PR Checks on: - pull_request_target: + pull_request: types: - opened - reopened @@ -96,14 +96,14 @@ jobs: id: find-comment with: issue-number: ${{ steps.get-workflow-artifacts.outputs.pr_number }} - comment-author: 'raducristianpopa' + comment-author: 'github-actions[bot]' body-includes: '' - name: Add/Update comment if: ${{ steps.get-workflow-artifacts.outputs.conclusion != 'cancelled' }} uses: peter-evans/create-or-update-comment@v4 with: - token: ${{ secrets.PAT }} + token: ${{ secrets.GITHUB_TOKEN }} comment-id: ${{ steps.find-comment.outputs.comment-id }} issue-number: ${{ steps.get-workflow-artifacts.outputs.pr_number }} body: ${{ steps.get-workflow-artifacts.outputs.comment_body }} From 4a37000e262fda2c33c2c9ce50b48b83d76cee2a Mon Sep 17 00:00:00 2001 From: Sid Vishnoi <8426945+sidvishnoi@users.noreply.github.com> Date: Wed, 21 Aug 2024 17:17:39 +0530 Subject: [PATCH 09/11] add permssions --- .github/workflows/pr-checks.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index 00618784..d26a4cc1 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -11,6 +11,9 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true +permissions: + pull-requests: write + jobs: build: name: Build From 090ccc33fe517b0d236059712fa1de510f99b514 Mon Sep 17 00:00:00 2001 From: Sid Vishnoi <8426945+sidvishnoi@users.noreply.github.com> Date: Wed, 21 Aug 2024 17:20:26 +0530 Subject: [PATCH 10/11] Update pr-checks.yml --- .github/workflows/pr-checks.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index d26a4cc1..53ce304b 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -13,6 +13,7 @@ concurrency: permissions: pull-requests: write + issues: write jobs: build: From 14960f25d3182a1deccf6e7715c6de97fc215d1c Mon Sep 17 00:00:00 2001 From: Sid Vishnoi <8426945+sidvishnoi@users.noreply.github.com> Date: Wed, 21 Aug 2024 17:27:48 +0530 Subject: [PATCH 11/11] Update pr-checks.yml --- .github/workflows/pr-checks.yml | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index 53ce304b..f80687cf 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -1,7 +1,7 @@ name: PR Checks on: - pull_request: + pull_request_target: types: - opened - reopened @@ -11,10 +11,6 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true -permissions: - pull-requests: write - issues: write - jobs: build: name: Build @@ -26,6 +22,10 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + repository: ${{ (github.event.pull_request_target || github.event.pull_request).head.repo.full_name }} + ref: ${{ (github.event.pull_request_target || github.event.pull_request).head.sha }} - name: Environment setup uses: ./.github/actions/setup @@ -50,7 +50,11 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 - + with: + token: ${{ secrets.GITHUB_TOKEN }} + repository: ${{ (github.event.pull_request_target || github.event.pull_request).head.repo.full_name }} + ref: ${{ (github.event.pull_request_target || github.event.pull_request).head.sha }} + - name: Environment setup uses: ./.github/actions/setup @@ -70,6 +74,10 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + repository: ${{ (github.event.pull_request_target || github.event.pull_request).head.repo.full_name }} + ref: ${{ (github.event.pull_request_target || github.event.pull_request).head.sha }} - name: Environment setup uses: ./.github/actions/setup @@ -85,6 +93,10 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + repository: ${{ (github.event.pull_request_target || github.event.pull_request).head.repo.full_name }} + ref: ${{ (github.event.pull_request_target || github.event.pull_request).head.sha }} - name: Get workflow artifacts uses: actions/github-script@v7