Skip to content

Commit 21f9293

Browse files
committed
refactor(monorepo): move workflow to correct location (#251)
# Auto Deploy Preview Workflow Closes: WORLD-XXX ## Overview This PR adds a new GitHub workflow for automatically deploying preview environments. The workflow is designed to be called from other workflows and handles the coordination with World Forge for deployments. ## Brief Changelog - Added new reusable workflow `auto_deploy.yml` that can be triggered via `workflow_call` - Implemented a signal job that emits a repository dispatch event to trigger auto-deployment - Added status monitoring that waits for World Forge deployment statuses - Implemented timeout handling with both initial (2 min) and hard (45 min) deadlines - Added failure detection and reporting for deployment issues ## Testing and Verifying This change can be verified by triggering the workflow from another workflow and confirming that it properly signals the auto-deploy event and correctly monitors the deployment statuses.
1 parent dbaf20b commit 21f9293

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

.github/workflows/auto_deploy.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Auto Deploy Preview
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
base:
7+
type: string
8+
required: true
9+
head:
10+
type: string
11+
required: true
12+
13+
permissions:
14+
contents: write
15+
statuses: read
16+
17+
jobs:
18+
signal:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Emit repository_dispatch to App
22+
uses: actions/github-script@v7
23+
with:
24+
script: |
25+
await github.rest.repos.createDispatchEvent({
26+
owner: context.repo.owner,
27+
repo: context.repo.repo,
28+
event_type: "auto-deploy",
29+
client_payload: { base: inputs.base, head: inputs.head }
30+
})
31+
- name: Wait for World Forge status
32+
uses: actions/github-script@v7
33+
with:
34+
script: |
35+
const owner = context.repo.owner, repo = context.repo.repo, ref = inputs.head;
36+
const prefix = "world-forge/auto-deploy";
37+
const initDeadline = Date.now() + 2*60*1000;
38+
const hardDeadline = Date.now() + 45*60*1000;
39+
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
40+
async function allStatuses() {
41+
const { data } = await github.rest.repos.getCombinedStatusForRef({ owner, repo, ref });
42+
return data.statuses || [];
43+
}
44+
let expected = null;
45+
while (Date.now() < initDeadline) {
46+
const statuses = await allStatuses();
47+
const aggFail = statuses.find(s => s.context === prefix && (s.state === "failure" || s.state === "error"));
48+
if (aggFail) { core.setFailed(aggFail.description || "Auto-deploy aggregate failed"); return; }
49+
const aggs = statuses.filter(s => s.context === prefix && s.state === "pending");
50+
for (const a of aggs) {
51+
const n = parseInt(a.description || "0", 10);
52+
if (!Number.isNaN(n) && n > 0) { expected = n; break; }
53+
}
54+
if (expected) break;
55+
await sleep(5000);
56+
}
57+
if (!expected) { core.setFailed("Auto-deploy did not publish expected deployment count."); return; }
58+
while (Date.now() < hardDeadline) {
59+
const statuses = await allStatuses();
60+
const perProject = statuses.filter(s => s.context.startsWith(prefix + "/"));
61+
const success = perProject.filter(s => s.state === "success").length;
62+
const failed = perProject.filter(s => s.state === "failure" || s.state === "error").length;
63+
if (success + failed >= expected) { if (failed > 0) core.setFailed(`Deploy failures: ${failed}/${expected}`); return; }
64+
await sleep(10000);
65+
}
66+
core.setFailed("Timed out waiting for auto-deploy results.");
67+

0 commit comments

Comments
 (0)