Skip to content

Commit 677f397

Browse files
committed
refactor: ♻️ Detect in-progress deploy-ui for PR on open
1 parent 7645f5f commit 677f397

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

.github/workflows/deploy-preview-app.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ jobs:
232232
permissions:
233233
contents: read
234234
deployments: read
235+
actions: read
235236
issues: write
236237
pull-requests: write
237238

@@ -257,6 +258,7 @@ jobs:
257258
script: |
258259
const previewUrl = `https://${process.env.KAMAL_APP_DOMAIN}`;
259260
const issue_number = context.payload.pull_request.number;
261+
const branch = context.payload.pull_request.head.ref;
260262
261263
// Look up the latest deployment for this preview environment
262264
const { data: deployments } = await github.rest.repos.listDeployments({
@@ -284,7 +286,22 @@ jobs:
284286
body = `## Preview deployment\n\nA preview environment will be available at [${previewUrl}](${previewUrl}) after the next push to this branch.`;
285287
}
286288
} else {
287-
body = `## Preview deployment\n\nA preview environment will be available at [${previewUrl}](${previewUrl}) after the next push to this branch.`;
289+
// No deployment record yet — check if deploy-ui is currently running for this branch.
290+
// The GitHub deployment record is only created after kamal completes, so a concurrent
291+
// push can leave listDeployments empty while the workflow is still in progress.
292+
const { data: runs } = await github.rest.actions.listWorkflowRunsForRepo({
293+
owner: context.repo.owner,
294+
repo: context.repo.repo,
295+
branch,
296+
status: 'in_progress',
297+
per_page: 10,
298+
});
299+
const deployRunning = runs.workflow_runs.some(r => r.name === 'Deploy preview environment');
300+
if (deployRunning) {
301+
body = `## Preview deployment in progress\n\nA preview environment is being built and will be available at [${previewUrl}](${previewUrl}) once ready. Please wait...`;
302+
} else {
303+
body = `## Preview deployment\n\nA preview environment will be available at [${previewUrl}](${previewUrl}) after the next push to this branch.`;
304+
}
288305
}
289306
290307
const { data: comments } = await github.rest.issues.listComments({

0 commit comments

Comments
 (0)