Skip to content

Commit 66acf19

Browse files
authoredNov 14, 2024··
fix(scripts): dart and js releases [skip-bc] (#4104)
1 parent c11f209 commit 66acf19

File tree

5 files changed

+113
-91
lines changed

5 files changed

+113
-91
lines changed
 

Diff for: ‎clients/algoliasearch-client-javascript/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"scripts": {
99
"build": "lerna run build --scope '@algolia/requester-testing' --scope '@algolia/logger-console' --scope 'algoliasearch' --scope '@algolia/client-composition' --include-dependencies",
1010
"clean": "lerna run clean",
11-
"release:bump": "lerna version ${0:-patch} --no-changelog --no-git-tag-version --no-push --exact --force-publish --yes",
1211
"release:publish": "tsc --project scripts/tsconfig.json && node scripts/dist/scripts/publish.js",
1312
"test": "lerna run test $*",
1413
"test:size": "bundlesize",

Diff for: ‎scripts/release/createReleasePR.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const fetchedUsers: Record<string, string> = {};
4646

4747
export function getVersionChangesText(versions: Versions): string {
4848
return LANGUAGES.map((lang) => {
49-
if (!versions[lang]) {
49+
if (!versions[lang]?.next) {
5050
return `- ~${lang}: ${getPackageVersionDefault(lang)} (no commit)~`;
5151
}
5252

Diff for: ‎scripts/release/dart.ts

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import fsp from 'fs/promises';
2+
3+
import yaml from 'js-yaml';
4+
5+
import clientsConfig from '../../config/clients.config.json' assert { type: 'json' };
6+
import { GENERATORS, toAbsolutePath } from '../common.js';
7+
8+
import { writeJsonFile } from './common.js';
9+
import { updateChangelog } from './updateAPIVersions.js';
10+
11+
/**
12+
* Updates packages versions and generates the changelog.
13+
*/
14+
export async function updateDartPackages(changelog: string, nextVersion: string): Promise<void> {
15+
for (const gen of Object.values(GENERATORS)) {
16+
if (gen.language !== 'dart') {
17+
continue;
18+
}
19+
20+
if (!nextVersion) {
21+
throw new Error(`Failed to bump '${gen.packageName}'.`);
22+
}
23+
24+
let currentVersion = await getPubspecField(gen.output, 'version');
25+
26+
// if there's no version then it mostly means it's a new client.
27+
if (!currentVersion) {
28+
currentVersion = '0.0.1';
29+
}
30+
31+
await updateChangelog('dart', changelog, currentVersion, nextVersion, toAbsolutePath(`${gen.output}/CHANGELOG.md`));
32+
}
33+
34+
// Version is sync'd on every clients so we set it once.
35+
clientsConfig.dart.packageVersion = nextVersion;
36+
37+
// update `clients.config.json` file for the utils version.
38+
await writeJsonFile(toAbsolutePath('config/clients.config.json'), clientsConfig);
39+
40+
// Core client package path
41+
const corePackagePath = 'clients/algoliasearch-client-dart/packages/client_core';
42+
43+
// fetch the version from the pubspec file of the core package
44+
let currentCoreVersion = await getPubspecField(corePackagePath, 'version');
45+
if (!currentCoreVersion) {
46+
currentCoreVersion = '0.0.1';
47+
}
48+
49+
// update the changelog for core package
50+
await updateChangelog(
51+
'dart',
52+
changelog,
53+
currentCoreVersion,
54+
nextVersion,
55+
toAbsolutePath(`${corePackagePath}/CHANGELOG.md`),
56+
);
57+
58+
// we've bumped generated clients but still need to do the manual ones.
59+
await bumpPubspecVersion(toAbsolutePath(`${corePackagePath}/pubspec.yaml`), nextVersion);
60+
}
61+
62+
/**
63+
* Get 'version' from pubspec.yaml file.
64+
*/
65+
async function getPubspecField(filePath: string, field: string): Promise<string | undefined> {
66+
try {
67+
const fileContent = await fsp.readFile(toAbsolutePath(`${filePath}/pubspec.yaml`), 'utf8');
68+
const pubspec = yaml.load(fileContent) as Record<string, any>;
69+
70+
return pubspec[field];
71+
} catch (error) {
72+
throw new Error(`Error reading file ${filePath}: ${error}`);
73+
}
74+
}
75+
76+
/**
77+
* Bump 'version' of the given pubspec.yaml file path.
78+
*/
79+
async function bumpPubspecVersion(filePath: string, nextVersion: string): Promise<void> {
80+
try {
81+
const fileContent = await fsp.readFile(toAbsolutePath(filePath), 'utf8');
82+
const pubspec = yaml.load(fileContent) as Record<string, any>;
83+
84+
pubspec.version = nextVersion;
85+
86+
await fsp.writeFile(filePath, yaml.dump(pubspec));
87+
} catch (error) {
88+
throw new Error(`Error writing file ${filePath}: ${error}`);
89+
}
90+
}

Diff for: ‎scripts/release/javascript.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ReleaseType } from 'semver';
2+
import { run } from '../common.js';
3+
import { getLanguageFolder } from '../config.js';
4+
import { isPreRelease } from './versionsHistory.js';
5+
6+
export async function updateJavaScriptPackages(releaseType: ReleaseType) {
7+
const cwd = getLanguageFolder('javascript');
8+
const packages = JSON.parse(await run('yarn lerna ls --json --all --loglevel silent', { cwd })) as Array<{
9+
version: string;
10+
location: string;
11+
}>;
12+
13+
for (const pkg of packages) {
14+
await run(`yarn version ${isPreRelease(pkg.version) ? 'prerelease' : releaseType}`, { cwd: pkg.location });
15+
}
16+
}

Diff for: ‎scripts/release/updateAPIVersions.ts

+6-89
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import fsp from 'fs/promises';
22

3-
import yaml from 'js-yaml';
4-
53
import clientsConfig from '../../config/clients.config.json' assert { type: 'json' };
6-
import { CI, exists, GENERATORS, run, setVerbose, toAbsolutePath } from '../common.js';
4+
import { CI, exists, setVerbose, toAbsolutePath } from '../common.js';
75
import { getGitHubUrl, getLanguageFolder } from '../config.js';
86
import type { Language } from '../types.js';
97

108
import { writeJsonFile } from './common.js';
9+
import { updateDartPackages } from './dart.js';
10+
import { updateJavaScriptPackages } from './javascript.js';
1111
import type { Changelog, Versions } from './types.js';
1212

1313
async function updateConfigFiles(versionsToRelease: Versions): Promise<void> {
@@ -21,7 +21,7 @@ async function updateConfigFiles(versionsToRelease: Versions): Promise<void> {
2121
await writeJsonFile(toAbsolutePath('config/clients.config.json'), clientsConfig);
2222
}
2323

24-
async function updateChangelog(
24+
export async function updateChangelog(
2525
lang: Language,
2626
changelog: string,
2727
current: string,
@@ -58,11 +58,9 @@ export async function updateAPIVersions(versions: Versions, changelog: Changelog
5858
continue;
5959
}
6060

61-
if (lang === 'javascript') {
61+
if (lang === 'javascript' && releaseType) {
6262
setVerbose(CI);
63-
await run(`yarn install && yarn release:bump ${releaseType}`, {
64-
cwd: getLanguageFolder(lang),
65-
});
63+
await updateJavaScriptPackages(releaseType);
6664
}
6765

6866
await updateChangelog(
@@ -74,84 +72,3 @@ export async function updateAPIVersions(versions: Versions, changelog: Changelog
7472
);
7573
}
7674
}
77-
78-
/**
79-
* Updates packages versions and generates the changelog.
80-
*/
81-
async function updateDartPackages(changelog: string, nextVersion: string): Promise<void> {
82-
for (const gen of Object.values(GENERATORS)) {
83-
if (gen.language !== 'dart') {
84-
continue;
85-
}
86-
87-
if (!nextVersion) {
88-
throw new Error(`Failed to bump '${gen.packageName}'.`);
89-
}
90-
91-
let currentVersion = await getPubspecField(gen.output, 'version');
92-
93-
// if there's no version then it mostly means it's a new client.
94-
if (!currentVersion) {
95-
currentVersion = '0.0.1';
96-
}
97-
98-
await updateChangelog('dart', changelog, currentVersion, nextVersion, toAbsolutePath(`${gen.output}/CHANGELOG.md`));
99-
}
100-
101-
// Version is sync'd on every clients so we set it once.
102-
clientsConfig.dart.packageVersion = nextVersion;
103-
104-
// update `clients.config.json` file for the utils version.
105-
await writeJsonFile(toAbsolutePath('config/clients.config.json'), clientsConfig);
106-
107-
// Core client package path
108-
const corePackagePath = 'clients/algoliasearch-client-dart/packages/client_core';
109-
110-
// fetch the version from the pubspec file of the core package
111-
let currentCoreVersion = await getPubspecField(corePackagePath, 'version');
112-
if (!currentCoreVersion) {
113-
currentCoreVersion = '0.0.1';
114-
}
115-
116-
// update the changelog for core package
117-
await updateChangelog(
118-
'dart',
119-
changelog,
120-
currentCoreVersion,
121-
nextVersion,
122-
toAbsolutePath(`${corePackagePath}/CHANGELOG.md`),
123-
);
124-
125-
// we've bumped generated clients but still need to do the manual ones.
126-
await bumpPubspecVersion(toAbsolutePath(`${corePackagePath}/pubspec.yaml`), nextVersion);
127-
}
128-
129-
/**
130-
* Get 'version' from pubspec.yaml file.
131-
*/
132-
async function getPubspecField(filePath: string, field: string): Promise<string | undefined> {
133-
try {
134-
const fileContent = await fsp.readFile(toAbsolutePath(`${filePath}/pubspec.yaml`), 'utf8');
135-
const pubspec = yaml.load(fileContent) as Record<string, any>;
136-
137-
return pubspec[field];
138-
} catch (error) {
139-
throw new Error(`Error reading file ${filePath}: ${error}`);
140-
}
141-
}
142-
143-
/**
144-
* Bump 'version' of the given pubspec.yaml file path.
145-
*/
146-
async function bumpPubspecVersion(filePath: string, nextVersion: string): Promise<void> {
147-
try {
148-
const fileContent = await fsp.readFile(toAbsolutePath(filePath), 'utf8');
149-
const pubspec = yaml.load(fileContent) as Record<string, any>;
150-
151-
pubspec.version = nextVersion;
152-
153-
await fsp.writeFile(filePath, yaml.dump(pubspec));
154-
} catch (error) {
155-
throw new Error(`Error writing file ${filePath}: ${error}`);
156-
}
157-
}

0 commit comments

Comments
 (0)
Please sign in to comment.