Skip to content

Commit

Permalink
Merge pull request #535 from Tradeshift/POPS-2928_1
Browse files Browse the repository at this point in the history
fix: add support when using GH hosted runners
  • Loading branch information
arminioa authored Jul 26, 2023
2 parents 1971a90 + f47e1f1 commit 4f26e9c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 6 deletions.
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ inputs:
description: >
This flag can be used to enable Qemu, which is used for multi architecture builds like arm
default: "false"
aws-access-key-id:
required: false
description: >
AWS Access Key ID is required if runners are hosted by GitHub.
aws-secret-access-key:
required: false
description: >
AWS Secret Key is required if runners are hosted by GitHub.
outputs:
builder:
description: buildx builder name
Expand Down
23 changes: 21 additions & 2 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion src/aws.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as semver from 'semver';

import {info} from '@actions/core';
import {info, setSecret, exportVariable} from '@actions/core';
import {which} from '@actions/io';
import {getExecOutput} from '@actions/exec';

Expand Down Expand Up @@ -153,3 +153,17 @@ export async function getECRPassword(repository: string): Promise<string> {

return getDockerLoginPWD(repository, region);
}

export function exportCredentials(
accessKeyId: string,
secretAccessKey: string
): void {
if (accessKeyId && secretAccessKey) {
info('Use AWS credentials.');

setSecret(accessKeyId);
exportVariable('AWS_ACCESS_KEY_ID', accessKeyId);
setSecret(secretAccessKey);
exportVariable('AWS_SECRET_ACCESS_KEY', secretAccessKey);
}
}
16 changes: 14 additions & 2 deletions src/inputs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {getECRPassword, isECRRepository} from './aws';
import {getECRPassword, isECRRepository, exportCredentials} from './aws';
import {context} from '@actions/github';
import csvparse from 'csv-parse/lib/sync';
import {getInput, getMultilineInput} from '@actions/core';
Expand All @@ -22,6 +22,13 @@ export interface Inputs {
username: string;
authOnly: boolean;
useqemu: boolean;
awsAccessKeyId: string;
awsSecretAccessKey: string;
}

function isSelfHostedRunner(): boolean {
const labels = process.env.RUNNER_LABELS || '';
return labels?.includes('self-hosted');
}

export async function getInputs(): Promise<Inputs> {
Expand All @@ -43,9 +50,14 @@ export async function getInputs(): Promise<Inputs> {
tags: await getInputList('tags'),
username: getInput('username'),
authOnly: getInput('auth-only') === 'true',
useqemu: getInput('useqemu') === 'true'
useqemu: getInput('useqemu') === 'true',
awsAccessKeyId: getInput('aws-access-key-id'),
awsSecretAccessKey: getInput('aws-secret-access-key')
};
if (isECRRepository(inputs.repository)) {
if (!isSelfHostedRunner()) {
exportCredentials(inputs.awsAccessKeyId, inputs.awsSecretAccessKey);
}
inputs.username = 'AWS';
inputs.password = await getECRPassword(inputs.repository);
}
Expand Down

0 comments on commit 4f26e9c

Please sign in to comment.