|
5 | 5 | tags: [ 'v*' ] # Trigger release only on version tags |
6 | 6 |
|
7 | 7 | jobs: |
8 | | - # Release job - publishes to crates.io when pushing version tags |
| 8 | + # Verify tests passed before release |
| 9 | + verify-tests: |
| 10 | + name: Verify tests passed |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Check latest workflow run |
| 14 | + uses: actions/github-script@v7 |
| 15 | + with: |
| 16 | + script: | |
| 17 | + // Get the commit SHA for the tag |
| 18 | + const tagRef = context.ref; |
| 19 | + const tagSha = context.sha; |
| 20 | + |
| 21 | + console.log(`Checking tests for tag ${tagRef} (${tagSha})`); |
| 22 | + |
| 23 | + // Get recent workflow runs for the test workflow |
| 24 | + const { data: workflows } = await github.rest.actions.listWorkflowRuns({ |
| 25 | + owner: context.repo.owner, |
| 26 | + repo: context.repo.repo, |
| 27 | + workflow_id: 'test.yml', |
| 28 | + head_sha: tagSha, |
| 29 | + per_page: 1 |
| 30 | + }); |
| 31 | + |
| 32 | + if (workflows.total_count === 0) { |
| 33 | + console.log('⚠️ No test workflow found for this commit'); |
| 34 | + console.log('This might be expected if this is the first run after adding the tag trigger'); |
| 35 | + return; |
| 36 | + } |
| 37 | + |
| 38 | + const latestRun = workflows.workflow_runs[0]; |
| 39 | + console.log(`Latest test run: ${latestRun.status} (${latestRun.conclusion})`); |
| 40 | + |
| 41 | + if (latestRun.conclusion !== 'success') { |
| 42 | + console.log('❌ Tests did not pass - release cannot proceed'); |
| 43 | + process.exit(1); |
| 44 | + } |
| 45 | + |
| 46 | + console.log('✅ Tests passed - release can proceed'); |
| 47 | +
|
| 48 | + # Release job - publishes to crates.io when version tags are pushed |
9 | 49 | release: |
10 | 50 | name: Release to crates.io |
11 | 51 | runs-on: ubuntu-latest |
12 | | - # Use GitHub environment for enhanced security (optional but recommended) |
| 52 | + needs: verify-tests |
| 53 | + # Use GitHub environment for enhanced security and manual approval if desired |
13 | 54 | environment: release |
14 | 55 | permissions: |
15 | 56 | id-token: write # Required for OIDC token exchange with crates.io |
|
0 commit comments