|
20 | 20 | PYTHON_VERSION: "3.11" |
21 | 21 |
|
22 | 22 | jobs: |
| 23 | + check-ci-status: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Get commit SHA |
| 29 | + id: get-sha |
| 30 | + run: | |
| 31 | + if [[ "${{ github.event_name }}" == "push" ]]; then |
| 32 | + echo "sha=${{ github.sha }}" >> $GITHUB_OUTPUT |
| 33 | + else |
| 34 | + # For workflow_dispatch, use the current HEAD |
| 35 | + echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT |
| 36 | + fi |
| 37 | +
|
| 38 | + - name: Check CI status |
| 39 | + uses: actions/github-script@v7 |
| 40 | + with: |
| 41 | + script: | |
| 42 | + const sha = '${{ steps.get-sha.outputs.sha }}'; |
| 43 | + console.log(`Checking CI status for commit: ${sha}`); |
| 44 | +
|
| 45 | + // Get check runs for this commit |
| 46 | + const { data: checkRuns } = await github.rest.checks.listForRef({ |
| 47 | + owner: context.repo.owner, |
| 48 | + repo: context.repo.repo, |
| 49 | + ref: sha, |
| 50 | + }); |
| 51 | +
|
| 52 | + // Find CI/CD workflow runs |
| 53 | + const ciRuns = checkRuns.check_runs.filter(run => |
| 54 | + run.name.includes('test') || run.name.includes('lint') || run.name.includes('security') |
| 55 | + ); |
| 56 | +
|
| 57 | + if (ciRuns.length === 0) { |
| 58 | + core.setFailed('No CI runs found for this commit. Please ensure CI has run successfully.'); |
| 59 | + return; |
| 60 | + } |
| 61 | +
|
| 62 | + // Check if all CI runs passed |
| 63 | + const failedRuns = ciRuns.filter(run => |
| 64 | + run.conclusion !== 'success' && run.conclusion !== 'skipped' |
| 65 | + ); |
| 66 | +
|
| 67 | + if (failedRuns.length > 0) { |
| 68 | + const failedNames = failedRuns.map(run => `${run.name}: ${run.conclusion}`).join(', '); |
| 69 | + core.setFailed(`CI checks failed: ${failedNames}`); |
| 70 | + return; |
| 71 | + } |
| 72 | +
|
| 73 | + console.log('All CI checks passed!'); |
| 74 | +
|
23 | 75 | validate-version: |
24 | 76 | runs-on: ubuntu-latest |
| 77 | + needs: check-ci-status |
25 | 78 | outputs: |
26 | 79 | version: ${{ steps.version.outputs.version }} |
27 | 80 | tag_name: ${{ steps.version.outputs.tag_name }} |
|
0 commit comments