|
| 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 | +} |
0 commit comments