Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: publish latest version as well #8017

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion scripts/publish-canary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down
22 changes: 15 additions & 7 deletions scripts/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -29,7 +30,7 @@ const path = getValueByFlag<string>('--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`,
Expand All @@ -40,16 +41,23 @@ const path = getValueByFlag<string>('--path', '');
successLog(`+${packageJson.name}@${version} is published successfully`);
})();

function makeTag(version: string, versions: string[]): string {
function makeTag(version: string): string {
const customTag = getValueByFlag<string>('--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}`;
}
5 changes: 2 additions & 3 deletions scripts/shared/bump-version.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
9 changes: 9 additions & 0 deletions scripts/shared/get-all-tags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {execute} from './execute';

export function getAllTags(name: string): Record<string, string> {
try {
return JSON.parse(execute(`npm view ${name} dist-tags --json || echo "{}"`, {}));
} catch {
return {};
}
}
3 changes: 0 additions & 3 deletions scripts/shared/get-last-major-version.ts

This file was deleted.

14 changes: 14 additions & 0 deletions scripts/shared/parse-version.ts
Original file line number Diff line number Diff line change
@@ -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};
}
Loading