From eee4924fab8193483cac86bc45f50cffdf50e3c8 Mon Sep 17 00:00:00 2001 From: splincode Date: Tue, 2 Jul 2024 16:06:20 +0300 Subject: [PATCH] ci: publish latest version as well --- scripts/publish-canary.ts | 3 ++- scripts/publish.ts | 22 +++++++++++++++------- scripts/shared/bump-version.ts | 5 ++--- scripts/shared/get-all-tags.ts | 9 +++++++++ scripts/shared/get-last-major-version.ts | 3 --- scripts/shared/parse-version.ts | 14 ++++++++++++++ 6 files changed, 42 insertions(+), 14 deletions(-) create mode 100644 scripts/shared/get-all-tags.ts delete mode 100644 scripts/shared/get-last-major-version.ts create mode 100644 scripts/shared/parse-version.ts diff --git a/scripts/publish-canary.ts b/scripts/publish-canary.ts index baa7efba5fb5..e2bead9533e9 100644 --- a/scripts/publish-canary.ts +++ b/scripts/publish-canary.ts @@ -5,12 +5,13 @@ import {infoLog} from '../projects/cdk/schematics/utils/colored-log'; import {execute} from './shared/execute'; import {IGNORABLE_TAIGA_PACKAGES} from './shared/ignorable-packages'; import {overwriteVersion} from './shared/overwrite-version'; +import {parseVersion} from './shared/parse-version'; import {syncVersions} from './shared/sync-versions'; (function main(): void { const type = 'canary'; const commit = execute('git rev-parse HEAD', {}).slice(0, 7); - const [major, minor, patch] = version.split(/[.-]/) as [string, string, string]; + const {major, minor, patch} = parseVersion(version); // construct new version from base version x.y.z to become x.y.z-{type}.{shortSha} const newVersion = `${major}.${minor}.${patch}-${type}.${commit}`; diff --git a/scripts/publish.ts b/scripts/publish.ts index 5ebb02d02bf2..f214a97b0d0b 100644 --- a/scripts/publish.ts +++ b/scripts/publish.ts @@ -7,8 +7,9 @@ import { } from '../projects/cdk/schematics/utils/colored-log'; import {getValueByFlag} from './shared/argv.utils'; import {execute} from './shared/execute'; +import {getAllTags} from './shared/get-all-tags'; import {getAllVersions} from './shared/get-all-versions'; -import {getLastMajorVersion} from './shared/get-last-major-version'; +import {parseVersion} from './shared/parse-version'; const isDryRun = getValueByFlag<'false' | 'true' | 'undefined'>('--dry-run', 'false') === 'true'; @@ -29,7 +30,7 @@ const path = getValueByFlag('--path', ''); infoLog(`version: ${version}`); const dry = isDryRun ? '--dry-run' : ''; - const tag = makeTag(version, versions); + const tag = makeTag(version); execute( `cd ${path} && npm version ${version} --allow-same-version --no-git-tag-version`, @@ -40,16 +41,23 @@ const path = getValueByFlag('--path', ''); successLog(`+${packageJson.name}@${version} is published successfully`); })(); -function makeTag(version: string, versions: string[]): string { +function makeTag(version: string): string { const customTag = getValueByFlag('--customTag', ''); if (customTag !== '') { return `--tag ${customTag}`; } - const currentMajor = parseInt(version, 10); - const maxMajorVersion = getLastMajorVersion(versions, currentMajor); - const tagFlag = maxMajorVersion > currentMajor ? `--tag v${currentMajor}-lts` : ''; + if (version.includes('rc')) { + return '--tag next --pre-id rc'; + } + + const baseLatestTag = getAllTags('@taiga-ui/core').latest; + const currentMajor = parseVersion(version).major; + const latestOrLTS = + parseVersion(baseLatestTag).major === currentMajor + ? 'latest' + : `v${currentMajor}-lts`; - return version.includes('rc') ? '--tag next' : tagFlag; + return `--tag ${latestOrLTS}`; } diff --git a/scripts/shared/bump-version.ts b/scripts/shared/bump-version.ts index 9f0255aeef6c..ec52d009189c 100644 --- a/scripts/shared/bump-version.ts +++ b/scripts/shared/bump-version.ts @@ -1,9 +1,8 @@ +import {parseVersion} from './parse-version'; import {TuiReleaseMode} from './release-mode'; export function bumpVersion(version: string, mode: TuiReleaseMode): string { - let [major, minor, patch, , rc = -1] = version - .split(/[.-]/) - .map(value => Number(value)); + let {major, minor, patch, rc} = parseVersion(version); if (rc !== -1 && mode !== 'major' && mode !== 'prerelease') { throw new Error( diff --git a/scripts/shared/get-all-tags.ts b/scripts/shared/get-all-tags.ts new file mode 100644 index 000000000000..0fec2777aa72 --- /dev/null +++ b/scripts/shared/get-all-tags.ts @@ -0,0 +1,9 @@ +import {execute} from './execute'; + +export function getAllTags(name: string): Record { + try { + return JSON.parse(execute(`npm view ${name} dist-tags --json || echo "{}"`, {})); + } catch { + return {}; + } +} diff --git a/scripts/shared/get-last-major-version.ts b/scripts/shared/get-last-major-version.ts deleted file mode 100644 index 6058659b868c..000000000000 --- a/scripts/shared/get-last-major-version.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function getLastMajorVersion(versions: string[], currentMajor: number): number { - return Math.max(...versions.map(x => parseInt(x, 10)), currentMajor); -} diff --git a/scripts/shared/parse-version.ts b/scripts/shared/parse-version.ts new file mode 100644 index 000000000000..af7688c31ad5 --- /dev/null +++ b/scripts/shared/parse-version.ts @@ -0,0 +1,14 @@ +interface ParsedVersion { + major: number; + minor: number; + patch: number; + rc: number; +} + +export function parseVersion(version: string): ParsedVersion { + const [major, minor, patch, , rc = -1] = version + .split(/[.-]/) + .map(value => Number(value)); + + return {major, minor, patch, rc}; +}