diff --git a/.github/actions/get-workflow-artifacts.cjs b/.github/actions/get-workflow-artifacts.cjs index 6c375e39f..7c57daa68 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) diff --git a/.github/workflows/build-previews.yml b/.github/workflows/build-previews.yml deleted file mode 100644 index 3212ca58f..000000000 --- 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 diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index ee81c342c..f80687cfd 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 @@ -22,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 @@ -46,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 @@ -66,9 +74,53 @@ 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 - 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 + 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 + 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: + 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 }} + edit-mode: replace diff --git a/.prettierignore b/.prettierignore index ab3fc7be8..f8d0584d0 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,6 +1,6 @@ public -generated dist +dev pnpm-lock.yaml *.svg .gitignore