mirror of
https://gitea.com/docker/login-action.git
synced 2024-11-22 17:39:35 +01:00
Fix tests
This commit is contained in:
parent
25aa6aa30c
commit
04f461cc60
4 changed files with 30 additions and 20 deletions
|
@ -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', () => {
|
describe('getCLIVersion', () => {
|
||||||
it('valid', async () => {
|
it('valid', async () => {
|
||||||
const cliVersion = await aws.getCLIVersion();
|
const cliVersion = await aws.getCLIVersion();
|
||||||
console.log(`cliVersion: ${cliVersion}`);
|
console.log(`cliVersion: ${cliVersion}`);
|
||||||
expect(semver.valid(cliVersion)).toBe(true);
|
expect(semver.valid(cliVersion)).not.toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
20
dist/index.js
generated
vendored
20
dist/index.js
generated
vendored
|
@ -3023,13 +3023,10 @@ function loginECR(registry, username, password) {
|
||||||
core.info(`💡 AWS ECR registry detected with ${ecrRegion} region`);
|
core.info(`💡 AWS ECR registry detected with ${ecrRegion} region`);
|
||||||
process.env.AWS_ACCESS_KEY_ID = username;
|
process.env.AWS_ACCESS_KEY_ID = username;
|
||||||
process.env.AWS_SECRET_ACCESS_KEY = password;
|
process.env.AWS_SECRET_ACCESS_KEY = password;
|
||||||
core.info(`⬇️ Retrieving docker login command through AWS CLI ${cliVersion}...`);
|
core.info(`⬇️ Retrieving docker login command through AWS CLI ${cliVersion} (${cliPath})...`);
|
||||||
yield execm.exec(cliPath, ['ecr', 'get-login', '--region', ecrRegion, '--no-include-email'], true).then(res => {
|
aws.getCLICmdOutput(['ecr', 'get-login', '--region', ecrRegion, '--no-include-email']).then(stdout => {
|
||||||
if (res.stderr != '' && !res.success) {
|
|
||||||
throw new Error(res.stderr);
|
|
||||||
}
|
|
||||||
core.info(`🔑 Logging into ${registry}...`);
|
core.info(`🔑 Logging into ${registry}...`);
|
||||||
execm.exec(res.stdout, [], true).then(res => {
|
execm.exec(stdout, [], true).then(res => {
|
||||||
if (res.stderr != '' && !res.success) {
|
if (res.stderr != '' && !res.success) {
|
||||||
throw new Error(res.stderr);
|
throw new Error(res.stderr);
|
||||||
}
|
}
|
||||||
|
@ -4102,7 +4099,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.getRegion = exports.parseCLIVersion = exports.getCLIVersion = exports.getCLI = exports.isECR = void 0;
|
exports.getRegion = exports.parseCLIVersion = exports.getCLIVersion = exports.getCLICmdOutput = exports.getCLI = exports.isECR = void 0;
|
||||||
const semver = __importStar(__webpack_require__(383));
|
const semver = __importStar(__webpack_require__(383));
|
||||||
const io = __importStar(__webpack_require__(436));
|
const io = __importStar(__webpack_require__(436));
|
||||||
const execm = __importStar(__webpack_require__(757));
|
const execm = __importStar(__webpack_require__(757));
|
||||||
|
@ -4112,14 +4109,17 @@ exports.isECR = (registry) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
exports.getCLI = () => __awaiter(void 0, void 0, void 0, function* () {
|
exports.getCLI = () => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
return io.which('aws', true);
|
return io.which('aws', true);
|
||||||
});
|
});
|
||||||
exports.getCLIVersion = () => __awaiter(void 0, void 0, void 0, function* () {
|
exports.getCLICmdOutput = (args) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
return execm.exec('aws', ['--version'], true).then(res => {
|
return execm.exec(yield exports.getCLI(), args, true).then(res => {
|
||||||
if (res.stderr != '' && !res.success) {
|
if (res.stderr != '' && !res.success) {
|
||||||
throw new Error(res.stderr);
|
throw new Error(res.stderr);
|
||||||
}
|
}
|
||||||
return exports.parseCLIVersion(res.stdout);
|
return res.stdout;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
exports.getCLIVersion = () => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
|
return exports.parseCLIVersion(yield exports.getCLICmdOutput(['--version']));
|
||||||
|
});
|
||||||
exports.parseCLIVersion = (stdout) => __awaiter(void 0, void 0, void 0, function* () {
|
exports.parseCLIVersion = (stdout) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
const matches = /aws-cli\/([0-9.]+)/.exec(stdout);
|
const matches = /aws-cli\/([0-9.]+)/.exec(stdout);
|
||||||
if (matches) {
|
if (matches) {
|
||||||
|
|
10
src/aws.ts
10
src/aws.ts
|
@ -10,15 +10,19 @@ export const getCLI = async (): Promise<string> => {
|
||||||
return io.which('aws', true);
|
return io.which('aws', true);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getCLIVersion = async (): Promise<string | undefined> => {
|
export const getCLICmdOutput = async (args: string[]): Promise<string> => {
|
||||||
return execm.exec('aws', ['--version'], true).then(res => {
|
return execm.exec(await getCLI(), args, true).then(res => {
|
||||||
if (res.stderr != '' && !res.success) {
|
if (res.stderr != '' && !res.success) {
|
||||||
throw new Error(res.stderr);
|
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> => {
|
export const parseCLIVersion = async (stdout: string): Promise<string | undefined> => {
|
||||||
const matches = /aws-cli\/([0-9.]+)/.exec(stdout);
|
const matches = /aws-cli\/([0-9.]+)/.exec(stdout);
|
||||||
if (matches) {
|
if (matches) {
|
||||||
|
|
|
@ -47,13 +47,11 @@ export async function loginECR(registry: string, username: string, password: str
|
||||||
|
|
||||||
process.env.AWS_ACCESS_KEY_ID = username;
|
process.env.AWS_ACCESS_KEY_ID = username;
|
||||||
process.env.AWS_SECRET_ACCESS_KEY = password;
|
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 => {
|
core.info(`⬇️ Retrieving docker login command through AWS CLI ${cliVersion} (${cliPath})...`);
|
||||||
if (res.stderr != '' && !res.success) {
|
aws.getCLICmdOutput(['ecr', 'get-login', '--region', ecrRegion, '--no-include-email']).then(stdout => {
|
||||||
throw new Error(res.stderr);
|
|
||||||
}
|
|
||||||
core.info(`🔑 Logging into ${registry}...`);
|
core.info(`🔑 Logging into ${registry}...`);
|
||||||
execm.exec(res.stdout, [], true).then(res => {
|
execm.exec(stdout, [], true).then(res => {
|
||||||
if (res.stderr != '' && !res.success) {
|
if (res.stderr != '' && !res.success) {
|
||||||
throw new Error(res.stderr);
|
throw new Error(res.stderr);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue