Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add multi-value repository parameter #573

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,27 @@ The purpose of Trebuchet is to improve the quality of life for pushing Docker im
repository: ${{ secrets.REPOSITORY }}
tag: ${{ secrets.TAG }}
```
or, if uploading multiple images at the same time

```
- uses: HylandSoftware/trebuchet-action@v1
with:
action: copy
source-account-id: ${{ secrets.SOURCE_ACCOUNT_ID }}
source-role-arn: ${{ secrets.SOURCE_ROLE }}
tag: ${{ secrets.TAG }}
repositories: |
${{ secrets.REPOSITORY1 }}
${{ secrets.REPOSITORY2 }}
${{ secrets.REPOSITORY3 }}

```

| Paramater | Required | Default | Description |
| ---------- | ------- | ------- | ----------- |
| action | true | n/a | The command to execute, `push` or `copy` are the currently supported actions. |
| repository | true | n/a | The name of the image in either the local docker or remote registry. |
| repository | false | n/a | The name of the image in either the local docker or remote registry. Mutually exclusive with repositories. |
| repositories | false | n/a | The names of the images in either the local docker or remote registry separated by a new line. Mutually exclusive with repository. |
| tag | true | n/a | The tag of the image to use when performing the action. |
| region | false | ENV_VAR | The AWS region to execute against. It will use this property or pull from the AWS_DEFAULT_REGION Environment variable. |
| source-account-id | false | CURRENT_ACCOUNT | The account id of the source AWS account for a pull / copy, if different than the default account id. |
Expand Down
9 changes: 7 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ inputs:
description: 'The role arn to use when pulling the image from ECR. Only needed when the source role is different from the default environment credentials.'
default: ''
repository:
required: true
description: 'The name of the image in either the local docker or remote registry.'
required: false
description: 'The name of the image in either the local docker or remote registry. Mutually exclusive with repositories.'
default: ''
repositories:
required: false
description: 'The names of the images in either the local docker or remote registry separated by a new line. Mutually exclusive with repository.'
default: ''
tag:
required: true
description: 'The tag of the image to use when performing the action'
Expand Down
50 changes: 34 additions & 16 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.

52 changes: 38 additions & 14 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,25 @@ async function run(): Promise<void> {
//const region: string = core.getInput('region');

const action: string = core.getInput('action');
const repository: string = core.getInput('repository');
const repositoryInput: string = core.getInput('repository');
const repositoriesInput: string = core.getInput('repositories');
const tag: string = core.getInput('tag');
const sourceAccountId = core.getInput('source-account-id');
const sourceRoleArn = core.getInput('source-role-arn');
const immutable: boolean =
(core.getInput('immutable', { required: false }) || 'false') === 'true';
const ecrClient = new ECR({});

if (repository === undefined || repository.length === 0) {
core.setFailed('Repository parameter is missing');
if (repositoryInput !== undefined && repositoriesInput !== undefined) {
core.setFailed('Repository and Repositories cannot both be set.');
return;
}

if (
(repositoryInput === undefined || repositoryInput.length === 0) &&
(repositoriesInput === undefined || repositoriesInput.length === 0)
) {
core.setFailed('Repository or Repositories parameter is required');
return;
}

Expand All @@ -28,10 +37,23 @@ async function run(): Promise<void> {
return;
}

let repositories;

if (repositoryInput !== undefined && repositoryInput.length > 0) {
repositories = [repositoryInput];
} else {
repositories = repositoriesInput.split(/\r\n|\r|\n/g);
if (repositories === undefined || repositories.length === 0) {
core.setFailed('Repositories parameter is set to an invalid value');
}
}

switch (action) {
case 'push': {
const push = new Push(ecrClient, repository, tag, immutable);
await push.execute();
for (const repository of repositories) {
const push = new Push(ecrClient, repository, tag, immutable);
await push.execute();
}
break;
}
//case 'pull': {
Expand All @@ -40,15 +62,17 @@ async function run(): Promise<void> {
// break;
//}
case 'copy': {
const promote = new Copy(
ecrClient,
sourceRoleArn,
sourceAccountId,
repository,
tag,
immutable
);
await promote.execute();
for (const repository of repositories) {
const promote = new Copy(
ecrClient,
sourceRoleArn,
sourceAccountId,
repository,
tag,
immutable
);
await promote.execute();
}
break;
}
default: {
Expand Down
Loading