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
constBUILD_AND_DEPLOY_JOB_NAME_PREFIX='Build and deploy';
11
+
12
+
/**
13
+
* This function checks if a given release is a valid baseTag to get the PR list with `git log baseTag...endTag`.
14
+
*
15
+
* The rules are:
16
+
* - production deploys can only be compared with other production deploys
17
+
* - staging deploys can be compared with other staging deploys or production deploys.
18
+
* The reason is that the final staging release in each deploy cycle will BECOME a production release.
19
+
* For example, imagine a checklist is closed with version 9.0.20-6; that's the most recent staging deploy, but the release for 9.0.20-6 is now finalized, so it looks like a prod deploy.
20
+
* When 9.0.21-0 finishes deploying to staging, the most recent prerelease is 9.0.20-5. However, we want 9.0.20-6...9.0.21-0,
21
+
* NOT 9.0.20-5...9.0.21-0 (so that the PR CP'd in 9.0.20-6 is not included in the next checklist)
// This should never happen. Just doing this to appease TS.
60
+
return'';
61
+
}
62
+
63
+
// we never want to compare a tag with itself. This check is necessary because prod deploys almost always have the same version as the last staging deploy.
64
+
// In this case, the next for wrong environment fails because the release that triggered that staging deploy is now finalized, so it looks like a prod deploy.
const BUILD_AND_DEPLOY_JOB_NAME_PREFIX = 'Build and deploy';
11506
+
/**
11507
+
* This function checks if a given release is a valid baseTag to get the PR list with `git log baseTag...endTag`.
11508
+
*
11509
+
* The rules are:
11510
+
* - production deploys can only be compared with other production deploys
11511
+
* - staging deploys can be compared with other staging deploys or production deploys.
11512
+
* The reason is that the final staging release in each deploy cycle will BECOME a production release.
11513
+
* For example, imagine a checklist is closed with version 9.0.20-6; that's the most recent staging deploy, but the release for 9.0.20-6 is now finalized, so it looks like a prod deploy.
11514
+
* When 9.0.21-0 finishes deploying to staging, the most recent prerelease is 9.0.20-5. However, we want 9.0.20-6...9.0.21-0,
11515
+
* NOT 9.0.20-5...9.0.21-0 (so that the PR CP'd in 9.0.20-6 is not included in the next checklist)
11516
+
*/
11517
+
async function isReleaseValidBaseForEnvironment(releaseTag, isProductionDeploy) {
* This function checks if a given deploy workflow is a valid basis for comparison when listing PRs merged between two versions.
11543
+
* It returns the reason a version should be skipped, or an empty string if the version should not be skipped.
11544
+
*/
11545
+
async function shouldSkipVersion(lastSuccessfulDeploy, inputTag, isProductionDeploy) {
11546
+
if (!lastSuccessfulDeploy?.head_branch) {
11547
+
// This should never happen. Just doing this to appease TS.
11548
+
return '';
11549
+
}
11550
+
// we never want to compare a tag with itself. This check is necessary because prod deploys almost always have the same version as the last staging deploy.
11551
+
// In this case, the next for wrong environment fails because the release that triggered that staging deploy is now finalized, so it looks like a prod deploy.
11552
+
if (lastSuccessfulDeploy?.head_branch === inputTag) {
11553
+
return `Same as input tag ${inputTag}`;
11554
+
}
11555
+
if (!(await isReleaseValidBaseForEnvironment(lastSuccessfulDeploy?.head_branch, isProductionDeploy))) {
11556
+
return 'Was a staging deploy, we only want to compare with other production deploys';
11557
+
}
11558
+
if (!(await wasDeploySuccessful(lastSuccessfulDeploy.id))) {
11559
+
return 'Was an unsuccessful deploy, nothing was deployed in that version';
})).data.jobs.some((job) => job.name.startsWith('Build and deploy') && job.conclusion === 'success'))) {
11536
-
console.log(`Deploy was not a success: ${lastSuccessfulDeploy.html_url}, looking at the next one`);
11537
-
lastSuccessfulDeploy = completedDeploys.shift();
11538
-
}
11539
11581
if (!lastSuccessfulDeploy) {
11540
11582
throw new Error('Could not find a prior successful deploy');
11541
11583
}
11584
+
let reason = await shouldSkipVersion(lastSuccessfulDeploy, inputTag, isProductionDeploy);
11585
+
while (lastSuccessfulDeploy && reason) {
11586
+
console.log(`Deploy of tag ${lastSuccessfulDeploy.head_branch} was not valid as a base for comparison, looking at the next one. Reason: ${reason}`, lastSuccessfulDeploy.html_url);
11587
+
lastSuccessfulDeploy = completedDeploys.shift();
11588
+
if (!lastSuccessfulDeploy) {
11589
+
throw new Error('Could not find a prior successful deploy');
0 commit comments