parent
1a211c6f27
commit
25aa6aa30c
@ -0,0 +1,40 @@
|
|||||||
|
name: test
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- releases/v*
|
||||||
|
paths-ignore:
|
||||||
|
- '**.md'
|
||||||
|
pull_request:
|
||||||
|
paths-ignore:
|
||||||
|
- '**.md'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os:
|
||||||
|
- ubuntu-20.04
|
||||||
|
- ubuntu-18.04
|
||||||
|
- ubuntu-16.04
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v2.3.2
|
||||||
|
-
|
||||||
|
name: Install
|
||||||
|
run: yarn install
|
||||||
|
-
|
||||||
|
name: Test
|
||||||
|
run: yarn run test
|
||||||
|
-
|
||||||
|
name: Upload coverage
|
||||||
|
uses: codecov/codecov-action@v1.0.13
|
||||||
|
if: success()
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
|
file: ./coverage/clover.xml
|
@ -0,0 +1,46 @@
|
|||||||
|
import * as semver from 'semver';
|
||||||
|
import * as aws from '../src/aws';
|
||||||
|
|
||||||
|
describe('isECR', () => {
|
||||||
|
test.each([
|
||||||
|
['registry.gitlab.com', false],
|
||||||
|
['gcr.io', false],
|
||||||
|
['012345678901.dkr.ecr.eu-west-3.amazonaws.com', true]
|
||||||
|
])('given registry %p', async (registry, expected) => {
|
||||||
|
expect(await aws.isECR(registry)).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getCLI', () => {
|
||||||
|
it('exists', async () => {
|
||||||
|
const awsPath = await aws.getCLI();
|
||||||
|
console.log(`awsPath: ${awsPath}`);
|
||||||
|
expect(awsPath).not.toEqual('');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getCLIVersion', () => {
|
||||||
|
it('valid', async () => {
|
||||||
|
const cliVersion = await aws.getCLIVersion();
|
||||||
|
console.log(`cliVersion: ${cliVersion}`);
|
||||||
|
expect(semver.valid(cliVersion)).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('parseCLIVersion', () => {
|
||||||
|
test.each([
|
||||||
|
['v1', 'aws-cli/1.18.120 Python/2.7.17 Linux/5.3.0-1034-azure botocore/1.17.43', '1.18.120'],
|
||||||
|
['v2', 'aws-cli/2.0.41 Python/3.7.3 Linux/4.19.104-microsoft-standard exe/x86_64.ubuntu.18', '2.0.41']
|
||||||
|
])('given aws %p', async (version, stdout, expected) => {
|
||||||
|
expect(await aws.parseCLIVersion(stdout)).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getRegion', () => {
|
||||||
|
test.each([['012345678901.dkr.ecr.eu-west-3.amazonaws.com', 'eu-west-3']])(
|
||||||
|
'given registry %p',
|
||||||
|
async (registry, expected) => {
|
||||||
|
expect(await aws.getRegion(registry)).toEqual(expected);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,12 @@
|
|||||||
|
module.exports = {
|
||||||
|
clearMocks: true,
|
||||||
|
moduleFileExtensions: ['js', 'ts'],
|
||||||
|
setupFiles: ["dotenv/config"],
|
||||||
|
testEnvironment: 'node',
|
||||||
|
testMatch: ['**/*.test.ts'],
|
||||||
|
testRunner: 'jest-circus/runner',
|
||||||
|
transform: {
|
||||||
|
'^.+\\.ts$': 'ts-jest'
|
||||||
|
},
|
||||||
|
verbose: false
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
import * as semver from 'semver';
|
||||||
|
import * as io from '@actions/io';
|
||||||
|
import * as execm from './exec';
|
||||||
|
|
||||||
|
export const isECR = async (registry: string): Promise<boolean> => {
|
||||||
|
return registry.includes('amazonaws');
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getCLI = async (): Promise<string> => {
|
||||||
|
return io.which('aws', true);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getCLIVersion = async (): Promise<string | undefined> => {
|
||||||
|
return execm.exec('aws', ['--version'], true).then(res => {
|
||||||
|
if (res.stderr != '' && !res.success) {
|
||||||
|
throw new Error(res.stderr);
|
||||||
|
}
|
||||||
|
return parseCLIVersion(res.stdout);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const parseCLIVersion = async (stdout: string): Promise<string | undefined> => {
|
||||||
|
const matches = /aws-cli\/([0-9.]+)/.exec(stdout);
|
||||||
|
if (matches) {
|
||||||
|
return semver.clean(matches[1]);
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getRegion = async (registry: string): Promise<string> => {
|
||||||
|
return registry.substring(registry.indexOf('ecr.') + 4, registry.indexOf('.amazonaws'));
|
||||||
|
};
|
@ -1,7 +0,0 @@
|
|||||||
export const isECR = async (registry: string): Promise<boolean> => {
|
|
||||||
return registry.includes('amazonaws');
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getRegion = async (registry: string): Promise<string> => {
|
|
||||||
return registry.substring(registry.indexOf('ecr.') + 4, registry.indexOf('.amazonaws'));
|
|
||||||
};
|
|
Loading…
Reference in New Issue