( repo: ReleaseRepoWithApi, releaseConfig: ReleaseConfig, branchName: string, )
| 31 | * @param branchName Branch that is checked to be an active LTS version-branch. |
| 32 | * */ |
| 33 | export async function assertActiveLtsBranch( |
| 34 | repo: ReleaseRepoWithApi, |
| 35 | releaseConfig: ReleaseConfig, |
| 36 | branchName: string, |
| 37 | ) { |
| 38 | const {version} = await getVersionInfoForBranch(repo, branchName); |
| 39 | const {'dist-tags': distTags, time} = await fetchProjectNpmPackageInfo(releaseConfig); |
| 40 | |
| 41 | // LTS versions should be tagged in NPM in the following format: `v{major}-lts`. |
| 42 | const ltsNpmTag = getLtsNpmDistTagOfMajor(version.major); |
| 43 | const ltsVersion = semver.parse(distTags[ltsNpmTag]); |
| 44 | |
| 45 | // Ensure that there is an LTS version tagged for the given version-branch major. e.g. |
| 46 | // if the version branch is `9.2.x` then we want to make sure that there is an LTS |
| 47 | // version tagged in NPM for `v9`, following the `v{major}-lts` tag convention. |
| 48 | if (ltsVersion === null) { |
| 49 | throw new InvalidTargetBranchError(`No LTS version tagged for v${version.major} in NPM.`); |
| 50 | } |
| 51 | |
| 52 | // Ensure that the correct branch is used for the LTS version. We do not want to merge |
| 53 | // changes to older minor version branches that do not reflect the current LTS version. |
| 54 | if (branchName !== `${ltsVersion.major}.${ltsVersion.minor}.x`) { |
| 55 | throw new InvalidTargetBranchError( |
| 56 | `Not using last-minor branch for v${version.major} LTS version. PR ` + |
| 57 | `should be updated to target: ${ltsVersion.major}.${ltsVersion.minor}.x`, |
| 58 | ); |
| 59 | } |
| 60 | |
| 61 | const today = new Date(); |
| 62 | const majorReleaseDate = new Date(time[`${version.major}.0.0`]); |
| 63 | const ltsEndDate = computeLtsEndDateOfMajor(majorReleaseDate); |
| 64 | |
| 65 | // Check if LTS has already expired for the targeted major version. If so, we do not |
| 66 | // allow the merge as per our LTS guarantees. Can be forcibly overridden if desired. |
| 67 | // See: https://angular.io/guide/releases#support-policy-and-schedule. |
| 68 | if (today > ltsEndDate) { |
| 69 | const ltsEndDateText = ltsEndDate.toLocaleDateString(defaultLocale); |
| 70 | Log.warn(red(`Long-term support ended for v${version.major} on ${ltsEndDateText}.`)); |
| 71 | Log.warn( |
| 72 | yellow( |
| 73 | `Merging of pull requests for this major is generally not ` + |
| 74 | `desired, but can be forcibly ignored.`, |
| 75 | ), |
| 76 | ); |
| 77 | if (await Prompt.confirm({message: 'Do you want to forcibly proceed with merging?'})) { |
| 78 | return; |
| 79 | } |
| 80 | throw new InvalidTargetBranchError( |
| 81 | `Long-term supported ended for v${version.major} on ${ltsEndDateText}. ` + |
| 82 | `Pull request cannot be merged into the ${branchName} branch.`, |
| 83 | ); |
| 84 | } |
| 85 | } |
no test coverage detected