E2E Check #357301
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: E2E Check | |
on: | |
status: | |
jobs: | |
e2e-check-rerun: | |
runs-on: ubuntu-latest | |
if: ${{ github.event.state == 'success' && startsWith( github.event.context, 'percy/' ) }} | |
steps: | |
- uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const sha = (context.payload && context.payload.commit && context.payload.commit.sha) || (context.payload && context.payload.after); | |
if (!sha) { | |
console.log('No commit SHA found.'); | |
console.log(''); | |
console.log(`context.eventName: ${JSON.stringify(context.eventName, null, 2)}`); | |
console.log(`context.payload: ${JSON.stringify(context.payload, null, 2)}`); | |
console.log(''); | |
process.exit(1); | |
} | |
console.log(`Finding e2e workflow run for commit ${sha}.`); | |
const {data} = await github.rest.actions.listWorkflowRuns({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
workflow_id: 'e2e.yml', | |
head_sha: sha, | |
status: 'completed', | |
per_page: 1 | |
}); | |
const run = data.workflow_runs[0]; | |
// If there is a run that failed and completed | |
if (data.total_count > 0 && run && run.conclusion === 'failure' && run.status === 'completed') { | |
console.log(`E2E workflow run ${run.id} failed. Looking into the E2E Visual Review job.`); | |
const {data} = await github.rest.actions.listJobsForWorkflowRun({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: run.id, | |
per_page: 100, | |
filter: 'latest' | |
}); | |
const e2eReviewJob = (data.jobs || []).find(job => job.name === 'E2E Visual Review'); | |
// If the "E2E Visual Review" job ran and failed (i.e., the workflow didn't fail before that step) | |
if ( | |
e2eReviewJob && | |
e2eReviewJob.status === 'completed' && | |
e2eReviewJob.conclusion === 'failure' | |
) { | |
console.log(`Re-running E2E Visual Review job ${e2eReviewJob.id} for workflow run ${run.id}.`); | |
await github.rest.actions.reRunJobForWorkflowRun({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
job_id: e2eReviewJob.id | |
}); | |
} else { | |
// CLI call for github.rest.actions.listJobsForWorkflowRun | |
// https://docs.github.com/en/rest/actions/workflow-jobs?apiVersion=2022-11-28#list-jobs-for-a-workflow-run | |
console.log('') | |
console.log(`# gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" \\`) | |
console.log(` "/repos/${context.repo.owner}/${context.repo.repo}/actions/runs/${run.id}/jobs?per_page=100&filter=latest"`) | |
console.log('') | |
if (e2eReviewJob) { | |
console.log(`E2E Visual Review job ${e2eReviewJob.id} for workflow run ${run.id} is status ${e2eReviewJob.status}, conclusion ${e2eReviewJob.conclusion}.`); | |
} else { | |
console.log(`No E2E Visual Review job found for workflow run ${run.id}.`); | |
} | |
} | |
} else { | |
// CLI call for github.rest.actions.listWorkflowRuns | |
// https://docs.github.com/en/rest/actions/workflow-runs?apiVersion=2022-11-28#list-workflow-runs-for-a-workflow | |
console.log(''); | |
console.log(`# gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" \\`); | |
console.log(` "/repos/${context.repo.owner}/${context.repo.repo}/actions/workflows/e2e.yml/runs?head_sha=${sha}&status=completed&per_page=1"`); | |
console.log(''); | |
if (data.total_count === 0 || !run) { | |
console.log('No e2e workflow run found.'); | |
} else if (run.conclusion === 'success') { | |
console.log(`E2E workflow run ${run.id} succeeded. No action needed.`); | |
} else { | |
console.log(`E2E workflow run ${run.id} is status ${run.status}, conclusion ${run.conclusion}.`); | |
} | |
} |