mirror of
https://github.com/docker/login-action.git
synced 2025-08-18 18:49:59 +08:00
Handle AWS CLI v2
This commit is contained in:
22
src/aws.ts
22
src/aws.ts
@@ -26,14 +26,26 @@ export const getCLICmdOutput = async (args: string[]): Promise<string> => {
|
||||
});
|
||||
};
|
||||
|
||||
export const getCLIVersion = async (): Promise<string | undefined> => {
|
||||
export const getCLIVersion = async (): Promise<string> => {
|
||||
return parseCLIVersion(await getCLICmdOutput(['--version']));
|
||||
};
|
||||
|
||||
export const parseCLIVersion = async (stdout: string): Promise<string | undefined> => {
|
||||
export const parseCLIVersion = async (stdout: string): Promise<string> => {
|
||||
const matches = /aws-cli\/([0-9.]+)/.exec(stdout);
|
||||
if (matches) {
|
||||
return semver.clean(matches[1]);
|
||||
if (!matches) {
|
||||
throw new Error(`Cannot parse AWS CLI version`);
|
||||
}
|
||||
return semver.clean(matches[1]);
|
||||
};
|
||||
|
||||
export const getECRLoginCmd = async (cliVersion: string, registry: string, region: string): Promise<string> => {
|
||||
if (semver.satisfies(cliVersion, '>=2.0.0')) {
|
||||
return getCLICmdOutput(['ecr', 'get-login-password', '--region', region]).then(pwd => {
|
||||
return `docker login --username AWS --password ${pwd} ${registry}`;
|
||||
});
|
||||
} else {
|
||||
return getCLICmdOutput(['ecr', 'get-login', '--region', region, '--no-include-email']).then(dockerLoginCmd => {
|
||||
return dockerLoginCmd;
|
||||
});
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
Reference in New Issue
Block a user