-
Notifications
You must be signed in to change notification settings - Fork 532
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
feat(build-infrastructure): Add setVersion API #22919
Open
tylerbutler
wants to merge
7
commits into
microsoft:main
Choose a base branch
from
tylerbutler:bt-build-infra-versions-04
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+110
−27
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5c83787
feat(build-infrastructure): Add setVersion API
tylerbutler 5f080f2
use async function
tylerbutler ecfccb9
Merge branch 'main' into bt-build-infra-versions-04
tylerbutler 299560c
Update build-tools/packages/build-infrastructure/src/versions.ts
tylerbutler 2bd4bca
Merge branch 'main' into bt-build-infra-versions-04
tylerbutler 9f97235
Merge branch 'main' into bt-build-infra-versions-04
tylerbutler 637dacc
Merge branch 'main' into bt-build-infra-versions-04
tylerbutler 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 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
72 changes: 72 additions & 0 deletions
72
build-tools/packages/build-infrastructure/src/test/versions.test.ts
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,72 @@ | ||
/*! | ||
* Copyright (c) Microsoft Corporation and contributors. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
import { strict as assert } from "node:assert"; | ||
import path from "node:path"; | ||
|
||
import { expect } from "chai"; | ||
import { afterEach, describe, it } from "mocha"; | ||
import * as semver from "semver"; | ||
import { simpleGit } from "simple-git"; | ||
|
||
import { loadFluidRepo } from "../fluidRepo.js"; | ||
import type { ReleaseGroupName, WorkspaceName } from "../types.js"; | ||
import { setVersion } from "../versions.js"; | ||
|
||
import { testDataPath, testRepoRoot } from "./init.js"; | ||
|
||
const repo = loadFluidRepo(path.join(testDataPath, "./testRepo")); | ||
const main = repo.releaseGroups.get("main" as ReleaseGroupName); | ||
assert(main !== undefined); | ||
|
||
const group2 = repo.releaseGroups.get("group2" as ReleaseGroupName); | ||
assert(group2 !== undefined); | ||
|
||
const group3 = repo.releaseGroups.get("group3" as ReleaseGroupName); | ||
assert(group3 !== undefined); | ||
|
||
const secondWorkspace = repo.workspaces.get("second" as WorkspaceName); | ||
assert(secondWorkspace !== undefined); | ||
|
||
/** | ||
* A git client rooted in the test repo. Used for resetting tests. | ||
*/ | ||
const git = simpleGit(testRepoRoot); | ||
|
||
describe("setVersion", () => { | ||
afterEach(async () => { | ||
await git.checkout(["HEAD", "--", testRepoRoot]); | ||
repo.reload(); | ||
}); | ||
|
||
it("release group", async () => { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
await setVersion(main.packages, semver.parse("1.2.1")!); | ||
repo.reload(); | ||
|
||
const allCorrect = main.packages.every((pkg) => pkg.version === "1.2.1"); | ||
expect(main.version).to.equal("1.2.1"); | ||
expect(allCorrect).to.be.true; | ||
}); | ||
|
||
it("workspace", async () => { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
await setVersion(secondWorkspace.packages, semver.parse("2.2.1")!); | ||
repo.reload(); | ||
|
||
const allCorrect = secondWorkspace.packages.every((pkg) => pkg.version === "2.2.1"); | ||
expect(allCorrect).to.be.true; | ||
}); | ||
|
||
it("repo", async () => { | ||
const packages = [...repo.packages.values()]; | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
await setVersion(packages, semver.parse("1.2.1")!); | ||
repo.reload(); | ||
|
||
const allCorrect = packages.every((pkg) => pkg.version === "1.2.1"); | ||
expect(allCorrect).to.be.true; | ||
}); | ||
}); |
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,33 @@ | ||
/*! | ||
* Copyright (c) Microsoft Corporation and contributors. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
import * as semver from "semver"; | ||
|
||
import { updatePackageJsonFileAsync } from "./packageJsonUtils.js"; | ||
import type { IPackage, PackageJson } from "./types.js"; | ||
|
||
/** | ||
* Sets the version of a group of packages. | ||
* | ||
* Note that any loaded objects such as an IFluidRepo instance may need to be reloaded after calling this function. | ||
* | ||
* @param packages - An array of objects whose version should be updated. | ||
* @param version - The version to set. | ||
*/ | ||
export async function setVersion<J extends PackageJson>( | ||
packages: IPackage[], | ||
version: semver.SemVer, | ||
): Promise<void> { | ||
const translatedVersion = version; | ||
const setPackagePromises: Promise<void>[] = []; | ||
for (const pkg of packages) { | ||
setPackagePromises.push( | ||
updatePackageJsonFileAsync<J>(pkg.directory, async (json) => { | ||
json.version = translatedVersion.version; | ||
}), | ||
); | ||
} | ||
await Promise.all(setPackagePromises); | ||
} |
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.
It's not necessary to re-assign the release groups and workspaces after reloading the repo?
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.
Hmmm, I don't think so. The reload operation just reloads the packages' data from disk. It doesn't actually load the IFluid repo from config again. That is, this is not the same as creating a new IFluidRepo. So the references should all stay the same after reload.