Skip to content

Commit

Permalink
Reorder workflow to update changelogs first (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptodev-2s authored Dec 4, 2023
1 parent 7778ab6 commit 56b275c
Show file tree
Hide file tree
Showing 21 changed files with 1,283 additions and 277 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"jest-it-up": "^2.0.2",
"jest-when": "^3.5.2",
"nanoid": "^3.3.4",
"outdent": "^0.8.0",
"prettier": "^2.2.1",
"prettier-plugin-packagejson": "^2.3.0",
"rimraf": "^4.0.5",
Expand Down
7 changes: 7 additions & 0 deletions src/command-line-arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type CommandLineArguments = {
tempDirectory: string | undefined;
reset: boolean;
backport: boolean;
defaultBranch: string;
};

/**
Expand Down Expand Up @@ -44,6 +45,12 @@ export async function readCommandLineArguments(
type: 'boolean',
default: false,
})
.option('default-branch', {
alias: 'b',
describe: 'The name of the default branch in the repository.',
default: 'main',
type: 'string',
})
.help()
.strict()
.parse();
Expand Down
48 changes: 31 additions & 17 deletions src/functional.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,21 +575,26 @@ describe('create-release-branch (functional)', () => {
},
});

// Tests four things:
// * The latest commit should be called "Release 1.0.0"
// Tests five things:
// * The latest commit should be called "Update Release 2.0.0"
// * The before latest commit should be called "Initialize Release 2.0.0"
// * The latest commit should be the current commit (HEAD)
// * The latest branch should be called "release/1.0.0"
// * The latest branch should be called "release/2.0.0"
// * The latest branch should point to the latest commit
const [latestCommitSubject, latestCommitId, latestCommitRevsMarker] =
(
await environment.runCommand('git', [
'log',
'--pretty=%s%x09%H%x09%D',
'--date-order',
'--max-count=1',
])
).stdout.split('\x09');
const latestCommitRevs = latestCommitRevsMarker.split(' -> ');
const latestCommitsInReverse = (
await environment.runCommand('git', [
'log',
'--pretty=%s%x09%H%x09%D',
'--date-order',
'--max-count=2',
])
).stdout
.split('\n')
.map((line) => {
const [subject, commitId, revsMarker] = line.split('\x09');
const revs = revsMarker.split(' -> ');
return { subject, commitId, revs };
});
const latestBranchCommitId = (
await environment.runCommand('git', [
'rev-list',
Expand All @@ -598,10 +603,19 @@ describe('create-release-branch (functional)', () => {
'--max-count=1',
])
).stdout;
expect(latestCommitSubject).toBe('Release 2.0.0');
expect(latestCommitRevs).toContain('HEAD');
expect(latestCommitRevs).toContain('release/2.0.0');
expect(latestBranchCommitId).toStrictEqual(latestCommitId);
expect(latestCommitsInReverse[0].subject).toBe(
'Update Release 2.0.0',
);
expect(latestCommitsInReverse[1].subject).toBe(
'Initialize Release 2.0.0',
);

expect(latestCommitsInReverse[0].revs).toContain('HEAD');
expect(latestCommitsInReverse[0].revs).toContain('release/2.0.0');

expect(latestBranchCommitId).toStrictEqual(
latestCommitsInReverse[0].commitId,
);
},
);
});
Expand Down
9 changes: 9 additions & 0 deletions src/initial-parameters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('initial-parameters', () => {
tempDirectory: '/path/to/temp',
reset: true,
backport: false,
defaultBranch: 'main',
});
jest
.spyOn(envModule, 'getEnvironmentVariables')
Expand All @@ -54,6 +55,7 @@ describe('initial-parameters', () => {
tempDirectoryPath: '/path/to/temp',
reset: true,
releaseType: 'ordinary',
defaultBranch: 'main',
});
});

Expand All @@ -69,6 +71,7 @@ describe('initial-parameters', () => {
tempDirectory: undefined,
reset: true,
backport: false,
defaultBranch: 'main',
});
jest
.spyOn(envModule, 'getEnvironmentVariables')
Expand Down Expand Up @@ -98,6 +101,7 @@ describe('initial-parameters', () => {
tempDirectory: 'tmp',
reset: true,
backport: false,
defaultBranch: 'main',
});
jest
.spyOn(envModule, 'getEnvironmentVariables')
Expand Down Expand Up @@ -127,6 +131,7 @@ describe('initial-parameters', () => {
tempDirectory: undefined,
reset: true,
backport: false,
defaultBranch: 'main',
});
jest
.spyOn(envModule, 'getEnvironmentVariables')
Expand Down Expand Up @@ -156,6 +161,7 @@ describe('initial-parameters', () => {
tempDirectory: '/path/to/temp',
reset: true,
backport: false,
defaultBranch: 'main',
});
jest
.spyOn(envModule, 'getEnvironmentVariables')
Expand Down Expand Up @@ -183,6 +189,7 @@ describe('initial-parameters', () => {
tempDirectory: '/path/to/temp',
reset: false,
backport: false,
defaultBranch: 'main',
});
jest
.spyOn(envModule, 'getEnvironmentVariables')
Expand Down Expand Up @@ -210,6 +217,7 @@ describe('initial-parameters', () => {
tempDirectory: '/path/to/temp',
reset: false,
backport: true,
defaultBranch: 'main',
});
jest
.spyOn(envModule, 'getEnvironmentVariables')
Expand Down Expand Up @@ -237,6 +245,7 @@ describe('initial-parameters', () => {
tempDirectory: '/path/to/temp',
reset: false,
backport: false,
defaultBranch: 'main',
});
jest
.spyOn(envModule, 'getEnvironmentVariables')
Expand Down
2 changes: 2 additions & 0 deletions src/initial-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type InitialParameters = {
tempDirectoryPath: string;
reset: boolean;
releaseType: ReleaseType;
defaultBranch: string;
};

/**
Expand Down Expand Up @@ -58,6 +59,7 @@ export async function determineInitialParameters({
project,
tempDirectoryPath,
reset: args.reset,
defaultBranch: args.defaultBranch,
releaseType: args.backport ? 'backport' : 'ordinary',
};
}
3 changes: 3 additions & 0 deletions src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('main', () => {
project,
tempDirectoryPath: '/path/to/temp/directory',
reset: true,
defaultBranch: 'main',
releaseType: 'backport',
});
const followMonorepoWorkflowSpy = jest
Expand All @@ -36,6 +37,7 @@ describe('main', () => {
tempDirectoryPath: '/path/to/temp/directory',
firstRemovingExistingReleaseSpecification: true,
releaseType: 'backport',
defaultBranch: 'main',
stdout,
stderr,
});
Expand All @@ -51,6 +53,7 @@ describe('main', () => {
project,
tempDirectoryPath: '/path/to/temp/directory',
reset: false,
defaultBranch: 'main',
releaseType: 'backport',
});
const followMonorepoWorkflowSpy = jest
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function main({
stdout: Pick<WriteStream, 'write'>;
stderr: Pick<WriteStream, 'write'>;
}) {
const { project, tempDirectoryPath, reset, releaseType } =
const { project, tempDirectoryPath, reset, releaseType, defaultBranch } =
await determineInitialParameters({ argv, cwd, stderr });

if (project.isMonorepo) {
Expand All @@ -37,6 +37,7 @@ export async function main({
tempDirectoryPath,
firstRemovingExistingReleaseSpecification: reset,
releaseType,
defaultBranch,
stdout,
stderr,
});
Expand Down
Loading

0 comments on commit 56b275c

Please sign in to comment.