Skip to content

Smartlyio/fetch latest runner prerelease #141

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

Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ terraform import module.runners.module.runners.aws_cloudwatch_log_group.scale_up
terraform import module.runners.module.runners.aws_cloudwatch_log_group.scale_down "/aws/lambda/default-scale-down"
terraform import module.runners.module.webhook.aws_cloudwatch_log_group.webhook "/aws/lambda/default-webhook"
```
- fix: Syncer will now sync the latest github actions runner pre-release, preventing any auto-updating on startup

## [0.4.0] - 2020-08-10

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import latestReleasesNoArm64 from '../../test/resources/github-latest-releases-n

const mockOctokit = {
repos: {
getLatestRelease: jest.fn(),
listReleases: jest.fn(),
},
};
jest.mock('@octokit/rest', () => ({
Expand All @@ -32,8 +32,8 @@ describe('Synchronize action distribution.', () => {
process.env.S3_BUCKET_NAME = bucketName;
process.env.S3_OBJECT_KEY = bucketObjectKey;

mockOctokit.repos.getLatestRelease.mockImplementation(() => ({
data: latestReleases.data,
mockOctokit.repos.listReleases.mockImplementation(() => ({
data: [latestReleases.data],
}));
});

Expand All @@ -47,7 +47,7 @@ describe('Synchronize action distribution.', () => {
});

await handle();
expect(mockOctokit.repos.getLatestRelease).toBeCalledTimes(1);
expect(mockOctokit.repos.listReleases).toBeCalledTimes(1);
expect(mockS3.getObjectTagging).toBeCalledWith({
Bucket: bucketName,
Key: bucketObjectKey,
Expand All @@ -65,7 +65,7 @@ describe('Synchronize action distribution.', () => {
});

await handle();
expect(mockOctokit.repos.getLatestRelease).toBeCalledTimes(1);
expect(mockOctokit.repos.listReleases).toBeCalledTimes(1);
expect(mockS3.getObjectTagging).toBeCalledWith({
Bucket: bucketName,
Key: bucketObjectKey,
Expand All @@ -83,7 +83,7 @@ describe('Synchronize action distribution.', () => {
});

await handle();
expect(mockOctokit.repos.getLatestRelease).toBeCalledTimes(1);
expect(mockOctokit.repos.listReleases).toBeCalledTimes(1);
expect(mockS3.getObjectTagging).toBeCalledWith({
Bucket: bucketName,
Key: bucketObjectKey,
Expand All @@ -101,7 +101,7 @@ describe('Synchronize action distribution.', () => {
});

await handle();
expect(mockOctokit.repos.getLatestRelease).toBeCalledTimes(1);
expect(mockOctokit.repos.listReleases).toBeCalledTimes(1);
expect(mockS3.getObjectTagging).toBeCalledWith({
Bucket: bucketName,
Key: bucketObjectKey,
Expand All @@ -118,16 +118,16 @@ describe('No release assets found.', () => {
});

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

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

it('No linux x64 asset.', async () => {
mockOctokit.repos.getLatestRelease.mockImplementation(() => ({
data: latestReleasesNoLinux.data,
mockOctokit.repos.listReleases.mockImplementation(() => ({
data: [latestReleasesNoLinux.data],
}));

await expect(handle()).rejects.toThrow(errorMessage);
Expand Down Expand Up @@ -162,8 +162,8 @@ describe('Synchronize action distribution for arm64.', () => {
});

it('No linux arm64 asset.', async () => {
mockOctokit.repos.getLatestRelease.mockImplementation(() => ({
data: latestReleasesNoArm64.data,
mockOctokit.repos.listReleases.mockImplementation(() => ({
data: [latestReleasesNoArm64.data],
}));

await expect(handle()).rejects.toThrow(errorMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ interface ReleaseAsset {

async function getLinuxReleaseAsset(runnerArch = 'x64'): Promise<ReleaseAsset | undefined> {
const githubClient = new Octokit();
const assets = await githubClient.repos.getLatestRelease({
const assetsList = await githubClient.repos.listReleases({
owner: 'actions',
repo: 'runner',
});
const linuxAssets = assets.data.assets?.filter((a) => a.name?.includes(`actions-runner-linux-${runnerArch}-`));
if (assetsList.data?.length === 0) {
return undefined;
}
const assets = assetsList.data[0];
const linuxAssets = assets.assets?.filter((a) => a.name?.includes(`actions-runner-linux-${runnerArch}-`));

return linuxAssets?.length === 1
? { name: linuxAssets[0].name, downloadUrl: linuxAssets[0].browser_download_url }
Expand Down