Skip to content

Commit

Permalink
feat: add parameter override by file
Browse files Browse the repository at this point in the history
  • Loading branch information
jbw committed Aug 23, 2023
1 parent 13e6d70 commit d70eb2f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
executeChangeSet: true
enableRollback: false
terminationProtection: false
parameterOverrides: 'test/parameters.json'
parameterOverridesFilePath: 'test/parameters.json'

- name: Integration tests
run: |
Expand Down
7 changes: 6 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ inputs:

templateFile:
description: 'The relative path to the template file'
required: true
required: false
default: ''

templateUrl:
Expand Down Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -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,
Expand All @@ -307,7 +312,7 @@ async function run() {
roleArn,
tags: JSON.parse(tags),
notificationArn,
parameterOverrides: JSON.parse(parameterOverrides),
parameterOverrides: parameterOverrides,
deleteFailedChangeSet: new Boolean(deleteFailedChangeSet),
},
client: {
Expand All @@ -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();
Expand Down
19 changes: 16 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand All @@ -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: {
Expand All @@ -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
Expand Down

0 comments on commit d70eb2f

Please sign in to comment.