Skip to content

release #1503

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

Merged
merged 22 commits into from
Dec 8, 2021
Merged

release #1503

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
de5b93f
fix: install_config_runner -> install_runner (#1479)
marekaf Dec 6, 2021
8266442
fix(syncer): Add tests, coverage report, and refactor lambda / naming…
npalm Dec 6, 2021
f1b99d9
fix: Download lambda (#1480)
npalm Dec 7, 2021
3415c5a
chore: Bump @vercel/ncc in /modules/runners/lambdas/runners (#1481)
dependabot[bot] Dec 7, 2021
a81aa9f
chore: Bump @vercel/ncc (#1482)
dependabot[bot] Dec 7, 2021
1b18651
chore: Bump prettier in /modules/runners/lambdas/runners (#1483)
dependabot[bot] Dec 7, 2021
fbc4f83
chore: Bump prettier (#1484)
dependabot[bot] Dec 7, 2021
e24fd3b
chore: Bump prettier in /modules/webhook/lambdas/webhook (#1485)
dependabot[bot] Dec 7, 2021
f4df8c9
chore: Bump @types/aws-lambda in /modules/runners/lambdas/runners (#1…
dependabot[bot] Dec 7, 2021
80fa6ec
chore: Bump @aws-sdk/client-ssm in /modules/webhook/lambdas/webhook (…
dependabot[bot] Dec 7, 2021
96ca4d3
chore: Bump aws-sdk in /modules/webhook/lambdas/webhook (#1490)
dependabot[bot] Dec 7, 2021
18041fd
chore: Bump @aws-sdk/client-ssm in /modules/runners/lambdas/runners (…
dependabot[bot] Dec 7, 2021
870fd2d
chore: Bump @types/aws-lambda in /modules/webhook/lambdas/webhook (#1…
dependabot[bot] Dec 7, 2021
a15e43e
chore: Bump @types/node in /modules/webhook/lambdas/webhook (#1500)
dependabot[bot] Dec 8, 2021
b2c5690
chore: Bump aws-sdk in /modules/runners/lambdas/runners (#1497)
dependabot[bot] Dec 8, 2021
edd0d0f
chore: Bump aws-sdk (#1494)
dependabot[bot] Dec 8, 2021
a6c2bcb
chore: Bump aws-sdk in /modules/webhook/lambdas/webhook (#1499)
dependabot[bot] Dec 8, 2021
007e7c6
chore: Bump @types/node in /modules/runners/lambdas/runners (#1496)
dependabot[bot] Dec 8, 2021
d1e16ab
chore: Bump ts-jest (#1489)
dependabot[bot] Dec 8, 2021
625331f
chore: Bump ts-jest in /modules/webhook/lambdas/webhook (#1502)
dependabot[bot] Dec 8, 2021
e883924
chore: Bump ts-jest in /modules/runners/lambdas/runners (#1501)
dependabot[bot] Dec 8, 2021
83bb07b
chore: Bump @vercel/ncc in /modules/webhook/lambdas/webhook (#1498)
dependabot[bot] Dec 8, 2021
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
6 changes: 2 additions & 4 deletions .github/workflows/lambda-runner-binaries-syncer.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
name: Lambda Syncer
env:
lambda_name: runner-binaries-syncer
lambda_path: modules/runner-binaries-syncer/lambdas/runner-binaries-syncer
on:
push:
branches:
Expand All @@ -17,7 +14,8 @@ jobs:
container: node:14
defaults:
run:
working-directory: ${{ env.lambda_path }}
working-directory: modules/runner-binaries-syncer/lambdas/runner-binaries-syncer

steps:
- uses: actions/checkout@v2
- name: Install dependencies
Expand Down
4 changes: 2 additions & 2 deletions examples/ubuntu/templates/user-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ echo export PATH=/home/$USER_NAME/bin:$PATH >>/home/$USER_NAME/.profile
loginctl enable-linger $USER_NAME
su -l $USER_NAME -c "systemctl --user enable docker"

${install_config_runner}
${install_runner}

# config runner for rootless docker
cd /home/$USER_NAME/actions-runner/
Expand All @@ -68,4 +68,4 @@ echo PATH=/home/$USER_NAME/bin:$PATH >>.env

${post_install}

./svc.sh start
${start_runner}
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
collectCoverage: true,
collectCoverageFrom: ['src/**/*.{ts,js,jsx}', '!src/**/*local*.ts'],
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@
"@types/request": "^2.48.4",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"@vercel/ncc": "^0.32.0",
"aws-sdk": "^2.1040.0",
"@vercel/ncc": "^0.33.0",
"aws-sdk": "^2.1044.0",
"eslint": "^7.32.0",
"eslint-plugin-prettier": "4.0.0",
"jest": "^27.4.3",
"prettier": "2.5.0",
"ts-jest": "^27.0.7",
"prettier": "2.5.1",
"ts-jest": "^27.1.0",
"ts-node-dev": "^1.1.6",
"typescript": "^4.5.2"
},
"dependencies": {
"tslog": "^3.3.0",
"axios": "^0.24.0"
"axios": "^0.24.0",
"tslog": "^3.3.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { sync } from './syncer/syncer';
import { handler } from './lambda';
import { mocked } from 'ts-jest/utils';

jest.mock('./syncer/syncer');

describe('Test download sync wrapper.', () => {
it('Test successful download.', async () => {
const mock = mocked(sync);
mock.mockImplementation(() => {
return new Promise((resolve) => {
resolve();
});
});
await expect(handler({}, {})).resolves;
});

it('Test wrapper with returning an error. ', async () => {
const mock = mocked(sync);
mock.mockRejectedValue(new Error(''));

await expect(handler({}, {})).resolves;
});
});
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { handle } from './syncer/handler';
import { sync } from './syncer/syncer';
import { logger } from './syncer/logger';

// eslint-disable-next-line
export const handler = async (event: any, context: any, callback: any): Promise<void> => {
export async function handler(event: any, context: any): Promise<void> {
logger.setSettings({ requestId: context.awsRequestId });
logger.debug(JSON.stringify(event));

try {
await handle();
callback(null);
await sync();
} catch (e) {
callback(e);
logger.warn('Ignoring error:', e);
}
};
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { handle } from './syncer/handler';
import { sync } from './syncer/syncer';

handle()
sync()
.then()
.catch((e) => {
console.log(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { handle } from './handler';
import { sync } from './syncer';
import listReleases from '../../test/resources/github-list-releases.json';
import listReleasesEmpty from '../../test/resources/github-list-releases-empty-assets.json';
import listReleasesNoLinux from '../../test/resources/github-list-releases-no-linux.json';
import listReleasesNoArm64 from '../../test/resources/github-list-releases-no-arm64.json';
import { S3 } from 'aws-sdk';
import axios from 'axios';
import { request } from 'http';
import { EventEmitter, PassThrough, Readable } from 'stream';

const mockOctokit = {
repos: {
Expand All @@ -13,9 +17,23 @@ jest.mock('@octokit/rest', () => ({
Octokit: jest.fn().mockImplementation(() => mockOctokit),
}));

// mock stream for Axios
const mockResponse = `{"data": 123}`;
const mockStream = new PassThrough();
mockStream.push(mockResponse);
mockStream.end();

jest.mock('axios');
const mockedAxios = axios as jest.Mocked<typeof axios>;
mockedAxios.request.mockResolvedValue({
data: mockStream,
});

const mockS3 = {
getObjectTagging: jest.fn(),
upload: jest.fn(),
upload: jest.fn().mockImplementation(() => {
return { promise: jest.fn(() => Promise.resolve()) };
}),
};
jest.mock('aws-sdk', () => ({
S3: jest.fn().mockImplementation(() => mockS3),
Expand All @@ -27,6 +45,8 @@ beforeEach(() => {
jest.clearAllMocks();
});

jest.setTimeout(60 * 1000);

describe('Synchronize action distribution.', () => {
beforeEach(() => {
process.env.S3_BUCKET_NAME = bucketName;
Expand All @@ -47,7 +67,7 @@ describe('Synchronize action distribution.', () => {
};
});

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

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

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

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

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

await handle();
await sync();
expect(mockOctokit.repos.listReleases).toBeCalledTimes(1);
expect(mockS3.getObjectTagging).toBeCalledWith({
Bucket: bucketName,
Expand Down Expand Up @@ -183,7 +203,7 @@ describe('Synchronize action distribution.', () => {
};
});

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

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

await handle();
await sync();
expect(mockOctokit.repos.listReleases).toBeCalledTimes(1);
expect(mockS3.getObjectTagging).toBeCalledWith({
Bucket: bucketName,
Expand All @@ -243,15 +263,15 @@ describe('No release assets found.', () => {
data: listReleasesEmpty,
}));

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

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

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

Expand All @@ -260,17 +280,17 @@ describe('Invalid config', () => {
it('No bucket and object key.', async () => {
delete process.env.S3_OBJECT_KEY;
delete process.env.S3_BUCKET_NAME;
await expect(handle()).rejects.toThrow(errorMessage);
await expect(sync()).rejects.toThrow(errorMessage);
});
it('No bucket.', async () => {
delete process.env.S3_BUCKET_NAME;
process.env.S3_OBJECT_KEY = bucketObjectKey;
await expect(handle()).rejects.toThrow(errorMessage);
await expect(sync()).rejects.toThrow(errorMessage);
});
it('No object key.', async () => {
delete process.env.S3_OBJECT_KEY;
process.env.S3_BUCKET_NAME = bucketName;
await expect(handle()).rejects.toThrow(errorMessage);
await expect(sync()).rejects.toThrow(errorMessage);
});
});

Expand All @@ -287,6 +307,6 @@ describe('Synchronize action distribution for arm64.', () => {
data: [listReleasesNoArm64],
}));

await expect(handle()).rejects.toThrow(errorMessage);
await expect(sync()).rejects.toThrow(errorMessage);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ async function uploadToS3(s3: S3, cacheObject: CacheObject, actionRunnerReleaseA
});
}

export const handle = async (): Promise<void> => {
export async function sync(): Promise<void> {
const s3 = new AWS.S3();

const runnerArch = process.env.GITHUB_RUNNER_ARCHITECTURE || 'x64';
Expand All @@ -125,8 +125,8 @@ export const handle = async (): Promise<void> => {
const currentVersion = await getCachedVersion(s3, cacheObject);
logger.debug('latest: ' + currentVersion);
if (currentVersion === undefined || currentVersion != actionRunnerReleaseAsset.name) {
uploadToS3(s3, cacheObject, actionRunnerReleaseAsset);
await uploadToS3(s3, cacheObject, actionRunnerReleaseAsset);
} else {
logger.debug('Distribution is up-to-date, no action.');
}
};
}
Loading