Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyMax committed Aug 21, 2020
1 parent 25aa6aa commit 04f461c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
10 changes: 9 additions & 1 deletion __tests__/aws.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,19 @@ describe('getCLI', () => {
});
});

describe('getCLICmdOutput', () => {
it('--version not empty', async () => {
const cliCmdOutput = await aws.getCLICmdOutput(['--version']);
console.log(`cliCmdOutput: ${cliCmdOutput}`);
expect(cliCmdOutput).not.toEqual('');
});
});

describe('getCLIVersion', () => {
it('valid', async () => {
const cliVersion = await aws.getCLIVersion();
console.log(`cliVersion: ${cliVersion}`);
expect(semver.valid(cliVersion)).toBe(true);
expect(semver.valid(cliVersion)).not.toBeNull();
});
});

Expand Down
20 changes: 10 additions & 10 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions src/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ 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 => {
export const getCLICmdOutput = async (args: string[]): Promise<string> => {
return execm.exec(await getCLI(), args, true).then(res => {
if (res.stderr != '' && !res.success) {
throw new Error(res.stderr);
}
return parseCLIVersion(res.stdout);
return res.stdout;
});
};

export const getCLIVersion = async (): Promise<string | undefined> => {
return parseCLIVersion(await getCLICmdOutput(['--version']));
};

export const parseCLIVersion = async (stdout: string): Promise<string | undefined> => {
const matches = /aws-cli\/([0-9.]+)/.exec(stdout);
if (matches) {
Expand Down
10 changes: 4 additions & 6 deletions src/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,11 @@ export async function loginECR(registry: string, username: string, password: str

process.env.AWS_ACCESS_KEY_ID = username;
process.env.AWS_SECRET_ACCESS_KEY = password;
core.info(`⬇️ Retrieving docker login command through AWS CLI ${cliVersion}...`);
await execm.exec(cliPath, ['ecr', 'get-login', '--region', ecrRegion, '--no-include-email'], true).then(res => {
if (res.stderr != '' && !res.success) {
throw new Error(res.stderr);
}

core.info(`⬇️ Retrieving docker login command through AWS CLI ${cliVersion} (${cliPath})...`);
aws.getCLICmdOutput(['ecr', 'get-login', '--region', ecrRegion, '--no-include-email']).then(stdout => {
core.info(`🔑 Logging into ${registry}...`);
execm.exec(res.stdout, [], true).then(res => {
execm.exec(stdout, [], true).then(res => {
if (res.stderr != '' && !res.success) {
throw new Error(res.stderr);
}
Expand Down

0 comments on commit 04f461c

Please sign in to comment.