forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
finishReleaseCycle.test.ts
240 lines (234 loc) · 12.4 KB
/
finishReleaseCycle.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
import {MockGithub} from '@kie/mock-github';
import path from 'path';
import assertions from './assertions/finishReleaseCycleAssertions';
import mocks from './mocks/finishReleaseCycleMocks';
import ExtendedAct from './utils/ExtendedAct';
import type {MockJobs} from './utils/JobMocker';
import * as utils from './utils/utils';
jest.setTimeout(90 * 1000);
let mockGithub: MockGithub;
const FILES_TO_COPY_INTO_TEST_REPO = [
...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO),
{
src: path.resolve(__dirname, '..', '.github', 'workflows', 'finishReleaseCycle.yml'),
dest: '.github/workflows/finishReleaseCycle.yml',
},
];
describe('test workflow finishReleaseCycle', () => {
beforeAll(() => {
// in case of the tests being interrupted without cleanup the mock repo directory may be left behind
// which breaks the next test run, this removes any possible leftovers
utils.removeMockRepoDir();
});
beforeEach(async () => {
// create a local repository and copy required files
mockGithub = new MockGithub({
repo: {
testFinishReleaseCycleWorkflowRepo: {
files: FILES_TO_COPY_INTO_TEST_REPO,
},
},
});
await mockGithub.setup();
});
afterEach(async () => {
await mockGithub.teardown();
});
const secrets = {
OS_BOTIFY_TOKEN: 'dummy_token',
LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd',
SLACK_WEBHOOK: 'dummy_slack_webhook',
OS_BOTIFY_APP_ID: 'os_botify_app_id',
OS_BOTIFY_PRIVATE_KEY: 'os_botify_private_key',
};
describe('issue closed', () => {
describe('issue has StagingDeployCash', () => {
describe('actor is a team member', () => {
describe('no deploy blockers', () => {
it('production updated, new version created', async () => {
const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(
act,
'issues',
{
action: 'closed',
type: 'closed',
issue: {
labels: [{name: 'StagingDeployCash'}],
number: '1234',
},
},
secrets,
);
const testMockSteps = {
validate: mocks.FINISHRELEASECYCLE__VALIDATE__TEAM_MEMBER_NO_BLOCKERS__STEP_MOCKS,
updateProduction: mocks.FINISHRELEASECYCLE__UPDATEPRODUCTION__STEP_MOCKS,
updateStaging: mocks.FINISHRELEASECYCLE__UPDATESTAGING__STEP_MOCKS,
};
const testMockJobs: MockJobs = {
createNewPatchVersion: {
steps: mocks.FINISHRELEASECYCLE__CREATENEWPATCHVERSION__STEP_MOCKS,
outputs: {
// eslint-disable-next-line no-template-curly-in-string
NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}',
},
runsOn: 'ubuntu-latest',
},
};
const result = await act.runEvent('issues', {
workflowFile: path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'),
mockSteps: testMockSteps,
actor: 'Dummy Author',
logFile: utils.getLogFilePath('finishReleaseCycle', expect.getState().currentTestName),
mockJobs: testMockJobs,
});
assertions.assertValidateJobExecuted(result, '1234');
assertions.assertUpdateProductionJobExecuted(result);
assertions.assertCreateNewPatchVersionJobExecuted(result);
assertions.assertUpdateStagingJobExecuted(result);
});
});
describe('deploy blockers', () => {
it('production not updated, new version not created, issue reopened', async () => {
const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(
act,
'issues',
{
action: 'closed',
type: 'closed',
issue: {
labels: [{name: 'StagingDeployCash'}],
number: '1234',
},
},
secrets,
);
const testMockSteps = {
validate: mocks.FINISHRELEASECYCLE__VALIDATE__TEAM_MEMBER_BLOCKERS__STEP_MOCKS,
updateProduction: mocks.FINISHRELEASECYCLE__UPDATEPRODUCTION__STEP_MOCKS,
updateStaging: mocks.FINISHRELEASECYCLE__UPDATESTAGING__STEP_MOCKS,
};
const testMockJobs = {
createNewPatchVersion: {
steps: mocks.FINISHRELEASECYCLE__CREATENEWPATCHVERSION__STEP_MOCKS,
outputs: {
// eslint-disable-next-line no-template-curly-in-string
NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}',
},
runsOn: 'ubuntu-latest',
},
};
const result = await act.runEvent('issues', {
workflowFile: path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'),
mockSteps: testMockSteps,
actor: 'Dummy Author',
logFile: utils.getLogFilePath('finishReleaseCycle', expect.getState().currentTestName),
mockJobs: testMockJobs,
});
assertions.assertValidateJobExecuted(result, '1234', true, true, true);
assertions.assertUpdateProductionJobExecuted(result, false);
assertions.assertCreateNewPatchVersionJobExecuted(result, false);
assertions.assertUpdateStagingJobExecuted(result, false);
});
});
});
describe('actor is not a team member', () => {
it('production not updated, new version not created, issue reopened', async () => {
const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(
act,
'issues',
{
action: 'closed',
type: 'closed',
issue: {
labels: [{name: 'StagingDeployCash'}],
number: '1234',
},
},
secrets,
);
const testMockSteps = {
validate: mocks.FINISHRELEASECYCLE__VALIDATE__NOT_TEAM_MEMBER_NO_BLOCKERS__STEP_MOCKS,
updateProduction: mocks.FINISHRELEASECYCLE__UPDATEPRODUCTION__STEP_MOCKS,
updateStaging: mocks.FINISHRELEASECYCLE__UPDATESTAGING__STEP_MOCKS,
};
const testMockJobs = {
createNewPatchVersion: {
steps: mocks.FINISHRELEASECYCLE__CREATENEWPATCHVERSION__STEP_MOCKS,
outputs: {
// eslint-disable-next-line no-template-curly-in-string
NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}',
},
runsOn: 'ubuntu-latest',
},
};
const result = await act.runEvent('issues', {
workflowFile: path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'),
mockSteps: testMockSteps,
actor: 'Dummy Author',
logFile: utils.getLogFilePath('finishReleaseCycle', expect.getState().currentTestName),
mockJobs: testMockJobs,
});
assertions.assertValidateJobExecuted(result, '1234', true, false, false);
assertions.assertUpdateProductionJobExecuted(result, false);
assertions.assertCreateNewPatchVersionJobExecuted(result, false);
assertions.assertUpdateStagingJobExecuted(result, false);
});
});
});
describe('issue does not have StagingDeployCash', () => {
it('validate job not run', async () => {
const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(
act,
'issues',
{
action: 'closed',
type: 'closed',
issue: {
labels: [{name: 'Some'}, {name: 'Other'}, {name: 'Labels'}],
number: '1234',
},
},
secrets,
);
const testMockSteps = {
validate: mocks.FINISHRELEASECYCLE__VALIDATE__TEAM_MEMBER_NO_BLOCKERS__STEP_MOCKS,
updateProduction: mocks.FINISHRELEASECYCLE__UPDATEPRODUCTION__STEP_MOCKS,
updateStaging: mocks.FINISHRELEASECYCLE__UPDATESTAGING__STEP_MOCKS,
};
const testMockJobs = {
createNewPatchVersion: {
steps: mocks.FINISHRELEASECYCLE__CREATENEWPATCHVERSION__STEP_MOCKS,
outputs: {
// eslint-disable-next-line no-template-curly-in-string
NEW_VERSION: '${{ steps.createNewVersion.outputs.NEW_VERSION }}',
},
runsOn: 'ubuntu-latest',
},
};
const result = await act.runEvent('issues', {
workflowFile: path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml'),
mockSteps: testMockSteps,
actor: 'Dummy Author',
logFile: utils.getLogFilePath('finishReleaseCycle', expect.getState().currentTestName),
mockJobs: testMockJobs,
});
assertions.assertValidateJobExecuted(result, '1234', false);
assertions.assertUpdateProductionJobExecuted(result, false);
assertions.assertCreateNewPatchVersionJobExecuted(result, false);
assertions.assertUpdateStagingJobExecuted(result, false);
});
});
});
});