Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions .github/workflows/vercel-preview-guard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,19 @@ jobs:
script: |
const { owner, repo } = context.repo;
const sha = process.env.HEAD_SHA;
// Vercel suffixes environments and commit contexts in multi-project repos.
const environment = 'Preview – regengine';
const statusContext = 'Vercel – regengine';
const environments = ['Preview – regengine', 'Preview'];
const statusContexts = ['Vercel – regengine', 'Vercel'];
const deadline = Date.now() + 25 * 60 * 1000;
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
const rejected = /\b(skip(?:ped)?|ignor(?:e|ed)|cancel(?:ed|led)|error|fail(?:ed|ure)?)\b/i;

while (Date.now() < deadline) {
const { data: deployments } = await github.rest.repos.listDeployments({
owner, repo, sha, environment, per_page: 100,
owner, repo, sha, per_page: 100,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Inspect all matching preview deployments

When another project or integration creates a Preview deployment for the same SHA, removing the server-side environment filter lets that deployment appear in this result set, but the subsequent .find(...) selects only one candidate. If that candidate's URL fails the regengine hostname allowlist, the loop repeatedly inspects it and never examines a later valid regengine deployment, so this non-required guard waits 25 minutes and never posts the access link. Iterate through all matching deployments until the URL identifies the regengine project (or query each accepted environment separately) rather than validating only the first match.

Useful? React with 👍 / 👎.

});
// Use only the newest deployment for this SHA and project.
const deployment = deployments.find(d =>
d.sha === sha && d.environment === environment);
d.sha === sha && environments.includes(d.environment));
if (deployment) {
const { data: statuses } = await github.rest.repos.listDeploymentStatuses({
owner, repo, deployment_id: deployment.id, per_page: 100,
Expand Down Expand Up @@ -76,7 +75,7 @@ jobs:
const { data: commitStatuses } = await github.rest.repos.listCommitStatusesForRef({
owner, repo, ref: sha, per_page: 100,
});
const vercelStatus = commitStatuses.find(s => s.context === statusContext);
const vercelStatus = commitStatuses.find(s => statusContexts.includes(s.context));
if (vercelStatus && (rejected.test(vercelStatus.description || '') ||
['error', 'failure'].includes(vercelStatus.state))) {
throw new Error(`Vercel preview status ended ${vercelStatus.state}: ${vercelStatus.description || 'no detail'}`);
Expand All @@ -86,7 +85,7 @@ jobs:
owner, repo, ref: sha, per_page: 100,
});
const vercelCheck = checks.check_runs.find(c =>
c.app?.slug === 'vercel' && c.name === statusContext);
c.app?.slug === 'vercel' && statusContexts.includes(c.name));
if (vercelCheck && ['skipped', 'cancelled', 'failure', 'timed_out', 'action_required', 'neutral', 'stale'].includes(vercelCheck.conclusion)) {
throw new Error(`Vercel preview check ended ${vercelCheck.conclusion}`);
}
Expand Down
Loading