Skip to content

Commit 69c81e8

Browse files
authored
Reformat root version to include the release no. (#22)
This commit changes how the root version is represented so that instead of looking like `<yyyy>.<mm>.<dd>`, it looks like `<ordinary>.<backport>.0`. That is, for most releases, the first number will get bumped, but for cases in which we want to issue a backport release — a release which introduces a fix to a previous version — then the second number will get incremented. The incrementing of the "ordinary" number is only implemented in this PR; incrementing the "backport" number will happen in a future PR.
1 parent 5b63b9e commit 69c81e8

18 files changed

+263
-363
lines changed

src/editor.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('editor', () => {
1111
it('returns information about the editor from EDITOR if it resolves to an executable', async () => {
1212
jest
1313
.spyOn(envModule, 'getEnvironmentVariables')
14-
.mockReturnValue({ EDITOR: 'editor', TODAY: undefined });
14+
.mockReturnValue({ EDITOR: 'editor' });
1515
when(jest.spyOn(miscUtils, 'resolveExecutable'))
1616
.calledWith('editor')
1717
.mockResolvedValue('/path/to/resolved-editor');
@@ -25,7 +25,7 @@ describe('editor', () => {
2525
it('falls back to VSCode if it exists and if EDITOR does not point to an executable', async () => {
2626
jest
2727
.spyOn(envModule, 'getEnvironmentVariables')
28-
.mockReturnValue({ EDITOR: 'editor', TODAY: undefined });
28+
.mockReturnValue({ EDITOR: 'editor' });
2929
when(jest.spyOn(miscUtils, 'resolveExecutable'))
3030
.calledWith('editor')
3131
.mockResolvedValue(null)
@@ -41,7 +41,7 @@ describe('editor', () => {
4141
it('returns null if resolving EDITOR returns null and resolving VSCode returns null', async () => {
4242
jest
4343
.spyOn(envModule, 'getEnvironmentVariables')
44-
.mockReturnValue({ EDITOR: 'editor', TODAY: undefined });
44+
.mockReturnValue({ EDITOR: 'editor' });
4545
when(jest.spyOn(miscUtils, 'resolveExecutable'))
4646
.calledWith('editor')
4747
.mockResolvedValue(null)
@@ -54,7 +54,7 @@ describe('editor', () => {
5454
it('returns null if resolving EDITOR returns null and resolving VSCode throws', async () => {
5555
jest
5656
.spyOn(envModule, 'getEnvironmentVariables')
57-
.mockReturnValue({ EDITOR: 'editor', TODAY: undefined });
57+
.mockReturnValue({ EDITOR: 'editor' });
5858
when(jest.spyOn(miscUtils, 'resolveExecutable'))
5959
.calledWith('editor')
6060
.mockResolvedValue(null)
@@ -67,7 +67,7 @@ describe('editor', () => {
6767
it('returns null if resolving EDITOR throws and resolving VSCode returns null', async () => {
6868
jest
6969
.spyOn(envModule, 'getEnvironmentVariables')
70-
.mockReturnValue({ EDITOR: 'editor', TODAY: undefined });
70+
.mockReturnValue({ EDITOR: 'editor' });
7171
when(jest.spyOn(miscUtils, 'resolveExecutable'))
7272
.calledWith('editor')
7373
.mockRejectedValue(new Error('some error'))
@@ -80,7 +80,7 @@ describe('editor', () => {
8080
it('returns null if resolving EDITOR throws and resolving VSCode throws', async () => {
8181
jest
8282
.spyOn(envModule, 'getEnvironmentVariables')
83-
.mockReturnValue({ EDITOR: 'editor', TODAY: undefined });
83+
.mockReturnValue({ EDITOR: 'editor' });
8484
when(jest.spyOn(miscUtils, 'resolveExecutable'))
8585
.calledWith('editor')
8686
.mockRejectedValue(new Error('some error'))
@@ -93,7 +93,7 @@ describe('editor', () => {
9393
it('returns null if EDITOR is unset and resolving VSCode returns null', async () => {
9494
jest
9595
.spyOn(envModule, 'getEnvironmentVariables')
96-
.mockReturnValue({ EDITOR: undefined, TODAY: undefined });
96+
.mockReturnValue({ EDITOR: undefined });
9797
when(jest.spyOn(miscUtils, 'resolveExecutable'))
9898
.calledWith('code')
9999
.mockResolvedValue(null);
@@ -104,7 +104,7 @@ describe('editor', () => {
104104
it('returns null if EDITOR is unset and resolving VSCode throws', async () => {
105105
jest
106106
.spyOn(envModule, 'getEnvironmentVariables')
107-
.mockReturnValue({ EDITOR: undefined, TODAY: undefined });
107+
.mockReturnValue({ EDITOR: undefined });
108108
when(jest.spyOn(miscUtils, 'resolveExecutable'))
109109
.calledWith('code')
110110
.mockRejectedValue(new Error('some error'));

src/env.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ describe('env', () => {
1616

1717
it('returns only the environment variables from process.env that we use in this tool', () => {
1818
process.env.EDITOR = 'editor';
19-
process.env.TODAY = 'today';
2019
process.env.EXTRA = 'extra';
2120

2221
expect(getEnvironmentVariables()).toStrictEqual({
2322
EDITOR: 'editor',
24-
TODAY: 'today',
2523
});
2624
});
2725
});

src/env.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
interface Env {
22
EDITOR: string | undefined;
3-
TODAY: string | undefined;
43
}
54

65
/**
@@ -10,7 +9,7 @@ interface Env {
109
* this tool needs to access, whether their values are defined or not.
1110
*/
1211
export function getEnvironmentVariables(): Env {
13-
return ['EDITOR', 'TODAY'].reduce((object, key) => {
12+
return ['EDITOR'].reduce((object, key) => {
1413
return { ...object, [key]: process.env[key] };
1514
}, {} as Env);
1615
}

src/functional.test.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('create-release-branch (functional)', () => {
99
packages: {
1010
$root$: {
1111
name: '@scope/monorepo',
12-
version: '2022.1.1',
12+
version: '1.0.0',
1313
directoryPath: '.',
1414
},
1515
a: {
@@ -41,7 +41,6 @@ describe('create-release-branch (functional)', () => {
4141
workspaces: {
4242
'.': ['packages/*'],
4343
},
44-
today: new Date('2022-06-24'),
4544
},
4645
async (environment) => {
4746
await environment.updateJsonFile('package.json', {
@@ -88,7 +87,7 @@ describe('create-release-branch (functional)', () => {
8887

8988
expect(await environment.readJsonFile('package.json')).toStrictEqual({
9089
name: '@scope/monorepo',
91-
version: '2022.6.24',
90+
version: '2.0.0',
9291
private: true,
9392
workspaces: ['packages/*'],
9493
scripts: { foo: 'bar' },
@@ -138,7 +137,7 @@ describe('create-release-branch (functional)', () => {
138137
packages: {
139138
$root$: {
140139
name: '@scope/monorepo',
141-
version: '2022.1.1',
140+
version: '1.0.0',
142141
directoryPath: '.',
143142
},
144143
a: {
@@ -238,7 +237,7 @@ describe('create-release-branch (functional)', () => {
238237
packages: {
239238
$root$: {
240239
name: '@scope/monorepo',
241-
version: '2022.1.1',
240+
version: '1.0.0',
242241
directoryPath: '.',
243242
},
244243
a: {
@@ -250,7 +249,6 @@ describe('create-release-branch (functional)', () => {
250249
workspaces: {
251250
'.': ['packages/*'],
252251
},
253-
today: new Date('2022-06-24'),
254252
},
255253
async (environment) => {
256254
await environment.runTool({
@@ -262,9 +260,9 @@ describe('create-release-branch (functional)', () => {
262260
});
263261

264262
// Tests four things:
265-
// * The latest commit should be called "Release YYYY-MM-DD"
263+
// * The latest commit should be called "Release 1.0.0"
266264
// * The latest commit should be the current commit (HEAD)
267-
// * The latest branch should be called "release/YYYY-MM-DD"
265+
// * The latest branch should be called "release/1.0.0"
268266
// * The latest branch should point to the latest commit
269267
const [latestCommitSubject, latestCommitId, latestCommitRevsMarker] =
270268
(
@@ -284,9 +282,9 @@ describe('create-release-branch (functional)', () => {
284282
'--max-count=1',
285283
])
286284
).stdout;
287-
expect(latestCommitSubject).toStrictEqual('Release 2022-06-24');
285+
expect(latestCommitSubject).toStrictEqual('Release 2.0.0');
288286
expect(latestCommitRevs).toContain('HEAD');
289-
expect(latestCommitRevs).toContain('release/2022-06-24');
287+
expect(latestCommitRevs).toContain('release/2.0.0');
290288
expect(latestBranchCommitId).toStrictEqual(latestCommitId);
291289
},
292290
);

src/initial-parameters.test.ts

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('initial-parameters', () => {
3232
});
3333
jest
3434
.spyOn(envModule, 'getEnvironmentVariables')
35-
.mockReturnValue({ TODAY: '2022-06-22', EDITOR: undefined });
35+
.mockReturnValue({ EDITOR: undefined });
3636
when(jest.spyOn(projectModule, 'readProject'))
3737
.calledWith('/path/to/project')
3838
.mockResolvedValue(project);
@@ -46,7 +46,6 @@ describe('initial-parameters', () => {
4646
project,
4747
tempDirectoryPath: '/path/to/temp',
4848
reset: true,
49-
today: new Date('2022-06-22'),
5049
});
5150
});
5251

@@ -63,7 +62,7 @@ describe('initial-parameters', () => {
6362
});
6463
jest
6564
.spyOn(envModule, 'getEnvironmentVariables')
66-
.mockReturnValue({ TODAY: undefined, EDITOR: undefined });
65+
.mockReturnValue({ EDITOR: undefined });
6766
const readProjectSpy = jest
6867
.spyOn(projectModule, 'readProject')
6968
.mockResolvedValue(project);
@@ -84,7 +83,7 @@ describe('initial-parameters', () => {
8483
});
8584
jest
8685
.spyOn(envModule, 'getEnvironmentVariables')
87-
.mockReturnValue({ TODAY: undefined, EDITOR: undefined });
86+
.mockReturnValue({ EDITOR: undefined });
8887
when(jest.spyOn(projectModule, 'readProject'))
8988
.calledWith('/path/to/project')
9089
.mockResolvedValue(project);
@@ -110,7 +109,7 @@ describe('initial-parameters', () => {
110109
});
111110
jest
112111
.spyOn(envModule, 'getEnvironmentVariables')
113-
.mockReturnValue({ TODAY: undefined, EDITOR: undefined });
112+
.mockReturnValue({ EDITOR: undefined });
114113
when(jest.spyOn(projectModule, 'readProject'))
115114
.calledWith('/path/to/project')
116115
.mockResolvedValue(project);
@@ -125,56 +124,52 @@ describe('initial-parameters', () => {
125124
);
126125
});
127126

128-
it('uses the current date if the TODAY environment variable was not provided', async () => {
127+
it('returns initial parameters including reset: true, derived from a command-line argument of "--reset true"', async () => {
129128
const project = buildMockProject();
130-
const today = new Date('2022-01-01');
131129
when(jest.spyOn(commandLineArgumentsModule, 'readCommandLineArguments'))
132130
.calledWith(['arg1', 'arg2'])
133131
.mockResolvedValue({
134132
projectDirectory: '/path/to/project',
135-
tempDirectory: undefined,
133+
tempDirectory: '/path/to/temp',
136134
reset: true,
137135
});
138136
jest
139137
.spyOn(envModule, 'getEnvironmentVariables')
140-
.mockReturnValue({ TODAY: undefined, EDITOR: undefined });
138+
.mockReturnValue({ EDITOR: undefined });
141139
when(jest.spyOn(projectModule, 'readProject'))
142140
.calledWith('/path/to/project')
143141
.mockResolvedValue(project);
144-
jest.setSystemTime(today);
145142

146143
const config = await determineInitialParameters(
147144
['arg1', 'arg2'],
148-
'/path/to/cwd',
145+
'/path/to/somewhere',
149146
);
150147

151-
expect(config.today).toStrictEqual(today);
148+
expect(config.reset).toBe(true);
152149
});
153150

154-
it('uses the current date if TODAY is not a parsable date', async () => {
151+
it('returns initial parameters including reset: false, derived from a command-line argument of "--reset false"', async () => {
155152
const project = buildMockProject();
156-
const today = new Date('2022-01-01');
157153
when(jest.spyOn(commandLineArgumentsModule, 'readCommandLineArguments'))
158154
.calledWith(['arg1', 'arg2'])
159155
.mockResolvedValue({
160156
projectDirectory: '/path/to/project',
161-
tempDirectory: undefined,
162-
reset: true,
157+
tempDirectory: '/path/to/temp',
158+
reset: false,
163159
});
164160
jest
165161
.spyOn(envModule, 'getEnvironmentVariables')
166-
.mockReturnValue({ TODAY: 'asdfgdasf', EDITOR: undefined });
162+
.mockReturnValue({ EDITOR: undefined });
167163
when(jest.spyOn(projectModule, 'readProject'))
168164
.calledWith('/path/to/project')
169165
.mockResolvedValue(project);
170-
jest.setSystemTime(today);
171166

172167
const config = await determineInitialParameters(
173168
['arg1', 'arg2'],
174-
'/path/to/cwd',
169+
'/path/to/somewhere',
175170
);
176171

177-
expect(config.today).toStrictEqual(today);
172+
expect(config.reset).toBe(false);
178173
});
179174
});
180175
});

src/initial-parameters.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import os from 'os';
22
import path from 'path';
3-
import { getEnvironmentVariables } from './env';
43
import { readCommandLineArguments } from './command-line-arguments';
54
import { readProject, Project } from './project';
65

76
interface InitialParameters {
87
project: Project;
98
tempDirectoryPath: string;
109
reset: boolean;
11-
today: Date;
1210
}
1311

1412
/**
@@ -24,7 +22,6 @@ export async function determineInitialParameters(
2422
cwd: string,
2523
): Promise<InitialParameters> {
2624
const inputs = await readCommandLineArguments(argv);
27-
const { TODAY } = getEnvironmentVariables();
2825

2926
const projectDirectoryPath = path.resolve(cwd, inputs.projectDirectory);
3027
const project = await readProject(projectDirectoryPath);
@@ -36,11 +33,6 @@ export async function determineInitialParameters(
3633
project.rootPackage.validatedManifest.name.replace('/', '__'),
3734
)
3835
: path.resolve(cwd, inputs.tempDirectory);
39-
const parsedTodayTimestamp =
40-
TODAY === undefined ? NaN : new Date(TODAY).getTime();
41-
const today = isNaN(parsedTodayTimestamp)
42-
? new Date()
43-
: new Date(parsedTodayTimestamp);
4436

45-
return { project, tempDirectoryPath, reset: inputs.reset, today };
37+
return { project, tempDirectoryPath, reset: inputs.reset };
4638
}

src/main.test.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ jest.mock('./monorepo-workflow-operations');
1010
describe('main', () => {
1111
it('executes the monorepo workflow if the project is a monorepo', async () => {
1212
const project = buildMockProject({ isMonorepo: true });
13-
const today = new Date();
1413
const stdout = fs.createWriteStream('/dev/null');
1514
const stderr = fs.createWriteStream('/dev/null');
1615
jest
@@ -19,7 +18,6 @@ describe('main', () => {
1918
project,
2019
tempDirectoryPath: '/path/to/temp/directory',
2120
reset: false,
22-
today,
2321
});
2422
const followMonorepoWorkflowSpy = jest
2523
.spyOn(monorepoWorkflowOperations, 'followMonorepoWorkflow')
@@ -36,15 +34,13 @@ describe('main', () => {
3634
project,
3735
tempDirectoryPath: '/path/to/temp/directory',
3836
firstRemovingExistingReleaseSpecification: false,
39-
today,
4037
stdout,
4138
stderr,
4239
});
4340
});
4441

4542
it('executes the polyrepo workflow if the project is within a polyrepo', async () => {
4643
const project = buildMockProject({ isMonorepo: false });
47-
const today = new Date();
4844
const stdout = fs.createWriteStream('/dev/null');
4945
const stderr = fs.createWriteStream('/dev/null');
5046
jest
@@ -53,7 +49,6 @@ describe('main', () => {
5349
project,
5450
tempDirectoryPath: '/path/to/temp/directory',
5551
reset: false,
56-
today,
5752
});
5853
const followMonorepoWorkflowSpy = jest
5954
.spyOn(monorepoWorkflowOperations, 'followMonorepoWorkflow')

src/main.ts

Lines changed: 1 addition & 2 deletions
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, today } =
28+
const { project, tempDirectoryPath, reset } =
2929
await determineInitialParameters(argv, cwd);
3030

3131
if (project.isMonorepo) {
@@ -36,7 +36,6 @@ export async function main({
3636
project,
3737
tempDirectoryPath,
3838
firstRemovingExistingReleaseSpecification: reset,
39-
today,
4039
stdout,
4140
stderr,
4241
});

0 commit comments

Comments
 (0)