-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91c949c
commit 72679d6
Showing
7 changed files
with
151 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import { $ as chainableExeca, execa } from 'execa'; | ||
import { $ as chainableExeca } from 'execa'; | ||
import { writeFile } from 'fs/promises'; | ||
import { EOL } from 'os'; | ||
import * as path from 'path'; | ||
import { releaseTagToNameAndVersion } from './release_tag_to_name_and_version.js'; | ||
|
||
/** | ||
* | ||
|
@@ -64,7 +65,7 @@ export class GitClient { | |
commitAllChanges = async (message: string) => { | ||
await this.configure(); | ||
await this.execWithIO`git add .`; | ||
await this.execWithIO`git commit --message '${message}'`; | ||
await this.execWithIO`git commit --message ${message}`; | ||
}; | ||
|
||
/** | ||
|
@@ -81,7 +82,7 @@ export class GitClient { | |
|
||
checkout = async (ref: string, paths: string[] = []) => { | ||
const additionalArgs = paths.length > 0 ? ['--', ...paths] : []; | ||
await execa('git', ['checkout', ref, ...additionalArgs]); | ||
await this.execWithIO`git checkout ${ref} ${additionalArgs}`; | ||
}; | ||
|
||
status = async () => { | ||
|
@@ -134,16 +135,11 @@ export class GitClient { | |
await this.validateReleaseCommitHash(releaseCommitHash); | ||
const releaseTags = await this.getTagsAtCommit(releaseCommitHash); | ||
|
||
/** | ||
* Local function to convert a release tag string to just the package name | ||
* Release tags are formatted as <packageName>@<version>. For example: @aws-amplify/[email protected] | ||
*/ | ||
const releaseTagToPackageName = (releaseTag: string) => | ||
releaseTag.slice(0, releaseTag.lastIndexOf('@')); | ||
|
||
// create a set of just the package names (strip off the version suffix) associated with this release commit | ||
const packageNamesRemaining = new Set( | ||
releaseTags.map(releaseTagToPackageName) | ||
releaseTags | ||
.map(releaseTagToNameAndVersion) | ||
.map((nameAndVersion) => nameAndVersion.packageName) | ||
); | ||
|
||
// initialize the release commit cursor to the commit of the release before the input releaseCommitHash | ||
|
@@ -162,7 +158,7 @@ export class GitClient { | |
releaseCommitCursor | ||
); | ||
releaseTagsAtCursor.forEach((releaseTag) => { | ||
const packageName = releaseTagToPackageName(releaseTag); | ||
const { packageName } = releaseTagToNameAndVersion(releaseTag); | ||
if (packageNamesRemaining.has(packageName)) { | ||
// this means we've found the previous version of "packageNameRemaining" that was released in releaseCommitHash | ||
// so we add it to the return list and remove it from the search set | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { beforeEach, describe, it } from 'node:test'; | ||
import { beforeEach, describe, it, mock } from 'node:test'; | ||
import { mkdir, writeFile } from 'fs/promises'; | ||
import { randomUUID } from 'crypto'; | ||
import { EOL, tmpdir } from 'os'; | ||
|
@@ -12,6 +12,8 @@ import { | |
} from './package-json/package_json.js'; | ||
import { runVersion } from '../version_runner.js'; | ||
import { runPublish } from '../publish_runner.js'; | ||
import { ReleaseLifecycleManager } from './release_lifecycle_manager.js'; | ||
import { GithubClient } from './github_client.js'; | ||
|
||
/** | ||
* This test suite is more of an integration test than a unit test. | ||
|
@@ -21,6 +23,11 @@ import { runPublish } from '../publish_runner.js'; | |
* Since all of these tests are sharing the same git tree, we're running in serial to avoid conflicts (mostly around duplicate tag names) | ||
*/ | ||
void describe('ReleaseLifecycleManager', async () => { | ||
let gitClient: GitClient; | ||
let npmClient: NpmClient; | ||
|
||
let cantaloupePackageName: string; | ||
let platypusPackageName: string; | ||
// before(async () => { | ||
// await import('../start_npm_proxy.js'); | ||
// }); | ||
|
@@ -29,6 +36,20 @@ void describe('ReleaseLifecycleManager', async () => { | |
// await import('../stop_npm_proxy.js'); | ||
// }); | ||
|
||
/** | ||
* This setup initializes a "sandbox" git repo that has a js mono repo with 2 packages, cantaloupe and platypus | ||
* It seeds the local npm proxy with a few releases of these packages. | ||
* When its done, the state of the git refs npm dist-tags should be as follows: | ||
* | ||
* minor bump of cantaloupe only ● <- HEAD, [email protected], cantaloupe@latest | ||
* | | ||
* minor bump of cantaloupe and platypus ● <- [email protected], [email protected], platypus@latest | ||
* | | ||
* minor bump of cantaloupe and platypus ● <- [email protected], [email protected] | ||
* | | ||
* initial commit ● <- [email protected], [email protected] | ||
* | ||
*/ | ||
beforeEach(async ({ name: testName }) => { | ||
// create temp dir | ||
const shortId = randomUUID().split('-')[0]; | ||
|
@@ -40,31 +61,31 @@ void describe('ReleaseLifecycleManager', async () => { | |
await mkdir(testWorkingDir); | ||
console.log(testWorkingDir); | ||
|
||
const gitClient = new GitClient(testWorkingDir); | ||
const npmClient = new NpmClient(null, testWorkingDir); | ||
gitClient = new GitClient(testWorkingDir); | ||
npmClient = new NpmClient(null, testWorkingDir); | ||
|
||
const $ = chainableExeca({ stdio: 'inherit', cwd: testWorkingDir }); | ||
const runVersionInTestDir = () => runVersion([], testWorkingDir); | ||
const runPublishInTestDir = () => | ||
runPublish({ useLocalRegistry: true }, testWorkingDir); | ||
|
||
// converting to lowercase because npm init creates packages with all lowercase | ||
const packageABaseName = | ||
`${testNameNormalized}-package-a-${shortId}`.toLocaleLowerCase(); | ||
const packageBBaseName = | ||
`${testNameNormalized}-package-b-${shortId}`.toLocaleLowerCase(); | ||
cantaloupePackageName = | ||
`${testNameNormalized}-cantaloupe-${shortId}`.toLocaleLowerCase(); | ||
platypusPackageName = | ||
`${testNameNormalized}-platypus-${shortId}`.toLocaleLowerCase(); | ||
|
||
await gitClient.init(); | ||
await npmClient.init(); | ||
|
||
await npmClient.initWorkspacePackage(packageABaseName); | ||
await npmClient.initWorkspacePackage(cantaloupePackageName); | ||
await setPackageToPublic( | ||
path.join(testWorkingDir, 'packages', packageABaseName) | ||
path.join(testWorkingDir, 'packages', cantaloupePackageName) | ||
); | ||
|
||
await npmClient.initWorkspacePackage(packageBBaseName); | ||
await npmClient.initWorkspacePackage(platypusPackageName); | ||
await setPackageToPublic( | ||
path.join(testWorkingDir, 'packages', packageBBaseName) | ||
path.join(testWorkingDir, 'packages', platypusPackageName) | ||
); | ||
|
||
await npmClient.install(['@changesets/cli']); | ||
|
@@ -76,32 +97,50 @@ void describe('ReleaseLifecycleManager', async () => { | |
await commitVersionBumpChangeset( | ||
testWorkingDir, | ||
gitClient, | ||
[packageABaseName, packageBBaseName], | ||
[cantaloupePackageName, platypusPackageName], | ||
'minor' | ||
); | ||
await runVersionInTestDir(); | ||
await gitClient.commitAllChanges('Version Packages (first release)'); | ||
await runPublishInTestDir(); | ||
|
||
await commitVersionBumpChangeset( | ||
testWorkingDir, | ||
gitClient, | ||
[packageABaseName, packageBBaseName], | ||
[cantaloupePackageName, platypusPackageName], | ||
'minor' | ||
); | ||
await runVersionInTestDir(); | ||
await gitClient.commitAllChanges('Version Packages (second release)'); | ||
await runPublishInTestDir(); | ||
|
||
await commitVersionBumpChangeset( | ||
testWorkingDir, | ||
gitClient, | ||
[packageABaseName], | ||
[cantaloupePackageName], | ||
'minor' | ||
); | ||
await runVersionInTestDir(); | ||
await gitClient.commitAllChanges('Version Packages (third release)'); | ||
await runPublishInTestDir(); | ||
}); | ||
|
||
void it('dummy test', () => {}); | ||
void it('dummy test', async () => { | ||
const githubClient = new GithubClient('garbage'); | ||
mock.method(githubClient, 'createPr', async () => ({ prUrl: 'testPrUrl' })); | ||
mock.method(gitClient, 'push', async () => {}); | ||
const releaseLifecycleManager = new ReleaseLifecycleManager( | ||
'HEAD', | ||
githubClient, | ||
gitClient, | ||
npmClient | ||
); | ||
await releaseLifecycleManager.deprecateRelease('cantaloupe is rotten'); | ||
|
||
// expect latest of cantaloupe to point back to 1.2.0 and 1.3.0 to be marked deprecated | ||
// platypus should not be modified | ||
// const await npmClient.getPackageInfo(cantaloupePackageName); | ||
}); | ||
}); | ||
|
||
const setPackageToPublic = async (packagePath: string) => { | ||
|
@@ -118,9 +157,7 @@ const commitVersionBumpChangeset = async ( | |
packageNames: string[], | ||
bump: VersionBump | ||
) => { | ||
const message = `${bump} version bump for packages ${packageNames.join( | ||
', ' | ||
)}`; | ||
const message = `${bump} bump for ${packageNames.join(', ')}`; | ||
await writeFile( | ||
path.join(projectPath, '.changeset', `${randomUUID()}.md`), | ||
getChangesetContent(packageNames, bump, message) | ||
|
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,10 @@ | ||
/** | ||
* Splits a release tag of <packageName>@<version> into its constituent parts | ||
*/ | ||
export const releaseTagToNameAndVersion = (releaseTag: string) => { | ||
const indexOfLastAt = releaseTag.lastIndexOf('@'); | ||
return { | ||
packageName: releaseTag.slice(0, indexOfLastAt), | ||
version: releaseTag.slice(indexOfLastAt + 1), | ||
}; | ||
}; |
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
Oops, something went wrong.