|
| 1 | +name: 'Check releasability status' |
| 2 | +description: 'Gets the status of the latest releasability check on the master branch and returns the version if it succeeded.' |
| 3 | + |
| 4 | +inputs: |
| 5 | + check-name: |
| 6 | + description: 'The name of the check run to find.' |
| 7 | + required: false |
| 8 | + default: 'Releasability status' |
| 9 | + github-token: |
| 10 | + description: 'The GitHub token for API calls.' |
| 11 | + required: true |
| 12 | + default: ${{ github.token }} |
| 13 | + |
| 14 | +outputs: |
| 15 | + version: |
| 16 | + description: 'The extracted version string from the check annotation.' |
| 17 | + value: ${{ steps.check_releasability_script.outputs.version }} |
| 18 | + |
| 19 | +runs: |
| 20 | + using: 'composite' |
| 21 | + steps: |
| 22 | + - name: Check releasability status |
| 23 | + id: check_releasability_script |
| 24 | + uses: actions/github-script@v7 |
| 25 | + with: |
| 26 | + github-token: ${{ inputs.github-token }} |
| 27 | + script: | |
| 28 | + const { owner, repo } = context.repo; |
| 29 | + const check_name = '${{ inputs.check-name }}'; |
| 30 | +
|
| 31 | + console.log(`Searching for check runs on the "master" branch.`); |
| 32 | + const { data: { check_runs } } = await github.rest.checks.listForRef({ |
| 33 | + owner, |
| 34 | + repo, |
| 35 | + ref: 'master', |
| 36 | + per_page: 50 |
| 37 | + }); |
| 38 | +
|
| 39 | + console.log(`Filtering for the first non-skipped check named "${check_name}".`); |
| 40 | + const targetCheck = check_runs.find(check => check.name === check_name && check.conclusion !== 'skipped'); |
| 41 | +
|
| 42 | + if (!targetCheck) { |
| 43 | + core.setFailed(`Could not find a recent, non-skipped check named "${check_name}" on the master branch.`); |
| 44 | + return; |
| 45 | + } |
| 46 | +
|
| 47 | + console.log(`Found latest relevant check run #${targetCheck.id} (Conclusion: ${targetCheck.conclusion}) on commit ${targetCheck.head_sha}.`); |
| 48 | +
|
| 49 | + if (targetCheck.conclusion !== 'success') { |
| 50 | + core.setFailed(`The check run "${check_name}" did not succeed. Conclusion: ${targetCheck.conclusion}.`); |
| 51 | + return; |
| 52 | + } |
| 53 | +
|
| 54 | + console.log('Check was successful. Fetching annotations...'); |
| 55 | + const { data: annotations } = await github.rest.checks.listAnnotations({ |
| 56 | + owner, |
| 57 | + repo, |
| 58 | + check_run_id: targetCheck.id |
| 59 | + }); |
| 60 | +
|
| 61 | + if (annotations.length === 0) { |
| 62 | + core.setFailed('Found the successful check, but it has no annotations.'); |
| 63 | + return; |
| 64 | + } |
| 65 | + |
| 66 | + const firstAnnotation = annotations[0]; |
| 67 | +
|
| 68 | + if (firstAnnotation.annotation_level === 'failure') { |
| 69 | + core.setFailed(`The check annotation indicates a failure: "${firstAnnotation.message}"`); |
| 70 | + return; |
| 71 | + } |
| 72 | +
|
| 73 | + const annotationMessage = firstAnnotation.message; |
| 74 | + console.log(`Found annotation message: "${annotationMessage}"`); |
| 75 | +
|
| 76 | + const match = annotationMessage.match(/of ([\d\.]+)/); |
| 77 | + if (!match || !match[1]) { |
| 78 | + core.setFailed(`Could not parse version from annotation message: "${annotationMessage}"`); |
| 79 | + return; |
| 80 | + } |
| 81 | +
|
| 82 | + const version = match[1]; |
| 83 | + console.log(`✅ Extracted version from annotation: ${version}`); |
| 84 | + core.setOutput('version', version); |
0 commit comments