diff --git a/clients/algoliasearch-client-javascript/package.json b/clients/algoliasearch-client-javascript/package.json index c98a3dcda7..d345e0cf40 100644 --- a/clients/algoliasearch-client-javascript/package.json +++ b/clients/algoliasearch-client-javascript/package.json @@ -8,7 +8,6 @@ "scripts": { "build": "lerna run build --scope '@algolia/requester-testing' --scope '@algolia/logger-console' --scope 'algoliasearch' --scope '@algolia/client-composition' --include-dependencies", "clean": "lerna run clean", - "release:bump": "lerna version ${0:-patch} --no-changelog --no-git-tag-version --no-push --exact --force-publish --yes", "release:publish": "tsc --project scripts/tsconfig.json && node scripts/dist/scripts/publish.js", "test": "lerna run test $*", "test:size": "bundlesize", diff --git a/scripts/release/createReleasePR.ts b/scripts/release/createReleasePR.ts index ac6fb51691..dedae88b4a 100755 --- a/scripts/release/createReleasePR.ts +++ b/scripts/release/createReleasePR.ts @@ -46,7 +46,7 @@ const fetchedUsers: Record = {}; export function getVersionChangesText(versions: Versions): string { return LANGUAGES.map((lang) => { - if (!versions[lang]) { + if (!versions[lang]?.next) { return `- ~${lang}: ${getPackageVersionDefault(lang)} (no commit)~`; } diff --git a/scripts/release/dart.ts b/scripts/release/dart.ts new file mode 100644 index 0000000000..31d35bcad1 --- /dev/null +++ b/scripts/release/dart.ts @@ -0,0 +1,90 @@ +import fsp from 'fs/promises'; + +import yaml from 'js-yaml'; + +import clientsConfig from '../../config/clients.config.json' assert { type: 'json' }; +import { GENERATORS, toAbsolutePath } from '../common.js'; + +import { writeJsonFile } from './common.js'; +import { updateChangelog } from './updateAPIVersions.js'; + +/** + * Updates packages versions and generates the changelog. + */ +export async function updateDartPackages(changelog: string, nextVersion: string): Promise { + for (const gen of Object.values(GENERATORS)) { + if (gen.language !== 'dart') { + continue; + } + + if (!nextVersion) { + throw new Error(`Failed to bump '${gen.packageName}'.`); + } + + let currentVersion = await getPubspecField(gen.output, 'version'); + + // if there's no version then it mostly means it's a new client. + if (!currentVersion) { + currentVersion = '0.0.1'; + } + + await updateChangelog('dart', changelog, currentVersion, nextVersion, toAbsolutePath(`${gen.output}/CHANGELOG.md`)); + } + + // Version is sync'd on every clients so we set it once. + clientsConfig.dart.packageVersion = nextVersion; + + // update `clients.config.json` file for the utils version. + await writeJsonFile(toAbsolutePath('config/clients.config.json'), clientsConfig); + + // Core client package path + const corePackagePath = 'clients/algoliasearch-client-dart/packages/client_core'; + + // fetch the version from the pubspec file of the core package + let currentCoreVersion = await getPubspecField(corePackagePath, 'version'); + if (!currentCoreVersion) { + currentCoreVersion = '0.0.1'; + } + + // update the changelog for core package + await updateChangelog( + 'dart', + changelog, + currentCoreVersion, + nextVersion, + toAbsolutePath(`${corePackagePath}/CHANGELOG.md`), + ); + + // we've bumped generated clients but still need to do the manual ones. + await bumpPubspecVersion(toAbsolutePath(`${corePackagePath}/pubspec.yaml`), nextVersion); +} + +/** + * Get 'version' from pubspec.yaml file. + */ +async function getPubspecField(filePath: string, field: string): Promise { + try { + const fileContent = await fsp.readFile(toAbsolutePath(`${filePath}/pubspec.yaml`), 'utf8'); + const pubspec = yaml.load(fileContent) as Record; + + return pubspec[field]; + } catch (error) { + throw new Error(`Error reading file ${filePath}: ${error}`); + } +} + +/** + * Bump 'version' of the given pubspec.yaml file path. + */ +async function bumpPubspecVersion(filePath: string, nextVersion: string): Promise { + try { + const fileContent = await fsp.readFile(toAbsolutePath(filePath), 'utf8'); + const pubspec = yaml.load(fileContent) as Record; + + pubspec.version = nextVersion; + + await fsp.writeFile(filePath, yaml.dump(pubspec)); + } catch (error) { + throw new Error(`Error writing file ${filePath}: ${error}`); + } +} diff --git a/scripts/release/javascript.ts b/scripts/release/javascript.ts new file mode 100644 index 0000000000..b5e079615b --- /dev/null +++ b/scripts/release/javascript.ts @@ -0,0 +1,16 @@ +import { ReleaseType } from 'semver'; +import { run } from '../common.js'; +import { getLanguageFolder } from '../config.js'; +import { isPreRelease } from './versionsHistory.js'; + +export async function updateJavaScriptPackages(releaseType: ReleaseType) { + const cwd = getLanguageFolder('javascript'); + const packages = JSON.parse(await run('yarn lerna ls --json --all --loglevel silent', { cwd })) as Array<{ + version: string; + location: string; + }>; + + for (const pkg of packages) { + await run(`yarn version ${isPreRelease(pkg.version) ? 'prerelease' : releaseType}`, { cwd: pkg.location }); + } +} diff --git a/scripts/release/updateAPIVersions.ts b/scripts/release/updateAPIVersions.ts index 15d3b4ded2..a35ba543cb 100755 --- a/scripts/release/updateAPIVersions.ts +++ b/scripts/release/updateAPIVersions.ts @@ -1,13 +1,13 @@ import fsp from 'fs/promises'; -import yaml from 'js-yaml'; - import clientsConfig from '../../config/clients.config.json' assert { type: 'json' }; -import { CI, exists, GENERATORS, run, setVerbose, toAbsolutePath } from '../common.js'; +import { CI, exists, setVerbose, toAbsolutePath } from '../common.js'; import { getGitHubUrl, getLanguageFolder } from '../config.js'; import type { Language } from '../types.js'; import { writeJsonFile } from './common.js'; +import { updateDartPackages } from './dart.js'; +import { updateJavaScriptPackages } from './javascript.js'; import type { Changelog, Versions } from './types.js'; async function updateConfigFiles(versionsToRelease: Versions): Promise { @@ -21,7 +21,7 @@ async function updateConfigFiles(versionsToRelease: Versions): Promise { await writeJsonFile(toAbsolutePath('config/clients.config.json'), clientsConfig); } -async function updateChangelog( +export async function updateChangelog( lang: Language, changelog: string, current: string, @@ -58,11 +58,9 @@ export async function updateAPIVersions(versions: Versions, changelog: Changelog continue; } - if (lang === 'javascript') { + if (lang === 'javascript' && releaseType) { setVerbose(CI); - await run(`yarn install && yarn release:bump ${releaseType}`, { - cwd: getLanguageFolder(lang), - }); + await updateJavaScriptPackages(releaseType); } await updateChangelog( @@ -74,84 +72,3 @@ export async function updateAPIVersions(versions: Versions, changelog: Changelog ); } } - -/** - * Updates packages versions and generates the changelog. - */ -async function updateDartPackages(changelog: string, nextVersion: string): Promise { - for (const gen of Object.values(GENERATORS)) { - if (gen.language !== 'dart') { - continue; - } - - if (!nextVersion) { - throw new Error(`Failed to bump '${gen.packageName}'.`); - } - - let currentVersion = await getPubspecField(gen.output, 'version'); - - // if there's no version then it mostly means it's a new client. - if (!currentVersion) { - currentVersion = '0.0.1'; - } - - await updateChangelog('dart', changelog, currentVersion, nextVersion, toAbsolutePath(`${gen.output}/CHANGELOG.md`)); - } - - // Version is sync'd on every clients so we set it once. - clientsConfig.dart.packageVersion = nextVersion; - - // update `clients.config.json` file for the utils version. - await writeJsonFile(toAbsolutePath('config/clients.config.json'), clientsConfig); - - // Core client package path - const corePackagePath = 'clients/algoliasearch-client-dart/packages/client_core'; - - // fetch the version from the pubspec file of the core package - let currentCoreVersion = await getPubspecField(corePackagePath, 'version'); - if (!currentCoreVersion) { - currentCoreVersion = '0.0.1'; - } - - // update the changelog for core package - await updateChangelog( - 'dart', - changelog, - currentCoreVersion, - nextVersion, - toAbsolutePath(`${corePackagePath}/CHANGELOG.md`), - ); - - // we've bumped generated clients but still need to do the manual ones. - await bumpPubspecVersion(toAbsolutePath(`${corePackagePath}/pubspec.yaml`), nextVersion); -} - -/** - * Get 'version' from pubspec.yaml file. - */ -async function getPubspecField(filePath: string, field: string): Promise { - try { - const fileContent = await fsp.readFile(toAbsolutePath(`${filePath}/pubspec.yaml`), 'utf8'); - const pubspec = yaml.load(fileContent) as Record; - - return pubspec[field]; - } catch (error) { - throw new Error(`Error reading file ${filePath}: ${error}`); - } -} - -/** - * Bump 'version' of the given pubspec.yaml file path. - */ -async function bumpPubspecVersion(filePath: string, nextVersion: string): Promise { - try { - const fileContent = await fsp.readFile(toAbsolutePath(filePath), 'utf8'); - const pubspec = yaml.load(fileContent) as Record; - - pubspec.version = nextVersion; - - await fsp.writeFile(filePath, yaml.dump(pubspec)); - } catch (error) { - throw new Error(`Error writing file ${filePath}: ${error}`); - } -}