From d70eb2fbc976ce7042b606e149c69b7dc677dda6 Mon Sep 17 00:00:00 2001 From: Jason Watson Date: Wed, 23 Aug 2023 17:02:29 +0100 Subject: [PATCH] feat: add parameter override by file --- .github/workflows/test.yml | 2 +- action.yml | 7 ++++++- dist/index.js | 13 +++++++++++-- src/index.ts | 19 ++++++++++++++++--- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 712c67c..eba5a9a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -47,7 +47,7 @@ jobs: executeChangeSet: true enableRollback: false terminationProtection: false - parameterOverrides: 'test/parameters.json' + parameterOverridesFilePath: 'test/parameters.json' - name: Integration tests run: | diff --git a/action.yml b/action.yml index 3ac83ab..766f2a6 100644 --- a/action.yml +++ b/action.yml @@ -10,7 +10,7 @@ inputs: templateFile: description: 'The relative path to the template file' - required: true + required: false default: '' templateUrl: @@ -68,6 +68,11 @@ inputs: required: false default: '{}' + parameterOverridesFilePath: + description: 'The path to the parameter overrides file' + required: false + default: '' + runs: using: node16 main: dist/index.js diff --git a/dist/index.js b/dist/index.js index 0b4ac11..74c5e4c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -268,6 +268,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.run = void 0; const core = __importStar(__nccwpck_require__(42186)); +const fs_1 = __importDefault(__nccwpck_require__(57147)); const path_1 = __importDefault(__nccwpck_require__(71017)); const cloud_formation_stack_1 = __nccwpck_require__(10175); const AWS_ENDPOINT_URL = process.env['AWS_ENDPOINT_URL']; @@ -289,11 +290,15 @@ async function run() { const tags = core.getInput('tags') || '{}'; const notificationArn = core.getInput('notificationArn'); const terminationProtection = core.getInput('terminationProtection'); - const parameterOverrides = core.getInput('parameterOverrides') || '{}'; + const parameterOverridesInput = core.getInput('parameterOverrides') || '[]'; + const parameterOverridesFilePath = core.getInput('parameterOverridesFilePath'); const deleteFailedChangeSet = core.getInput('deleteFailedChangeSet'); const template = templateFilePath ? { filepath: path_1.default.join(GITHUB_WORKSPACE, templateFilePath) } : { url: templateUrl }; + const parameterOverrides = parameterOverridesFilePath + ? loadFile(path_1.default.join(GITHUB_WORKSPACE, parameterOverridesFilePath)) + : JSON.parse(parameterOverridesInput); const stack = cloud_formation_stack_1.CloudFormationStack.createStack({ stack: { name: stackName, @@ -307,7 +312,7 @@ async function run() { roleArn, tags: JSON.parse(tags), notificationArn, - parameterOverrides: JSON.parse(parameterOverrides), + parameterOverrides: parameterOverrides, deleteFailedChangeSet: new Boolean(deleteFailedChangeSet), }, client: { @@ -324,6 +329,10 @@ async function run() { console.error(error); core.setFailed('Action failed'); } + function loadFile(filepath) { + const data = fs_1.default.readFileSync(filepath, 'utf8'); + return JSON.parse(data); + } } exports.run = run; run(); diff --git a/src/index.ts b/src/index.ts index 96e8fd4..6b3fcc2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ import * as core from '@actions/core'; +import fs from 'fs'; import path from 'path'; import { CloudFormationStack } from './cloudformation/stack/cloud-formation-stack'; @@ -25,13 +26,20 @@ export async function run() { const tags = core.getInput('tags') || '{}'; const notificationArn = core.getInput('notificationArn'); const terminationProtection = core.getInput('terminationProtection'); - const parameterOverrides = core.getInput('parameterOverrides') || '[]'; + const parameterOverridesInput = core.getInput('parameterOverrides') || '[]'; + const parameterOverridesFilePath = core.getInput('parameterOverridesFilePath'); const deleteFailedChangeSet = core.getInput('deleteFailedChangeSet'); - // filepath takes precedence over url + + // template filepath takes precedence over url const template: Template = templateFilePath ? { filepath: path.join(GITHUB_WORKSPACE, templateFilePath) } : { url: templateUrl }; + // parameterOverrides filepath takes precedence over url + const parameterOverrides = parameterOverridesFilePath + ? loadFile(path.join(GITHUB_WORKSPACE, parameterOverridesFilePath)) + : JSON.parse(parameterOverridesInput); + const stack = CloudFormationStack.createStack({ stack: { name: stackName, @@ -45,7 +53,7 @@ export async function run() { roleArn, tags: JSON.parse(tags), notificationArn, - parameterOverrides: JSON.parse(parameterOverrides), + parameterOverrides: parameterOverrides, deleteFailedChangeSet: new Boolean(deleteFailedChangeSet) as boolean, }, client: { @@ -63,6 +71,11 @@ export async function run() { console.error(error); core.setFailed('Action failed'); } + + function loadFile(filepath: string) { + const data = fs.readFileSync(filepath, 'utf8'); + return JSON.parse(data); + } } // eslint-disable-next-line @typescript-eslint/no-floating-promises