Skip to content

Commit bb4ecd8

Browse files
swintonclareliguori
authored andcommitted
Add initial implementation
1 parent 6c5c32e commit bb4ecd8

File tree

10 files changed

+5614
-0
lines changed

10 files changed

+5614
-0
lines changed

.eslintrc.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"env": {
3+
"commonjs": true,
4+
"es6": true,
5+
"node": true,
6+
"jest": true
7+
},
8+
"extends": "eslint:recommended",
9+
"globals": {
10+
"Atomics": "readonly",
11+
"SharedArrayBuffer": "readonly"
12+
},
13+
"parserOptions": {
14+
"ecmaVersion": 2018
15+
},
16+
"rules": {
17+
}
18+
}

.gitignore

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# comment this out distribution branches
2+
node_modules/
3+
4+
# Editors
5+
.vscode
6+
7+
# Logs
8+
logs
9+
*.log
10+
npm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
14+
# Runtime data
15+
pids
16+
*.pid
17+
*.seed
18+
*.pid.lock
19+
20+
# Directory for instrumented libs generated by jscoverage/JSCover
21+
lib-cov
22+
23+
# Coverage directory used by tools like istanbul
24+
coverage
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Other Dependency directories
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# Optional npm cache directory
48+
.npm
49+
50+
# Optional eslint cache
51+
.eslintcache
52+
53+
# Optional REPL history
54+
.node_repl_history
55+
56+
# Output of 'npm pack'
57+
*.tgz
58+
59+
# Yarn Integrity file
60+
.yarn-integrity
61+
62+
# dotenv environment variables file
63+
.env
64+
65+
# next.js build output
66+
.next

action.js

Whitespace-only changes.

action.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: 'Setup AWS'
2+
description: 'Setup an AWS CLI compatible environment'
3+
inputs:
4+
aws-access-key-id:
5+
description: 'Your AWS access key id credential'
6+
required: true
7+
aws-secret-access-key:
8+
description: 'Your AWS secret access key credential'
9+
required: true
10+
aws-default-region:
11+
description: 'Default AWS region, e.g. us-east-2'
12+
required: true
13+
aws-default-output:
14+
description: 'Default output format, e.g. json'
15+
required: false
16+
default: json
17+
runs:
18+
using: 'node12'
19+
main: 'dist/index.js'

index.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const path = require('path');
2+
const core = require('@actions/core');
3+
const io = require('@actions/io');
4+
5+
async function run() {
6+
try {
7+
// Get inputs
8+
const accessKeyId = core.getInput('aws-access-key-id', { required: true });
9+
const secretAccessKey = core.getInput('aws-secret-access-key', { required: true });
10+
const defaultRegion = core.getInput('aws-default-region', { required: true });
11+
const outputFormat = core.getInput('aws-default-output', { required: false });
12+
const awsHome = path.join(process.env.RUNNER_TEMP, '.aws');
13+
14+
// Ensure awsHome is a directory that exists
15+
await io.mkdirP(awsHome);
16+
17+
// Configure the AWS CLI using environment variables
18+
19+
// AWS_ACCESS_KEY_ID:
20+
// Specifies an AWS access key associated with an IAM user or role
21+
core.exportVariable('AWS_ACCESS_KEY_ID', accessKeyId);
22+
23+
// AWS_SECRET_ACCESS_KEY:
24+
// Specifies the secret key associated with the access key. This is essentially the "password" for the access key.
25+
core.exportVariable('AWS_SECRET_ACCESS_KEY', secretAccessKey);
26+
27+
// AWS_DEFAULT_REGION:
28+
// Specifies the AWS Region to send requests to
29+
core.exportVariable('AWS_DEFAULT_REGION', defaultRegion);
30+
31+
// AWS_DEFAULT_OUTPUT:
32+
// Specifies the output format to use
33+
core.exportVariable('AWS_DEFAULT_OUTPUT', outputFormat);
34+
35+
// AWS_CONFIG_FILE:
36+
// Specifies the location of the file that the AWS CLI uses to store configuration profiles.
37+
core.exportVariable('AWS_CONFIG_FILE', path.join(awsHome, 'config'));
38+
39+
// AWS_SHARED_CREDENTIALS_FILE:
40+
// Specifies the location of the file that the AWS CLI uses to store access keys.
41+
core.exportVariable('AWS_SHARED_CREDENTIALS_FILE', path.join(awsHome, 'credentials'));
42+
}
43+
catch (error) {
44+
core.setFailed(error.message);
45+
}
46+
}
47+
48+
module.exports = run;
49+
50+
/* istanbul ignore next */
51+
if (require.main === module) {
52+
run();
53+
}

index.test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const core = require('@actions/core');
2+
const io = require('@actions/io');
3+
4+
const run = require('.');
5+
6+
jest.mock('@actions/core');
7+
jest.mock('@actions/io');
8+
9+
describe('Setup AWS', () => {
10+
11+
beforeEach(() => {
12+
jest.clearAllMocks();
13+
14+
core.getInput = jest
15+
.fn()
16+
.mockReturnValueOnce('MY-AWS-ACCESS-KEY-ID') // aws-access-key-id
17+
.mockReturnValueOnce('MY-AWS-SECRET-ACCESS-KEY') // aws-secret-access-key
18+
.mockReturnValueOnce('us-east-2') // aws-default-region
19+
.mockReturnValueOnce('json'); // aws-default-output
20+
});
21+
22+
test('exports env vars', async () => {
23+
await run();
24+
expect(core.exportVariable).toHaveBeenCalledTimes(6);
25+
expect(core.exportVariable).toHaveBeenCalledWith('AWS_ACCESS_KEY_ID', 'MY-AWS-ACCESS-KEY-ID');
26+
expect(core.exportVariable).toHaveBeenCalledWith('AWS_SECRET_ACCESS_KEY', 'MY-AWS-SECRET-ACCESS-KEY');
27+
expect(core.exportVariable).toHaveBeenCalledWith('AWS_DEFAULT_REGION', 'us-east-2');
28+
expect(core.exportVariable).toHaveBeenCalledWith('AWS_DEFAULT_OUTPUT', 'json');
29+
expect(core.exportVariable).toHaveBeenCalledWith('AWS_CONFIG_FILE', '/runner/home/.aws/config');
30+
expect(core.exportVariable).toHaveBeenCalledWith('AWS_SHARED_CREDENTIALS_FILE', '/runner/home/.aws/credentials');
31+
});
32+
33+
test('aws can be configured for a different region', async () => {
34+
core.getInput = jest
35+
.fn()
36+
.mockReturnValueOnce('MY-AWS-ACCESS-KEY-ID') // aws-access-key-id
37+
.mockReturnValueOnce('MY-AWS-SECRET-ACCESS-KEY') // aws-secret-access-key
38+
.mockReturnValueOnce('eu-west-1') // aws-default-region
39+
.mockReturnValueOnce('json'); // aws-default-output
40+
41+
await run();
42+
expect(core.exportVariable).toHaveBeenCalledWith('AWS_DEFAULT_REGION', 'eu-west-1');
43+
});
44+
45+
test('error is caught by core.setFailed', async () => {
46+
io.mkdirP = jest
47+
.fn()
48+
.mockImplementation(() => {
49+
throw new Error();
50+
});
51+
52+
await run();
53+
54+
expect(core.setFailed).toBeCalled();
55+
});
56+
});

jest.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
testEnvironment: 'node',
3+
setupFiles: ['./jest.setup-env.js']
4+
};

jest.setup-env.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
process.env.RUNNER_TEMP = '/runner/home';

0 commit comments

Comments
 (0)