Skip to content

Commit

Permalink
chore: clean up github construct
Browse files Browse the repository at this point in the history
  • Loading branch information
ap0nia committed Jul 15, 2023
1 parent e5e03c7 commit 817a0c7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
4 changes: 1 addition & 3 deletions ant.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class MyStack extends Stack {
repo,
ref,
required_contexts: [],
environment: "staging - docs",
environment: "staging - api",
});

if (apiDeployment.status !== 201) {
Expand All @@ -102,8 +102,6 @@ export class MyStack extends Stack {
🚀 Staging instances deployed!
API - ${apiDeploymentStatus.data.environment_url}
Docs - ${apiDeploymentStatus.data.environment_url}
`,
});
},
Expand Down
30 changes: 17 additions & 13 deletions packages/ant-stack/src/cdk/constructs/GitHub/GitHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ export class GitHub<T extends Outputs = Outputs> extends Construct {

public readonly outputsFile: string;

public readonly stackName: string;
/**
* The stack that this construct is defined in.
*/
public readonly stack: Stack;

public readonly outputs: Record<PropertyKey, CfnOutput>;

Expand All @@ -51,31 +54,32 @@ export class GitHub<T extends Outputs = Outputs> extends Construct {

this.outputsFile = config.outputsFile ?? createTemporaryFile("outputs.json");

this.stackName = Stack.of(this).stackName;
this.stack = Stack.of(this);

/**
* CfnOutputs should be scoped directly under the stack so the keys don't get polluted.
* Strings representing nested constructs will be appended to the key otherwise.
*/
this.outputs = Object.entries(config.outputs ?? {}).reduce((outputs, [key, value]) => {
outputs[key] = new CfnOutput(scope, key, value);
outputs[key] = new CfnOutput(this.stack, key, value);
return outputs;
}, {} as Record<PropertyKey, CfnOutput>);
}

public parseOutputs(): JsonFrom<T> {
try {
console.log("outputs file: ", this.outputsFile);

const fileContents = fs.readFileSync(this.outputsFile, "utf-8");

console.log("file contents: ", fileContents);

const json = JSON.parse(fileContents);

console.log("json: ", json);

console.log("stack name: ", this.stackName);
if (json[this.stack.stackName] == null) {
throw new Error();
}

return json[this.stackName];
return json[this.stack.stackName];
} catch (e) {
console.log(`Error: ${e}. Failed to parse outputs file at ${this.outputsFile}.`);
console.log(
`Error: ${e}. Failed to parse outputs file at ${this.outputsFile} for the stack: ${this.stack.stackName}`
);
return {} as JsonFrom<T>;
}
}
Expand Down

0 comments on commit 817a0c7

Please sign in to comment.