mirror of
https://github.com/docker/login-action.git
synced 2025-04-20 18:16:45 +00:00
Check AWS CLI version
Add tests
This commit is contained in:
parent
1a211c6f27
commit
25aa6aa30c
10 changed files with 5905 additions and 49 deletions
32
src/aws.ts
Normal file
32
src/aws.ts
Normal file
|
@ -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'));
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue