You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Check if the branch exists before proceeding with deployment
385
+
// Skip this check if:
386
+
// 1. We're deploying to the stable branch (e.g., `.deploy main`)
387
+
// 2. We're deploying an exact SHA (allow_sha_deployments is enabled and a SHA was provided)
388
+
// 3. The PR is from a fork (we use SHA for forks, not branch names)
389
+
if(
390
+
data.environmentObj.stable_branch_used!==true&&
391
+
data.environmentObj.sha===null&&
392
+
isFork===false
393
+
){
394
+
core.debug(`checking if branch exists: ${ref}`)
395
+
try{
396
+
awaitoctokit.rest.repos.getBranch({
397
+
...context.repo,
398
+
branch: ref,
399
+
headers: API_HEADERS
400
+
})
401
+
core.info(`✅ branch exists: ${ref}`)
402
+
}catch(error){
403
+
if(error.status===404){
404
+
message=`### ⚠️ Cannot proceed with deployment\n\n- ref: \`${ref}\`\n\nThe branch for this pull request no longer exists. This can happen if the branch was deleted after the PR was merged or closed. If you need to deploy, you can:\n- Use the stable branch deployment (e.g., \`${data.inputs.trigger}${data.inputs.stable_branch}\`)\n- Use an exact SHA deployment if enabled (e.g., \`${data.inputs.trigger}${sha}\`)\n\n> If you are running this command on a closed pull request, you can also try reopening the pull request to restore the branch for a deployment.`
405
+
core.warning(`branch does not exist: ${ref}`)
406
+
return{message: message,status: false}
407
+
}
408
+
// If it's not a 404 error, it's unexpected - hard stop
409
+
message=`### ⚠️ Cannot proceed with deployment\n\n- ref: \`${ref}\`\n\n> An unexpected error occurred while checking if the branch exists: \`${error.message}\``
410
+
core.error(`unexpected error checking if branch exists: ${error.message}`)
411
+
return{message: message,status: false}
412
+
}
413
+
}
414
+
384
415
// Always allow deployments to the "stable" branch regardless of CI checks or PR review
0 commit comments