Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Testing workflow run for PR from fork #531

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions .github/actions/get-workflow-artifacts.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)
})

Expand All @@ -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, `<a href="${jobLogsUrl}">Run #${runId}</a>`)
.replace(TEMPLATE_VARS.tableBody, tableBody)
Expand Down
43 changes: 0 additions & 43 deletions .github/workflows/build-previews.yml

This file was deleted.

56 changes: 54 additions & 2 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: PR Checks

on:
pull_request:
pull_request_target:
types:
- opened
- reopened
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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: '<!-- __WM_EXTENSION_BUILD_PREVIEWS__ -->'

- 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
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
public
generated
dist
dev
pnpm-lock.yaml
*.svg
.gitignore
Expand Down