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

Update release versioning for snapshot releases #8389

Merged
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
2 changes: 2 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ nmHoistingLimits: none
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.6.0.cjs

npmRegistryServer: "https://registry.npmjs.org/"
2 changes: 1 addition & 1 deletion packages/eui-theme-borealis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@babel/preset-env": "^7.21.5",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.21.5",
"@elastic/eui-theme-common": "workspace:^",
"@elastic/eui-theme-common": "workspace:*",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed so that yarn replaces it during packing to an exact version instead of compatible with (^) version

"@types/chroma-js": "^2.4.0",
"@types/jest": "^29.5.12",
"@types/prettier": "2.7.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/eui-theme-common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@elastic/eui-theme-common",
"version": "0.0.9",
"version": "0.0.11",
Copy link
Member Author

@tkajtoch tkajtoch Mar 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last eui-theme-common version update was not committed. I must've forgotten to include it when doing it manually.

"description": "EUI theme common",
"license": "SEE LICENSE IN LICENSE.txt",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions packages/eui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"url": "https://github.com/elastic/eui.git"
},
"dependencies": {
"@elastic/eui-theme-common": "workspace:^",
"@elastic/eui-theme-common": "workspace:*",
"@elastic/prismjs-esql": "^1.0.0",
"@hello-pangea/dnd": "^16.6.0",
"@types/lodash": "^4.14.202",
Expand Down Expand Up @@ -106,7 +106,7 @@
"@cypress/webpack-dev-server": "^1.7.0",
"@elastic/charts": "^64.1.0",
"@elastic/datemath": "^5.0.3",
"@elastic/eui-theme-borealis": "workspace:^",
"@elastic/eui-theme-borealis": "workspace:*",
"@emotion/babel-preset-css-prop": "^11.11.0",
"@emotion/cache": "^11.11.0",
"@emotion/css": "^11.11.0",
Expand Down
89 changes: 52 additions & 37 deletions packages/release-cli/src/steps/update_versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import {
deleteObsoleteChangelogs,
updateChangelogContent,
} from '../update_changelog';
import { getUpcomingVersion, getVersionTypeFromChangelog } from '../version';
import {
getUniqueSnapshotId,
getUpcomingSnapshotVersion,
getUpcomingVersion,
getVersionTypeFromChangelog,
} from '../version';
import { commitFiles, isFileAddedToGit, stageFiles } from '../git_utils';

/**
Expand All @@ -37,49 +42,57 @@ export const stepUpdateVersions = async (
const filesToCommit: string[] = [];
const changedWorkspaces: YarnWorkspace[] = [];
const rootWorkspaceDir = getRootWorkspaceDir();
const snapshotId = getUniqueSnapshotId();

for (const workspace of workspaces) {
logger.debug(`Calculating changes in ${workspace.name}`);

const workspaceDir = path.join(rootWorkspaceDir, workspace.location);
const currentVersion = await getWorkspacePackageVersion(workspaceDir);

const { changelogMap, changelog, hasChanges, processedChangelogFiles } =
await collateChangelogFiles(workspaceDir);
if (options.type === 'snapshot') {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be done better and moved to separate functions but we can clean it up later

const newVersion = getUpcomingSnapshotVersion(currentVersion, snapshotId);
await updateWorkspaceVersion(workspace.name, newVersion);

if (!hasChanges) {
logger.debug(`[${workspace.name}] No changes detected`);
continue;
}
logger.info(`[${workspace.name}] Updating version ${currentVersion} -> ${newVersion}`);
} else {
const { changelogMap, changelog, hasChanges, processedChangelogFiles } =
await collateChangelogFiles(workspaceDir);

const versionType = getVersionTypeFromChangelog(changelogMap);
const newVersion = getUpcomingVersion(currentVersion, versionType);
if (!hasChanges) {
logger.debug(`[${workspace.name}] No changes detected`);
continue;
}

const statsStr = Object.entries(changelogMap)
.filter(([_, items]) => items.length)
.map(([name, items]) => `${items.length} ${name.toLowerCase()}`);
const versionType = getVersionTypeFromChangelog(changelogMap);
const newVersion = getUpcomingVersion(currentVersion, versionType);

logger.info(
`[${workspace.name}] Updating version ${currentVersion} -> ${newVersion} (${versionType} update; ${statsStr})`
);
const statsStr = Object.entries(changelogMap)
.filter(([_, items]) => items.length)
.map(([name, items]) => `${items.length} ${name.toLowerCase()}`);

const updatedYearChangelogPath = await updateChangelogContent(
workspaceDir,
changelog,
newVersion
);
await deleteObsoleteChangelogs(processedChangelogFiles);
logger.info(
`[${workspace.name}] Updating version ${currentVersion} -> ${newVersion} (${versionType} update; ${statsStr})`
);

// Update package.json version string
await updateWorkspaceVersion(workspace.name, newVersion);
const updatedYearChangelogPath = await updateChangelogContent(
workspaceDir,
changelog,
newVersion
);
await deleteObsoleteChangelogs(processedChangelogFiles);

filesToCommit.push(getWorkspacePackageJsonPath(workspaceDir));
filesToCommit.push(updatedYearChangelogPath);
// Update package.json version string
await updateWorkspaceVersion(workspace.name, newVersion);

// Only stage and commit changelog files that are added to git (versioned)
for (const file of processedChangelogFiles) {
if (await isFileAddedToGit(file)) {
filesToCommit.push(file);
filesToCommit.push(getWorkspacePackageJsonPath(workspaceDir));
filesToCommit.push(updatedYearChangelogPath);

// Only stage and commit changelog files that are added to git (versioned)
for (const file of processedChangelogFiles) {
if (await isFileAddedToGit(file)) {
filesToCommit.push(file);
}
}
}

Expand All @@ -90,16 +103,18 @@ export const stepUpdateVersions = async (
throw new Error('There are no changes to release');
}

// Stage yarn.lock changes
const yarnLockPath = path.join(rootWorkspaceDir, 'yarn.lock');
filesToCommit.push(yarnLockPath);
await stageFiles([yarnLockPath]);
if (options.type !== 'snapshot') {
// Stage yarn.lock changes
const yarnLockPath = path.join(rootWorkspaceDir, 'yarn.lock');
filesToCommit.push(yarnLockPath);
await stageFiles([yarnLockPath]);

// Stage updated package.json files
await stageFiles(filesToCommit);
// Stage updated package.json files
await stageFiles(filesToCommit);

// Commit all package.json files and yarn.lock
await commitFiles('chore: update package versions [skip ci]', filesToCommit);
// Commit all package.json files and yarn.lock
await commitFiles('chore: update package versions [skip ci]', filesToCommit);
}

return changedWorkspaces;
};
10 changes: 10 additions & 0 deletions packages/release-cli/src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ export const getUpcomingVersion = (currentVersion: string, target: string): stri
return [major, minor, patch].join('.');
};

export const getUpcomingSnapshotVersion = (currentVersion: string, uniqueId: string): string => {
// remove preid part of the version string if exists
const [version, _] = currentVersion.split('-');
return `${version}-snapshot.${uniqueId}`;
};

export const getUniqueSnapshotId = () => {
return Date.now().toString();
}

export const getVersionTypeFromChangelog = (changelogMap: ChangelogMap): VersionType => {
const hasFeatures = changelogMap['Features'].length > 0;
const hasBugFixes = changelogMap['Bug fixes'].length > 0;
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4672,7 +4672,7 @@ __metadata:
languageName: unknown
linkType: soft

"@elastic/eui-theme-borealis@workspace:^, @elastic/eui-theme-borealis@workspace:packages/eui-theme-borealis":
"@elastic/eui-theme-borealis@workspace:*, @elastic/eui-theme-borealis@workspace:^, @elastic/eui-theme-borealis@workspace:packages/eui-theme-borealis":
version: 0.0.0-use.local
resolution: "@elastic/eui-theme-borealis@workspace:packages/eui-theme-borealis"
dependencies:
Expand All @@ -4681,7 +4681,7 @@ __metadata:
"@babel/preset-env": "npm:^7.21.5"
"@babel/preset-react": "npm:^7.18.6"
"@babel/preset-typescript": "npm:^7.21.5"
"@elastic/eui-theme-common": "workspace:^"
"@elastic/eui-theme-common": "workspace:*"
"@types/chroma-js": "npm:^2.4.0"
"@types/jest": "npm:^29.5.12"
"@types/prettier": "npm:2.7.3"
Expand All @@ -4706,7 +4706,7 @@ __metadata:
languageName: unknown
linkType: soft

"@elastic/eui-theme-common@workspace:^, @elastic/eui-theme-common@workspace:packages/eui-theme-common":
"@elastic/eui-theme-common@workspace:*, @elastic/eui-theme-common@workspace:^, @elastic/eui-theme-common@workspace:packages/eui-theme-common":
version: 0.0.0-use.local
resolution: "@elastic/eui-theme-common@workspace:packages/eui-theme-common"
dependencies:
Expand Down Expand Up @@ -4822,8 +4822,8 @@ __metadata:
"@cypress/webpack-dev-server": "npm:^1.7.0"
"@elastic/charts": "npm:^64.1.0"
"@elastic/datemath": "npm:^5.0.3"
"@elastic/eui-theme-borealis": "workspace:^"
"@elastic/eui-theme-common": "workspace:^"
"@elastic/eui-theme-borealis": "workspace:*"
"@elastic/eui-theme-common": "workspace:*"
"@elastic/prismjs-esql": "npm:^1.0.0"
"@emotion/babel-preset-css-prop": "npm:^11.11.0"
"@emotion/cache": "npm:^11.11.0"
Expand Down
Loading