Skip to content

Commit d6d3fd2

Browse files
authored
Update publish.yml
Signed-off-by: 1minds3t <1minds3t@proton.me>
1 parent 4a4a5e7 commit d6d3fd2

1 file changed

Lines changed: 132 additions & 12 deletions

File tree

.github/workflows/publish.yml

Lines changed: 132 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,144 @@ on:
1313
permissions:
1414
contents: read
1515
id-token: write
16+
actions: write
1617

1718
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+
18116
wait-for-tests:
19-
name: Wait for ALL Build Tests
117+
name: Wait for Build Completion
118+
needs: ensure-tests-running
20119
runs-on: ubuntu-latest
21120

22121
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
25124
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');
32154
33155
deploy:
34156
needs: wait-for-tests
@@ -55,7 +177,6 @@ jobs:
55177
run: |
56178
PACKAGE_VERSION=$(python -c "import tomli; print(tomli.load(open('pyproject.toml', 'rb'))['project']['version'])")
57179
58-
# For manual runs, use the input version. For releases, parse the tag.
59180
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
60181
EXPECTED_VERSION="${{ inputs.version }}"
61182
else
@@ -82,5 +203,4 @@ jobs:
82203
password: ${{ secrets.PYPI_API_TOKEN }}
83204

84205
- name: Success
85-
if: success()
86-
run: echo "🎉 Published version ${{ inputs.version || github.ref_name }}"
206+
run: echo "🎉 Published!"

0 commit comments

Comments
 (0)