From caa7f9808f48be05268bce4f598156f0a9a46cf3 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Wed, 9 Sep 2020 14:48:11 +0200 Subject: [PATCH] feat(dev-infra): add logic for determining active LTS branches (#38656) Adds logic for determining active LTS branches for a given release configuration. The active LTS branches can be determined by querying NPM and matching dist tags against a specific pattern. i.e. `v{major}-lts`. This logic will be useful for the release tool that supports publishing of active LTS version branches. PR Close #38656 --- .../release/versioning/long-term-support.ts | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/dev-infra/release/versioning/long-term-support.ts b/dev-infra/release/versioning/long-term-support.ts index 379fbb9b0e..4dc33c37d9 100644 --- a/dev-infra/release/versioning/long-term-support.ts +++ b/dev-infra/release/versioning/long-term-support.ts @@ -6,6 +6,30 @@ * found in the LICENSE file at https://angular.io/license */ +import * as semver from 'semver'; + +import {ReleaseConfig} from '../config/index'; + +import {fetchProjectNpmPackageInfo} from './npm-registry'; + +/** Interface describing determined LTS branches. */ +export interface LtsBranches { + /** List of active LTS version branches. */ + active: LtsBranch[]; + /** List of inactive LTS version branches. */ + inactive: LtsBranch[]; +} + +/** Interface describing an LTS version branch. */ +export interface LtsBranch { + /** Name of the branch. */ + name: string; + /** Most recent version for the given LTS branch. */ + version: semver.SemVer; + /** NPM dist tag for the LTS version. */ + npmDistTag: string; +} + /** * Number of months a major version in Angular is actively supported. See: * https://angular.io/guide/releases#support-policy-and-schedule. @@ -18,6 +42,44 @@ export const majorActiveSupportDuration = 6; */ export const majorActiveTermSupportDuration = 12; +/** Regular expression that matches LTS NPM dist tags. */ +export const ltsNpmDistTagRegex = /^v(\d+)-lts$/; + +/** Finds all long-term support release trains from the specified NPM package. */ +export async function fetchLongTermSupportBranchesFromNpm(config: ReleaseConfig): + Promise { + const {'dist-tags': distTags, time} = await fetchProjectNpmPackageInfo(config); + const today = new Date(); + const active: LtsBranch[] = []; + const inactive: LtsBranch[] = []; + + // Iterate through the NPM package information and determine active/inactive LTS versions with + // their corresponding branches. We assume that a LTS tagged version in NPM belongs to the + // last-minor branch of a given major (i.e. we assume there are no outdated LTS NPM dist tags). + for (const npmDistTag in distTags) { + if (ltsNpmDistTagRegex.test(npmDistTag)) { + const version = semver.parse(distTags[npmDistTag])!; + const branchName = `${version.major}.${version.minor}.x`; + const majorReleaseDate = new Date(time[`${version.major}.0.0`]); + const ltsEndDate = computeLtsEndDateOfMajor(majorReleaseDate); + const ltsBranch: LtsBranch = {name: branchName, version, npmDistTag}; + // Depending on whether the LTS phase is still active, add the branch + // the list of active or inactive LTS branches. + if (today <= ltsEndDate) { + active.push(ltsBranch); + } else { + inactive.push(ltsBranch); + } + } + } + + // Sort LTS branches in descending order. i.e. most recent ones first. + active.sort((a, b) => semver.rcompare(a.version, b.version)); + inactive.sort((a, b) => semver.rcompare(a.version, b.version)); + + return {active, inactive}; +} + /** * Computes the date when long-term support ends for a major released at the * specified date.