Skip to content

Commit

Permalink
Port changes from vue ecosystem ci (vitejs#256)
Browse files Browse the repository at this point in the history
* feat: add a comparison column to the PR comment

Co-Authored-By: Haoqun Jiang <3277634+sodatea@users.noreply.github.com>

* feat: updateComment -> deleteComment + createComment

So that maintainers can get one more email notification when the CI is
done.

Co-Authored-By: Haoqun Jiang <3277634+sodatea@users.noreply.github.com>

* feat: swap delete comment and create comment

* feat: show ref the CI ran on

* fix: fix ref link

* fix: set working-directory

* fix: set working-directory

* feat: change ref link

---------

Co-authored-by: Haoqun Jiang <3277634+sodatea@users.noreply.github.com>
  • Loading branch information
2 people authored and danielroe committed Oct 30, 2023
1 parent e6401c9 commit b031345
Showing 1 changed file with 71 additions and 10 deletions.
81 changes: 71 additions & 10 deletions .github/workflows/ecosystem-ci-from-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ jobs:
runs-on: ubuntu-latest
needs: init
if: "inputs.suite != '-'"
outputs:
ref: ${{ steps.get-ref.outputs.ref }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand All @@ -98,12 +100,20 @@ jobs:
env:
NUXT_UI_PRO_TOKEN: ${{ secrets.NUXT_UI_PRO_TOKEN }}
NUXT_UI_PRO_LICENSE: ${{ secrets.NUXT_UI_PRO_TOKEN }}
- id: get-ref
if: always()
run: |
ref=$(git log -1 --pretty=format:%H)
echo "ref=$ref" >> $GITHUB_OUTPUT
working-directory: workspace/nuxt

execute-all:
timeout-minutes: 30
runs-on: ubuntu-latest
needs: init
if: "inputs.suite == '-'"
outputs:
ref: ${{ steps.get-ref.outputs.ref }}
strategy:
matrix:
suite:
Expand Down Expand Up @@ -143,6 +153,12 @@ jobs:
env:
NUXT_UI_PRO_TOKEN: ${{ secrets.NUXT_UI_PRO_TOKEN }}
NUXT_UI_PRO_LICENSE: ${{ secrets.NUXT_UI_PRO_TOKEN }}
- id: get-ref
if: always()
run: |
ref=$(git log -1 --pretty=format:%H)
echo "ref=$ref" >> $GITHUB_OUTPUT
working-directory: workspace/nuxt

update-comment:
runs-on: ubuntu-latest
Expand All @@ -159,6 +175,10 @@ jobs:
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
const mainRepoName = 'nuxt'
const ref = "${{ needs.execute-all.outputs.ref }}" || "${{ needs.execute-selected-suite.outputs.ref }}"
const refLink = `[\`${ref.slice(0, 7)}\`](${context.serverUrl}/${context.repo.owner}/${mainRepoName}/pull/${context.payload.inputs.prNumber}/commits/${ref})`
const { data: { jobs } } = await github.rest.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
Expand All @@ -167,20 +187,20 @@ jobs:
});
const selectedSuite = context.payload.inputs.suite
let result
let results
if (selectedSuite !== "-") {
const { conclusion, html_url } = jobs.find(job => job.name === "execute-selected-suite")
result = [{ suite: selectedSuite, conclusion, link: html_url }]
results = [{ suite: selectedSuite, conclusion, link: html_url }]
} else {
result = jobs
results = jobs
.filter(job => job.name.startsWith('execute-all '))
.map(job => {
const suite = job.name.replace(/^execute-all \(([^)]+)\)$/, "$1")
return { suite, conclusion: job.conclusion, link: job.html_url }
})
}
const url = `${context.serverUrl}//${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
const url = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
const urlLink = `[Open](${url})`
const conclusionEmoji = {
Expand All @@ -189,17 +209,58 @@ jobs:
cancelled: ":stop_button:"
}
// check for previous ecosystem-ci runs against the main branch
// first, list workflow runs for ecosystem-ci.yml
const { data: { workflow_runs } } = await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'ecosystem-ci.yml'
});
// for simplity, we only take the latest completed scheduled run
// otherwise we would have to check the inputs for every maunally triggerred runs, which is an overkill
const latestScheduledRun = workflow_runs.find(run => run.event === "schedule" && run.status === "completed")
// get the jobs for the latest scheduled run
const { data: { jobs: scheduledJobs } } = await github.rest.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: latestScheduledRun.id
});
const scheduledResults = scheduledJobs
.filter(job => job.name.startsWith('test-ecosystem '))
.map(job => {
const suite = job.name.replace(/^test-ecosystem \(([^)]+)\)$/, "$1")
return { suite, conclusion: job.conclusion, link: job.html_url }
})
const body = `
📝 Ran ecosystem CI: ${urlLink}
📝 Ran ecosystem CI on ${refLink}: ${urlLink}
| suite | result | [latest scheduled](${latestScheduledRun.html_url}) |
|-------|--------|----------------|
${results.map(current => {
const latest = scheduledResults.find(s => s.suite === current.suite) || {} // in case a new suite is added after latest scheduled
const firstColumn = current.suite
const secondColumn = `${conclusionEmoji[current.conclusion]} [${current.conclusion}](${current.link})`
const thirdColumn = `${conclusionEmoji[latest.conclusion]} [${latest.conclusion}](${latest.link})`
| suite | result |
|-------|--------|
${result.map(r => `| [${r.suite}](${r.link}) | ${conclusionEmoji[r.conclusion]} ${r.conclusion} |`).join("\n")}
return `| ${firstColumn} | ${secondColumn} | ${thirdColumn} |`
}).join("\n")}
`
await github.rest.issues.updateComment({
await github.rest.issues.createComment({
issue_number: context.payload.inputs.prNumber,
owner: context.repo.owner,
repo: 'nuxt',
repo: mainRepoName,
comment_id: ${{ needs.init.outputs.comment-id }},
body
})
await github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: mainRepoName,
comment_id: ${{ needs.init.outputs.comment-id }}
})

0 comments on commit b031345

Please sign in to comment.