Skip to content

Commit 56b275c

Browse files
authored
Reorder workflow to update changelogs first (#109)
1 parent 7778ab6 commit 56b275c

21 files changed

+1283
-277
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"jest-it-up": "^2.0.2",
6262
"jest-when": "^3.5.2",
6363
"nanoid": "^3.3.4",
64+
"outdent": "^0.8.0",
6465
"prettier": "^2.2.1",
6566
"prettier-plugin-packagejson": "^2.3.0",
6667
"rimraf": "^4.0.5",

src/command-line-arguments.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export type CommandLineArguments = {
66
tempDirectory: string | undefined;
77
reset: boolean;
88
backport: boolean;
9+
defaultBranch: string;
910
};
1011

1112
/**
@@ -44,6 +45,12 @@ export async function readCommandLineArguments(
4445
type: 'boolean',
4546
default: false,
4647
})
48+
.option('default-branch', {
49+
alias: 'b',
50+
describe: 'The name of the default branch in the repository.',
51+
default: 'main',
52+
type: 'string',
53+
})
4754
.help()
4855
.strict()
4956
.parse();

src/functional.test.ts

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -575,21 +575,26 @@ describe('create-release-branch (functional)', () => {
575575
},
576576
});
577577

578-
// Tests four things:
579-
// * The latest commit should be called "Release 1.0.0"
578+
// Tests five things:
579+
// * The latest commit should be called "Update Release 2.0.0"
580+
// * The before latest commit should be called "Initialize Release 2.0.0"
580581
// * The latest commit should be the current commit (HEAD)
581-
// * The latest branch should be called "release/1.0.0"
582+
// * The latest branch should be called "release/2.0.0"
582583
// * The latest branch should point to the latest commit
583-
const [latestCommitSubject, latestCommitId, latestCommitRevsMarker] =
584-
(
585-
await environment.runCommand('git', [
586-
'log',
587-
'--pretty=%s%x09%H%x09%D',
588-
'--date-order',
589-
'--max-count=1',
590-
])
591-
).stdout.split('\x09');
592-
const latestCommitRevs = latestCommitRevsMarker.split(' -> ');
584+
const latestCommitsInReverse = (
585+
await environment.runCommand('git', [
586+
'log',
587+
'--pretty=%s%x09%H%x09%D',
588+
'--date-order',
589+
'--max-count=2',
590+
])
591+
).stdout
592+
.split('\n')
593+
.map((line) => {
594+
const [subject, commitId, revsMarker] = line.split('\x09');
595+
const revs = revsMarker.split(' -> ');
596+
return { subject, commitId, revs };
597+
});
593598
const latestBranchCommitId = (
594599
await environment.runCommand('git', [
595600
'rev-list',
@@ -598,10 +603,19 @@ describe('create-release-branch (functional)', () => {
598603
'--max-count=1',
599604
])
600605
).stdout;
601-
expect(latestCommitSubject).toBe('Release 2.0.0');
602-
expect(latestCommitRevs).toContain('HEAD');
603-
expect(latestCommitRevs).toContain('release/2.0.0');
604-
expect(latestBranchCommitId).toStrictEqual(latestCommitId);
606+
expect(latestCommitsInReverse[0].subject).toBe(
607+
'Update Release 2.0.0',
608+
);
609+
expect(latestCommitsInReverse[1].subject).toBe(
610+
'Initialize Release 2.0.0',
611+
);
612+
613+
expect(latestCommitsInReverse[0].revs).toContain('HEAD');
614+
expect(latestCommitsInReverse[0].revs).toContain('release/2.0.0');
615+
616+
expect(latestBranchCommitId).toStrictEqual(
617+
latestCommitsInReverse[0].commitId,
618+
);
605619
},
606620
);
607621
});

src/initial-parameters.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ describe('initial-parameters', () => {
3535
tempDirectory: '/path/to/temp',
3636
reset: true,
3737
backport: false,
38+
defaultBranch: 'main',
3839
});
3940
jest
4041
.spyOn(envModule, 'getEnvironmentVariables')
@@ -54,6 +55,7 @@ describe('initial-parameters', () => {
5455
tempDirectoryPath: '/path/to/temp',
5556
reset: true,
5657
releaseType: 'ordinary',
58+
defaultBranch: 'main',
5759
});
5860
});
5961

@@ -69,6 +71,7 @@ describe('initial-parameters', () => {
6971
tempDirectory: undefined,
7072
reset: true,
7173
backport: false,
74+
defaultBranch: 'main',
7275
});
7376
jest
7477
.spyOn(envModule, 'getEnvironmentVariables')
@@ -98,6 +101,7 @@ describe('initial-parameters', () => {
98101
tempDirectory: 'tmp',
99102
reset: true,
100103
backport: false,
104+
defaultBranch: 'main',
101105
});
102106
jest
103107
.spyOn(envModule, 'getEnvironmentVariables')
@@ -127,6 +131,7 @@ describe('initial-parameters', () => {
127131
tempDirectory: undefined,
128132
reset: true,
129133
backport: false,
134+
defaultBranch: 'main',
130135
});
131136
jest
132137
.spyOn(envModule, 'getEnvironmentVariables')
@@ -156,6 +161,7 @@ describe('initial-parameters', () => {
156161
tempDirectory: '/path/to/temp',
157162
reset: true,
158163
backport: false,
164+
defaultBranch: 'main',
159165
});
160166
jest
161167
.spyOn(envModule, 'getEnvironmentVariables')
@@ -183,6 +189,7 @@ describe('initial-parameters', () => {
183189
tempDirectory: '/path/to/temp',
184190
reset: false,
185191
backport: false,
192+
defaultBranch: 'main',
186193
});
187194
jest
188195
.spyOn(envModule, 'getEnvironmentVariables')
@@ -210,6 +217,7 @@ describe('initial-parameters', () => {
210217
tempDirectory: '/path/to/temp',
211218
reset: false,
212219
backport: true,
220+
defaultBranch: 'main',
213221
});
214222
jest
215223
.spyOn(envModule, 'getEnvironmentVariables')
@@ -237,6 +245,7 @@ describe('initial-parameters', () => {
237245
tempDirectory: '/path/to/temp',
238246
reset: false,
239247
backport: false,
248+
defaultBranch: 'main',
240249
});
241250
jest
242251
.spyOn(envModule, 'getEnvironmentVariables')

src/initial-parameters.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type InitialParameters = {
2020
tempDirectoryPath: string;
2121
reset: boolean;
2222
releaseType: ReleaseType;
23+
defaultBranch: string;
2324
};
2425

2526
/**
@@ -58,6 +59,7 @@ export async function determineInitialParameters({
5859
project,
5960
tempDirectoryPath,
6061
reset: args.reset,
62+
defaultBranch: args.defaultBranch,
6163
releaseType: args.backport ? 'backport' : 'ordinary',
6264
};
6365
}

src/main.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe('main', () => {
1818
project,
1919
tempDirectoryPath: '/path/to/temp/directory',
2020
reset: true,
21+
defaultBranch: 'main',
2122
releaseType: 'backport',
2223
});
2324
const followMonorepoWorkflowSpy = jest
@@ -36,6 +37,7 @@ describe('main', () => {
3637
tempDirectoryPath: '/path/to/temp/directory',
3738
firstRemovingExistingReleaseSpecification: true,
3839
releaseType: 'backport',
40+
defaultBranch: 'main',
3941
stdout,
4042
stderr,
4143
});
@@ -51,6 +53,7 @@ describe('main', () => {
5153
project,
5254
tempDirectoryPath: '/path/to/temp/directory',
5355
reset: false,
56+
defaultBranch: 'main',
5457
releaseType: 'backport',
5558
});
5659
const followMonorepoWorkflowSpy = jest

src/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export async function main({
2525
stdout: Pick<WriteStream, 'write'>;
2626
stderr: Pick<WriteStream, 'write'>;
2727
}) {
28-
const { project, tempDirectoryPath, reset, releaseType } =
28+
const { project, tempDirectoryPath, reset, releaseType, defaultBranch } =
2929
await determineInitialParameters({ argv, cwd, stderr });
3030

3131
if (project.isMonorepo) {
@@ -37,6 +37,7 @@ export async function main({
3737
tempDirectoryPath,
3838
firstRemovingExistingReleaseSpecification: reset,
3939
releaseType,
40+
defaultBranch,
4041
stdout,
4142
stderr,
4243
});

0 commit comments

Comments
 (0)