Skip to content

Commit

Permalink
Moved params extraction to seperate function and fixed docs
Browse files Browse the repository at this point in the history
  • Loading branch information
oryanmoshe committed Mar 4, 2020
1 parent d352050 commit ee95580
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 56 deletions.
48 changes: 31 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,6 @@ This action allows you to wait for services to become stable **and** retry the w

## Inputs

### `aws-access-key-id`

**Required** - _string_\
Your `AWS_ACCESS_KEY_ID`.

### `aws-secret-access-key` - ``

**Required** - _string_\
Your `AWS_SECRET_ACCESS_KEY`.

### `aws-region`

**Required** - _string_\
Your `AWS_REGION`.

### `ecs-cluster`

**Required** - _string_\
Expand All @@ -32,9 +17,27 @@ A list of ECS services to make sure are stable.

### `retries`

**Required** - _integer_\
_Optional_ - _integer_\
The number of times you want to try the stability check. Default `2`.

### `aws-access-key-id`

_Optional_ - _string_\
Your AWS ACCESS_KEY_ID.\
Must be provided as an input / defined as an environment variable.

### `aws-secret-access-key`

_Optional_ - _string_\
Your AWS SECRET_ACCESS_KEY.\
Must be provided as an input / defined as an environment variable.

### `aws-region`

_Optional_ - _string_\
Your AWS REGION.\
Must be provided as an input / defined as an environment variable.

### `verbose`

_Optional_ - _boolean_\
Expand All @@ -49,8 +52,10 @@ How many retries happened until success.

## Example usage

### Using all available options

```yaml
uses: oryanmoshe/ecs-wait-action@v1.1
uses: oryanmoshe/ecs-wait-action@v1.3
with:
aws-access-key-id: AKIAIOSFODNN7EXAMPLE
aws-secret-access-key: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Expand All @@ -60,3 +65,12 @@ with:
retries: 5
verbose: false
```
### Minimal configuration
```yaml
uses: oryanmoshe/[email protected]
with:
ecs-cluster: my-ecs-cluster
ecs-services: '["my-ecs-service-1", "my-ecs-service-2"]'
```
13 changes: 6 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@ name: 'ECS Wait'
author: 'Oryan Moshe'
description: 'Waits for ECS service stability'
inputs:
ecs-cluster:
description: 'The ECS cluster name (string)'
required: true
ecs-services:
description: 'List of ECS services to wait for (string[])'
required: true
retries:
description: 'How many times to retry the 10 minute wait (integer)'
required: true
default: 2
aws-access-key-id:
description: 'The AWS_ACCESS_KEY_ID (string)'
aws-secret-access-key:
description: 'The AWS_SECRET_ACCESS_KEY (string)'
aws-region:
description: 'The AWS_REGION (string)'
ecs-cluster:
description: 'The ECS cluster name (string)'
required: true
ecs-services:
description: 'List of ECS services to wait for (string[])'
required: true
verbose:
description: 'Whether to print the retry log (bool)'
default: false
Expand Down
46 changes: 30 additions & 16 deletions dist/index.js

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

46 changes: 30 additions & 16 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,42 @@ const createEcsConnection = ({ accessKeyId, secretAccessKey, region }) =>
region,
});

/**
* Extracts step params from environment and context
* @returns {Object} The params needed to run this action
*/
const extractParams = () => {
const params = {
accessKeyId:
core.getInput('aws-access-key-id') || process.env.AWS_ACCESS_KEY_ID,
secretAccessKey:
core.getInput('aws-secret-access-key') ||
process.env.AWS_SECRET_ACCESS_KEY,
region: core.getInput('aws-region') || process.env.AWS_REGION,
retries: parseInt(core.getInput('retries'), 10),
cluster: core.getInput('ecs-cluster'),
services: JSON.parse(core.getInput('ecs-services')),
verbose: core.getInput('verbose') === 'true',
};

if (!params.accessKeyId || !params.secretAccessKey || !params.region) {
core.setFailed(
'AWS credentials were not found in inputs or environment variables.'
);
return null;
}

return params;
};

/**
* The GitHub Action entry point.
*/
const main = async () => {
try {
const params = {
accessKeyId:
core.getInput('aws-access-key-id') || process.env.AWS_ACCESS_KEY_ID,
secretAccessKey:
core.getInput('aws-secret-access-key') ||
process.env.AWS_SECRET_ACCESS_KEY,
region: core.getInput('aws-region') || process.env.AWS_REGION,
retries: parseInt(core.getInput('retries'), 10),
cluster: core.getInput('ecs-cluster'),
services: JSON.parse(core.getInput('ecs-services')),
verbose: core.getInput('verbose') === 'true',
};
const params = extractParams();

if (!params.accessKeyId || !params.secretAccessKey || !params.region) {
core.setFailed(
'AWS credentials were not found in inputs or environment variables.'
);
if (!params) {
return;
}

Expand Down

0 comments on commit ee95580

Please sign in to comment.