-
Notifications
You must be signed in to change notification settings - Fork 21
fix(scripts): dart and js releases [skip-bc] #4104
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
except the code move, this was the only change