Skip to content

Commit

Permalink
fix: Dowload lambda see philips-labs#1541 for details. (philips-labs#…
Browse files Browse the repository at this point in the history
…1542)

* fix: Update filter to match with new GitHub release assets.

* fix: Update filter to match with new GitHub release assets.

* Alter test data for pre-relases, add test case for empty response
  • Loading branch information
npalm authored Dec 22, 2021
1 parent d32ca1b commit 7cb73c8
Show file tree
Hide file tree
Showing 3 changed files with 6,793 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('Synchronize action distribution.', () => {
mockS3.getObjectTagging.mockImplementation(() => {
return {
promise() {
return Promise.resolve({ TagSet: [{ Key: 'name', Value: 'actions-runner-linux-x64-2.272.0.tar.gz' }] });
return Promise.resolve({ TagSet: [{ Key: 'name', Value: 'actions-runner-linux-x64-2.285.1.tar.gz' }] });
},
};
});
Expand All @@ -86,7 +86,7 @@ describe('Synchronize action distribution.', () => {
mockS3.getObjectTagging.mockImplementation(() => {
return {
promise() {
return Promise.resolve({ TagSet: [{ Key: 'name', Value: 'actions-runner-linux-x64-2.272.0.tar.gz' }] });
return Promise.resolve({ TagSet: [{ Key: 'name', Value: 'actions-runner-linux-x64-2.285.1.tar.gz' }] });
},
};
});
Expand All @@ -105,7 +105,7 @@ describe('Synchronize action distribution.', () => {
mockS3.getObjectTagging.mockImplementation(() => {
return {
promise() {
return Promise.resolve({ TagSet: [{ Key: 'name', Value: 'actions-runner-linux-x64-2.273.0.tar.gz' }] });
return Promise.resolve({ TagSet: [{ Key: 'name', Value: 'actions-runner-linux-x64-2.286.0.tar.gz' }] });
},
};
});
Expand Down Expand Up @@ -136,7 +136,7 @@ describe('Synchronize action distribution.', () => {
});
expect(mockS3.upload).toBeCalledTimes(1);
const s3JsonBody = mockS3.upload.mock.calls[0][0];
expect(s3JsonBody['Tagging']).toEqual('name=actions-runner-linux-x64-2.272.0.tar.gz');
expect(s3JsonBody['Tagging']).toEqual('name=actions-runner-linux-x64-2.285.1.tar.gz');
});

it('Distribution should update to release if there are no pre-releases.', async () => {
Expand All @@ -162,7 +162,7 @@ describe('Synchronize action distribution.', () => {
});
expect(mockS3.upload).toBeCalledTimes(1);
const s3JsonBody = mockS3.upload.mock.calls[0][0];
expect(s3JsonBody['Tagging']).toEqual('name=actions-runner-linux-x64-2.272.0.tar.gz');
expect(s3JsonBody['Tagging']).toEqual('name=actions-runner-linux-x64-2.285.1.tar.gz');
});

it('Distribution should update to prerelease.', async () => {
Expand All @@ -183,7 +183,7 @@ describe('Synchronize action distribution.', () => {
});
expect(mockS3.upload).toBeCalledTimes(1);
const s3JsonBody = mockS3.upload.mock.calls[0][0];
expect(s3JsonBody['Tagging']).toEqual('name=actions-runner-linux-x64-2.273.0.tar.gz');
expect(s3JsonBody['Tagging']).toEqual('name=actions-runner-linux-x64-2.286.0.tar.gz');
});

it('Distribution should not update to prerelease if there is a newer release.', async () => {
Expand Down Expand Up @@ -211,7 +211,7 @@ describe('Synchronize action distribution.', () => {
});
expect(mockS3.upload).toBeCalledTimes(1);
const s3JsonBody = mockS3.upload.mock.calls[0][0];
expect(s3JsonBody['Tagging']).toEqual('name=actions-runner-linux-x64-2.273.0.tar.gz');
expect(s3JsonBody['Tagging']).toEqual('name=actions-runner-linux-x64-2.286.0.tar.gz');
});

it('No tag in S3, distribution should update.', async () => {
Expand Down Expand Up @@ -273,6 +273,14 @@ describe('No release assets found.', () => {

await expect(sync()).rejects.toThrow(errorMessage);
});

it('Empty asset list.', async () => {
mockOctokit.repos.listReleases.mockImplementation(() => ({
data: [],
}));

await expect(sync()).rejects.toThrow(errorMessage);
});
});

describe('Invalid config', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ async function getReleaseAsset(
} else if (latestReleaseIndex != -1) {
asset = assetsList.data[latestReleaseIndex];
} else {
logger.warn('Cannot find either a release or pre release.');
return undefined;
}

const releaseVersion = asset.tag_name.replace('v', '');
const assets = asset.assets?.filter((a: { name?: string }) =>
a.name?.includes(`actions-runner-${runnerOs}-${runnerArch}-`),
a.name?.includes(`actions-runner-${runnerOs}-${runnerArch}-${releaseVersion}.`),
);

return assets?.length === 1 ? { name: assets[0].name, downloadUrl: assets[0].browser_download_url } : undefined;
Expand Down
Loading

0 comments on commit 7cb73c8

Please sign in to comment.