-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(scripts): dart and js releases [skip-bc] (#4104)
- Loading branch information
Showing
5 changed files
with
113 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<void> { | ||
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<string | undefined> { | ||
try { | ||
const fileContent = await fsp.readFile(toAbsolutePath(`${filePath}/pubspec.yaml`), 'utf8'); | ||
const pubspec = yaml.load(fileContent) as Record<string, any>; | ||
|
||
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<void> { | ||
try { | ||
const fileContent = await fsp.readFile(toAbsolutePath(filePath), 'utf8'); | ||
const pubspec = yaml.load(fileContent) as Record<string, any>; | ||
|
||
pubspec.version = nextVersion; | ||
|
||
await fsp.writeFile(filePath, yaml.dump(pubspec)); | ||
} catch (error) { | ||
throw new Error(`Error writing file ${filePath}: ${error}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters