Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit 63e0e27

Browse files
authored
fix(syncer): Fix for windows binaries in action runner syncer (#1716)
* Updated test data * Added an OS case for each test. * Added lookup for binary os label * Remove fixed values * Fix formatting * Use Record<T1,T2> * Fix references to `win` in variable descriptions. * Updated to latest runners file list * Fix formatting * Update lock file for windows example
1 parent fb53335 commit 63e0e27

File tree

7 files changed

+4448
-2364
lines changed

7 files changed

+4448
-2364
lines changed

Diff for: examples/windows/.terraform.lock.hcl

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: modules/runner-binaries-syncer/lambdas/runner-binaries-syncer/src/syncer/syncer.test.ts

+109-77
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,22 @@ jest.mock('aws-sdk', () => ({
4141
}));
4242

4343
const bucketName = 'my-bucket';
44-
const bucketObjectKey = 'actions-runner-linux.tar.gz';
44+
const objectExtension: Record<string, string> = {
45+
linux: '.tar.gz',
46+
win: '.zip',
47+
};
48+
const bucketObjectNames: Record<string, string> = {
49+
linux: `actions-runner-linux${objectExtension['linux']}`,
50+
win: `actions-runner-windows${objectExtension['win']}`,
51+
};
52+
53+
const bucketObjectKey = (os: string) => bucketObjectNames[os];
54+
55+
const runnerOs = [['linux'], ['win']];
56+
57+
const latestRelease = '2.287.0';
58+
const latestPreRelease = '2.287.1';
59+
4560
beforeEach(() => {
4661
jest.clearAllMocks();
4762
});
@@ -51,19 +66,22 @@ jest.setTimeout(60 * 1000);
5166
describe('Synchronize action distribution.', () => {
5267
beforeEach(() => {
5368
process.env.S3_BUCKET_NAME = bucketName;
54-
process.env.S3_OBJECT_KEY = bucketObjectKey;
5569
process.env.GITHUB_RUNNER_ALLOW_PRERELEASE_BINARIES = 'false';
5670

5771
mockOctokit.repos.listReleases.mockImplementation(() => ({
5872
data: listReleases,
5973
}));
6074
});
6175

62-
it('Distribution is up-to-date with latest release.', async () => {
76+
test.each(runnerOs)('%p Distribution is up-to-date with latest release.', async (os) => {
77+
process.env.S3_OBJECT_KEY = bucketObjectKey(os);
78+
process.env.GITHUB_RUNNER_OS = os;
6379
mockS3.getObjectTagging.mockImplementation(() => {
6480
return {
6581
promise() {
66-
return Promise.resolve({ TagSet: [{ Key: 'name', Value: 'actions-runner-linux-x64-2.285.1.tar.gz' }] });
82+
return Promise.resolve({
83+
TagSet: [{ Key: 'name', Value: `actions-runner-${os}-x64-${latestRelease}${objectExtension[os]}` }],
84+
});
6785
},
6886
};
6987
});
@@ -72,22 +90,52 @@ describe('Synchronize action distribution.', () => {
7290
expect(mockOctokit.repos.listReleases).toBeCalledTimes(1);
7391
expect(mockS3.getObjectTagging).toBeCalledWith({
7492
Bucket: bucketName,
75-
Key: bucketObjectKey,
93+
Key: bucketObjectKey(os),
7694
});
7795
expect(mockS3.upload).toBeCalledTimes(0);
7896
});
7997

80-
it('Distribution is up-to-date with latest release when there are no prereleases.', async () => {
98+
test.each(runnerOs)(
99+
'%p Distribution is up-to-date with latest release when there are no prereleases.',
100+
async (os) => {
101+
process.env.S3_OBJECT_KEY = bucketObjectKey(os);
102+
process.env.GITHUB_RUNNER_OS = os;
103+
process.env.GITHUB_RUNNER_ALLOW_PRERELEASE_BINARIES = 'true';
104+
const releases = listReleases.slice(1);
105+
106+
mockOctokit.repos.listReleases.mockImplementation(() => ({
107+
data: releases,
108+
}));
109+
mockS3.getObjectTagging.mockImplementation(() => {
110+
return {
111+
promise() {
112+
return Promise.resolve({
113+
TagSet: [{ Key: 'name', Value: `actions-runner-${os}-x64-${latestRelease}${objectExtension[os]}` }],
114+
});
115+
},
116+
};
117+
});
118+
119+
await sync();
120+
expect(mockOctokit.repos.listReleases).toBeCalledTimes(1);
121+
expect(mockS3.getObjectTagging).toBeCalledWith({
122+
Bucket: bucketName,
123+
Key: bucketObjectKey(os),
124+
});
125+
expect(mockS3.upload).toBeCalledTimes(0);
126+
},
127+
);
128+
129+
test.each(runnerOs)('%p Distribution is up-to-date with latest prerelease.', async (os) => {
130+
process.env.S3_OBJECT_KEY = bucketObjectKey(os);
131+
process.env.GITHUB_RUNNER_OS = os;
81132
process.env.GITHUB_RUNNER_ALLOW_PRERELEASE_BINARIES = 'true';
82-
const releases = listReleases.slice(1);
83-
84-
mockOctokit.repos.listReleases.mockImplementation(() => ({
85-
data: releases,
86-
}));
87133
mockS3.getObjectTagging.mockImplementation(() => {
88134
return {
89135
promise() {
90-
return Promise.resolve({ TagSet: [{ Key: 'name', Value: 'actions-runner-linux-x64-2.285.1.tar.gz' }] });
136+
return Promise.resolve({
137+
TagSet: [{ Key: 'name', Value: `actions-runner-${os}-x64-${latestPreRelease}${objectExtension[os]}` }],
138+
});
91139
},
92140
};
93141
});
@@ -96,17 +144,20 @@ describe('Synchronize action distribution.', () => {
96144
expect(mockOctokit.repos.listReleases).toBeCalledTimes(1);
97145
expect(mockS3.getObjectTagging).toBeCalledWith({
98146
Bucket: bucketName,
99-
Key: bucketObjectKey,
147+
Key: bucketObjectKey(os),
100148
});
101149
expect(mockS3.upload).toBeCalledTimes(0);
102150
});
103151

104-
it('Distribution is up-to-date with latest prerelease.', async () => {
105-
process.env.GITHUB_RUNNER_ALLOW_PRERELEASE_BINARIES = 'true';
152+
test.each(runnerOs)('%p Distribution should update to release.', async (os) => {
153+
process.env.S3_OBJECT_KEY = bucketObjectKey(os);
154+
process.env.GITHUB_RUNNER_OS = os;
106155
mockS3.getObjectTagging.mockImplementation(() => {
107156
return {
108157
promise() {
109-
return Promise.resolve({ TagSet: [{ Key: 'name', Value: 'actions-runner-linux-x64-2.286.0.tar.gz' }] });
158+
return Promise.resolve({
159+
TagSet: [{ Key: 'name', Value: `actions-runner-${os}-x64-0${objectExtension[os]}` }],
160+
});
110161
},
111162
};
112163
});
@@ -115,32 +166,16 @@ describe('Synchronize action distribution.', () => {
115166
expect(mockOctokit.repos.listReleases).toBeCalledTimes(1);
116167
expect(mockS3.getObjectTagging).toBeCalledWith({
117168
Bucket: bucketName,
118-
Key: bucketObjectKey,
119-
});
120-
expect(mockS3.upload).toBeCalledTimes(0);
121-
});
122-
123-
it('Distribution should update to release.', async () => {
124-
mockS3.getObjectTagging.mockImplementation(() => {
125-
return {
126-
promise() {
127-
return Promise.resolve({ TagSet: [{ Key: 'name', Value: 'actions-runner-linux-x64-0.tar.gz' }] });
128-
},
129-
};
130-
});
131-
132-
await sync();
133-
expect(mockOctokit.repos.listReleases).toBeCalledTimes(1);
134-
expect(mockS3.getObjectTagging).toBeCalledWith({
135-
Bucket: bucketName,
136-
Key: bucketObjectKey,
169+
Key: bucketObjectKey(os),
137170
});
138171
expect(mockS3.upload).toBeCalledTimes(1);
139172
const s3JsonBody = mockS3.upload.mock.calls[0][0];
140-
expect(s3JsonBody['Tagging']).toEqual('name=actions-runner-linux-x64-2.285.1.tar.gz');
173+
expect(s3JsonBody['Tagging']).toEqual(`name=actions-runner-${os}-x64-${latestRelease}${objectExtension[os]}`);
141174
});
142175

143-
it('Distribution should update to release if there are no pre-releases.', async () => {
176+
test.each(runnerOs)('%p Distribution should update to release if there are no pre-releases.', async (os) => {
177+
process.env.S3_OBJECT_KEY = bucketObjectKey(os);
178+
process.env.GITHUB_RUNNER_OS = os;
144179
process.env.GITHUB_RUNNER_ALLOW_PRERELEASE_BINARIES = 'true';
145180
const releases = listReleases.slice(1);
146181

@@ -150,7 +185,9 @@ describe('Synchronize action distribution.', () => {
150185
mockS3.getObjectTagging.mockImplementation(() => {
151186
return {
152187
promise() {
153-
return Promise.resolve({ TagSet: [{ Key: 'name', Value: 'actions-runner-linux-x64-0.tar.gz' }] });
188+
return Promise.resolve({
189+
TagSet: [{ Key: 'name', Value: `actions-runner-${os}-x64-0${objectExtension[os]}` }],
190+
});
154191
},
155192
};
156193
});
@@ -159,19 +196,23 @@ describe('Synchronize action distribution.', () => {
159196
expect(mockOctokit.repos.listReleases).toBeCalledTimes(1);
160197
expect(mockS3.getObjectTagging).toBeCalledWith({
161198
Bucket: bucketName,
162-
Key: bucketObjectKey,
199+
Key: bucketObjectKey(os),
163200
});
164201
expect(mockS3.upload).toBeCalledTimes(1);
165202
const s3JsonBody = mockS3.upload.mock.calls[0][0];
166-
expect(s3JsonBody['Tagging']).toEqual('name=actions-runner-linux-x64-2.285.1.tar.gz');
203+
expect(s3JsonBody['Tagging']).toEqual(`name=actions-runner-${os}-x64-${latestRelease}${objectExtension[os]}`);
167204
});
168205

169-
it('Distribution should update to prerelease.', async () => {
206+
test.each(runnerOs)('%p Distribution should update to prerelease.', async (os) => {
207+
process.env.S3_OBJECT_KEY = bucketObjectKey(os);
208+
process.env.GITHUB_RUNNER_OS = os;
170209
process.env.GITHUB_RUNNER_ALLOW_PRERELEASE_BINARIES = 'true';
171210
mockS3.getObjectTagging.mockImplementation(() => {
172211
return {
173212
promise() {
174-
return Promise.resolve({ TagSet: [{ Key: 'name', Value: 'actions-runner-linux-x64-0.tar.gz' }] });
213+
return Promise.resolve({
214+
TagSet: [{ Key: 'name', Value: `actions-runner-${os}-x64-0${objectExtension[os]}` }],
215+
});
175216
},
176217
};
177218
});
@@ -180,14 +221,16 @@ describe('Synchronize action distribution.', () => {
180221
expect(mockOctokit.repos.listReleases).toBeCalledTimes(1);
181222
expect(mockS3.getObjectTagging).toBeCalledWith({
182223
Bucket: bucketName,
183-
Key: bucketObjectKey,
224+
Key: bucketObjectKey(os),
184225
});
185226
expect(mockS3.upload).toBeCalledTimes(1);
186227
const s3JsonBody = mockS3.upload.mock.calls[0][0];
187-
expect(s3JsonBody['Tagging']).toEqual('name=actions-runner-linux-x64-2.286.0.tar.gz');
228+
expect(s3JsonBody['Tagging']).toEqual(`name=actions-runner-${os}-x64-${latestPreRelease}${objectExtension[os]}`);
188229
});
189230

190-
it('Distribution should not update to prerelease if there is a newer release.', async () => {
231+
test.each(runnerOs)('%p Distribution should not update to prerelease if there is a newer release.', async (os) => {
232+
process.env.S3_OBJECT_KEY = bucketObjectKey(os);
233+
process.env.GITHUB_RUNNER_OS = os;
191234
process.env.GITHUB_RUNNER_ALLOW_PRERELEASE_BINARIES = 'true';
192235
const releases = listReleases;
193236
releases[0].prerelease = false;
@@ -199,7 +242,9 @@ describe('Synchronize action distribution.', () => {
199242
mockS3.getObjectTagging.mockImplementation(() => {
200243
return {
201244
promise() {
202-
return Promise.resolve({ TagSet: [{ Key: 'name', Value: 'actions-runner-linux-x64-0.tar.gz' }] });
245+
return Promise.resolve({
246+
TagSet: [{ Key: 'name', Value: `actions-runner-${os}-x64-0${objectExtension[os]}` }],
247+
});
203248
},
204249
};
205250
});
@@ -208,14 +253,16 @@ describe('Synchronize action distribution.', () => {
208253
expect(mockOctokit.repos.listReleases).toBeCalledTimes(1);
209254
expect(mockS3.getObjectTagging).toBeCalledWith({
210255
Bucket: bucketName,
211-
Key: bucketObjectKey,
256+
Key: bucketObjectKey(os),
212257
});
213258
expect(mockS3.upload).toBeCalledTimes(1);
214259
const s3JsonBody = mockS3.upload.mock.calls[0][0];
215-
expect(s3JsonBody['Tagging']).toEqual('name=actions-runner-linux-x64-2.286.0.tar.gz');
260+
expect(s3JsonBody['Tagging']).toEqual(`name=actions-runner-${os}-x64-${latestPreRelease}${objectExtension[os]}`);
216261
});
217262

218-
it('No tag in S3, distribution should update.', async () => {
263+
test.each(runnerOs)('%p No tag in S3, distribution should update.', async (os) => {
264+
process.env.S3_OBJECT_KEY = bucketObjectKey(os);
265+
process.env.GITHUB_RUNNER_OS = os;
219266
mockS3.getObjectTagging.mockImplementation(() => {
220267
return {
221268
promise() {
@@ -228,12 +275,14 @@ describe('Synchronize action distribution.', () => {
228275
expect(mockOctokit.repos.listReleases).toBeCalledTimes(1);
229276
expect(mockS3.getObjectTagging).toBeCalledWith({
230277
Bucket: bucketName,
231-
Key: bucketObjectKey,
278+
Key: bucketObjectKey(os),
232279
});
233280
expect(mockS3.upload).toBeCalledTimes(1);
234281
});
235282

236-
it('Tags, but no version, distribution should update.', async () => {
283+
test.each(runnerOs)('%p Tags, but no version, distribution should update.', async (os) => {
284+
process.env.S3_OBJECT_KEY = bucketObjectKey(os);
285+
process.env.GITHUB_RUNNER_OS = os;
237286
mockS3.getObjectTagging.mockImplementation(() => {
238287
return {
239288
promise() {
@@ -246,7 +295,7 @@ describe('Synchronize action distribution.', () => {
246295
expect(mockOctokit.repos.listReleases).toBeCalledTimes(1);
247296
expect(mockS3.getObjectTagging).toBeCalledWith({
248297
Bucket: bucketName,
249-
Key: bucketObjectKey,
298+
Key: bucketObjectKey(os),
250299
});
251300
expect(mockS3.upload).toBeCalledTimes(1);
252301
});
@@ -256,7 +305,7 @@ describe('No release assets found.', () => {
256305
const errorMessage = 'Cannot find GitHub release asset.';
257306
beforeEach(() => {
258307
process.env.S3_BUCKET_NAME = bucketName;
259-
process.env.S3_OBJECT_KEY = bucketObjectKey;
308+
process.env.S3_OBJECT_KEY = bucketObjectKey('linux');
260309
});
261310

262311
it('Empty list of assets.', async () => {
@@ -267,7 +316,9 @@ describe('No release assets found.', () => {
267316
await expect(sync()).rejects.toThrow(errorMessage);
268317
});
269318

270-
it('No linux x64 asset.', async () => {
319+
test.each(runnerOs)('No %p x64 asset.', async (os) => {
320+
process.env.S3_OBJECT_KEY = bucketObjectKey(os);
321+
process.env.GITHUB_RUNNER_OS = os;
271322
mockOctokit.repos.listReleases.mockImplementation(() => ({
272323
data: [listReleasesNoLinux],
273324
}));
@@ -293,7 +344,7 @@ describe('Invalid config', () => {
293344
});
294345
it('No bucket.', async () => {
295346
delete process.env.S3_BUCKET_NAME;
296-
process.env.S3_OBJECT_KEY = bucketObjectKey;
347+
process.env.S3_OBJECT_KEY = bucketObjectKey('linux');
297348
await expect(sync()).rejects.toThrow(errorMessage);
298349
});
299350
it('No object key.', async () => {
@@ -307,35 +358,16 @@ describe('Synchronize action distribution for arm64.', () => {
307358
const errorMessage = 'Cannot find GitHub release asset.';
308359
beforeEach(() => {
309360
process.env.S3_BUCKET_NAME = bucketName;
310-
process.env.S3_OBJECT_KEY = bucketObjectKey;
311361
process.env.GITHUB_RUNNER_ARCHITECTURE = 'arm64';
312362
});
313363

314-
it('No linux arm64 asset.', async () => {
364+
test.each(runnerOs)('No %p arm64 asset.', async (os) => {
365+
process.env.S3_OBJECT_KEY = bucketObjectKey(os);
366+
process.env.GITHUB_RUNNER_OS = os;
315367
mockOctokit.repos.listReleases.mockImplementation(() => ({
316368
data: [listReleasesNoArm64],
317369
}));
318370

319371
await expect(sync()).rejects.toThrow(errorMessage);
320372
});
321373
});
322-
323-
describe('Synchronize action distribution for windows.', () => {
324-
const errorMessage = 'Cannot find GitHub release asset.';
325-
beforeEach(() => {
326-
process.env.S3_BUCKET_NAME = bucketName;
327-
process.env.S3_OBJECT_KEY = bucketObjectKey;
328-
process.env.GITHUB_RUNNER_OS = 'win';
329-
});
330-
331-
it('No win asset.', async () => {
332-
mockOctokit.repos.listReleases.mockImplementation(() => ({
333-
data: listReleases.map((release) => ({
334-
...release,
335-
assets: release.assets.filter((asset) => !asset.name.includes('win')),
336-
})),
337-
}));
338-
339-
await expect(sync()).rejects.toThrow(errorMessage);
340-
});
341-
});

0 commit comments

Comments
 (0)