Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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