|
13 | 13 | permissions: |
14 | 14 | contents: read |
15 | 15 | id-token: write |
| 16 | + actions: write |
16 | 17 |
|
17 | 18 | jobs: |
| 19 | + ensure-tests-running: |
| 20 | + name: Ensure Build Tests Are Running |
| 21 | + runs-on: ubuntu-latest |
| 22 | + outputs: |
| 23 | + run_id: ${{ steps.find-or-trigger.outputs.run_id }} |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Find existing or trigger new build |
| 27 | + id: find-or-trigger |
| 28 | + uses: actions/github-script@v7 |
| 29 | + with: |
| 30 | + script: | |
| 31 | + const workflow_id = 'cross-platform-build-verification.yml'; |
| 32 | + const ref = context.eventName === 'release' |
| 33 | + ? context.payload.release.tag_name |
| 34 | + : context.ref; |
| 35 | + |
| 36 | + // Check if there's already a running build |
| 37 | + const runs = await github.rest.actions.listWorkflowRuns({ |
| 38 | + owner: context.repo.owner, |
| 39 | + repo: context.repo.repo, |
| 40 | + workflow_id: workflow_id, |
| 41 | + status: 'in_progress', |
| 42 | + per_page: 10 |
| 43 | + }); |
| 44 | + |
| 45 | + let targetRun = runs.data.workflow_runs.find(run => |
| 46 | + run.head_sha === context.sha || run.head_branch === ref |
| 47 | + ); |
| 48 | + |
| 49 | + if (targetRun) { |
| 50 | + console.log(`✅ Found existing running build: ${targetRun.id}`); |
| 51 | + core.setOutput('run_id', targetRun.id); |
| 52 | + return; |
| 53 | + } |
| 54 | + |
| 55 | + // If release event, wait for the auto-triggered build to appear |
| 56 | + if (context.eventName === 'release') { |
| 57 | + console.log('📦 Release event - waiting for auto-triggered build to appear...'); |
| 58 | + |
| 59 | + for (let i = 0; i < 12; i++) { // Wait up to 1 minute |
| 60 | + await new Promise(resolve => setTimeout(resolve, 5000)); |
| 61 | + |
| 62 | + const refreshRuns = await github.rest.actions.listWorkflowRuns({ |
| 63 | + owner: context.repo.owner, |
| 64 | + repo: context.repo.repo, |
| 65 | + workflow_id: workflow_id, |
| 66 | + per_page: 10 |
| 67 | + }); |
| 68 | + |
| 69 | + targetRun = refreshRuns.data.workflow_runs.find(run => |
| 70 | + run.head_sha === context.sha |
| 71 | + ); |
| 72 | + |
| 73 | + if (targetRun) { |
| 74 | + console.log(`✅ Found auto-triggered build: ${targetRun.id}`); |
| 75 | + core.setOutput('run_id', targetRun.id); |
| 76 | + return; |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + throw new Error('❌ Release should have auto-triggered build, but none found'); |
| 81 | + } |
| 82 | + |
| 83 | + // Manual trigger - create new build |
| 84 | + console.log('🔧 Manual workflow_dispatch - triggering new build...'); |
| 85 | + |
| 86 | + await github.rest.actions.createWorkflowDispatch({ |
| 87 | + owner: context.repo.owner, |
| 88 | + repo: context.repo.repo, |
| 89 | + workflow_id: workflow_id, |
| 90 | + ref: ref |
| 91 | + }); |
| 92 | + |
| 93 | + console.log('Waiting for new build to appear...'); |
| 94 | + |
| 95 | + // Wait for the triggered build to show up |
| 96 | + for (let i = 0; i < 24; i++) { // Wait up to 2 minutes |
| 97 | + await new Promise(resolve => setTimeout(resolve, 5000)); |
| 98 | + |
| 99 | + const newRuns = await github.rest.actions.listWorkflowRuns({ |
| 100 | + owner: context.repo.owner, |
| 101 | + repo: context.repo.repo, |
| 102 | + workflow_id: workflow_id, |
| 103 | + per_page: 5 |
| 104 | + }); |
| 105 | + |
| 106 | + const latestRun = newRuns.data.workflow_runs[0]; |
| 107 | + if (latestRun && latestRun.status !== 'completed') { |
| 108 | + console.log(`✅ New build started: ${latestRun.id}`); |
| 109 | + core.setOutput('run_id', latestRun.id); |
| 110 | + return; |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + throw new Error('❌ Failed to find triggered build'); |
| 115 | +
|
18 | 116 | wait-for-tests: |
19 | | - name: Wait for ALL Build Tests |
| 117 | + name: Wait for Build Completion |
| 118 | + needs: ensure-tests-running |
20 | 119 | runs-on: ubuntu-latest |
21 | 120 |
|
22 | 121 | steps: |
23 | | - - name: Wait for ENTIRE Cross-Platform Workflow |
24 | | - uses: fountainhead/action-wait-for-check@v1.1.0 |
| 122 | + - name: Wait for build workflow |
| 123 | + uses: actions/github-script@v7 |
25 | 124 | with: |
26 | | - token: ${{ secrets.GITHUB_TOKEN }} |
27 | | - # Wait for the WORKFLOW to complete, not just one job |
28 | | - checkName: 'Cross-Platform Build Verification' # This is the workflow name |
29 | | - ref: ${{ github.event.release.tag_name || github.sha }} |
30 | | - timeoutSeconds: 3600 |
31 | | - intervalSeconds: 30 |
| 125 | + script: | |
| 126 | + const run_id = '${{ needs.ensure-tests-running.outputs.run_id }}'; |
| 127 | + const maxAttempts = 120; // 1 hour |
| 128 | + const intervalMs = 30000; |
| 129 | + |
| 130 | + console.log(`Monitoring build run ID: ${run_id}`); |
| 131 | + |
| 132 | + for (let i = 0; i < maxAttempts; i++) { |
| 133 | + const run = await github.rest.actions.getWorkflowRun({ |
| 134 | + owner: context.repo.owner, |
| 135 | + repo: context.repo.repo, |
| 136 | + run_id: run_id |
| 137 | + }); |
| 138 | + |
| 139 | + console.log(`Status: ${run.data.status} | Conclusion: ${run.data.conclusion || 'N/A'}`); |
| 140 | + |
| 141 | + if (run.data.status === 'completed') { |
| 142 | + if (run.data.conclusion === 'success') { |
| 143 | + console.log('✅ All build tests passed!'); |
| 144 | + return; |
| 145 | + } else { |
| 146 | + throw new Error(`❌ Build failed with conclusion: ${run.data.conclusion}`); |
| 147 | + } |
| 148 | + } |
| 149 | + |
| 150 | + await new Promise(resolve => setTimeout(resolve, intervalMs)); |
| 151 | + } |
| 152 | + |
| 153 | + throw new Error('❌ Timeout waiting for build'); |
32 | 154 |
|
33 | 155 | deploy: |
34 | 156 | needs: wait-for-tests |
|
55 | 177 | run: | |
56 | 178 | PACKAGE_VERSION=$(python -c "import tomli; print(tomli.load(open('pyproject.toml', 'rb'))['project']['version'])") |
57 | 179 | |
58 | | - # For manual runs, use the input version. For releases, parse the tag. |
59 | 180 | if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then |
60 | 181 | EXPECTED_VERSION="${{ inputs.version }}" |
61 | 182 | else |
|
82 | 203 | password: ${{ secrets.PYPI_API_TOKEN }} |
83 | 204 |
|
84 | 205 | - name: Success |
85 | | - if: success() |
86 | | - run: echo "🎉 Published version ${{ inputs.version || github.ref_name }}" |
| 206 | + run: echo "🎉 Published!" |
0 commit comments