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

Port changes from vue ecosystem ci #256

Merged
merged 8 commits into from
Oct 20, 2023
Merged
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
82 changes: 71 additions & 11 deletions .github/workflows/ecosystem-ci-from-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ jobs:
runs-on: ubuntu-latest
needs: init
if: "inputs.suite != '-'"
outputs:
ref: ${{ steps.get-ref.outputs.ref }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
Expand All @@ -105,12 +107,20 @@ jobs:
--branch ${{ inputs.branchName }}
--repo ${{ inputs.repo }}
${{ inputs.suite }}
- id: get-ref
if: always()
run: |
ref=$(git log -1 --pretty=format:%H)
echo "ref=$ref" >> $GITHUB_OUTPUT
working-directory: workspace/vite

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 @@ -157,6 +167,12 @@ jobs:
--branch ${{ inputs.branchName }}
--repo ${{ inputs.repo }}
${{ matrix.suite }}
- id: get-ref
if: always()
run: |
ref=$(git log -1 --pretty=format:%H)
echo "ref=$ref" >> $GITHUB_OUTPUT
working-directory: workspace/vite

update-comment:
runs-on: ubuntu-latest
Expand All @@ -173,6 +189,10 @@ jobs:
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
const mainRepoName = 'vite'
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 @@ -181,20 +201,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 @@ -203,17 +223,57 @@ 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: 'vite',
comment_id: ${{ needs.init.outputs.comment-id }},
repo: mainRepoName,
body
})

await github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: mainRepoName,
comment_id: ${{ needs.init.outputs.comment-id }}
})