Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new api to unlock github-specific stage-level properties #178

Merged
merged 8 commits into from
Apr 28, 2022

Conversation

kaizencc
Copy link
Contributor

@kaizencc kaizencc commented Apr 25, 2022

Fixes #162.

Introduces a new API as follows:

import { App } from 'aws-cdk-lib';
import { ShellStep } from 'aws-cdk-lib/pipelines';
import { GitHubWorkflow } from 'cdk-pipelines-github';

const app = new App();

const pipeline = new GitHubWorkflow(app, 'Pipeline', {
  synth: new ShellStep('Build', {
    commands: [
      'yarn install',
      'yarn build',
    ],
  }),
  gitHubActionRoleArn: 'arn:aws:iam::<account-id>:role/GitHubActionRole',
});

pipeline.addStageWithGitHubOptions(new MyStage(this, 'Beta', {
  env: BETA_ENV,
  gitHubEnvironment: 'beta',
}));
pipeline.addStageWithGitHubOptions(new MyStage(this, 'Prod', {
  env: PROD_ENV,
  gitHubEnvironment: 'prod',
}));

app.synth();

Unlocks GitHub Environments at a stage-level, as well as a blueprint for any future stage-level github-specific properties we want to add.

@kaizencc kaizencc changed the title Conroy/pipes feat: add new api to unlock github-specific stage-level properties Apr 25, 2022
src/pipeline.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@rix0rrr rix0rrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, minor comments. Feel free to merge afterwards.

src/pipeline.ts Outdated
// keep track of GitHub specific options
if (options?.gitHubEnvName) {
for (const stack of stageDeployment.stacks) {
this.stackEnvs[stack.stackName] = options.gitHubEnvName;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels potentially dangerous--multiple stacks can have the same name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the key to stack.artifactID which should be unique within the cloud assembly.

src/pipeline.ts Outdated Show resolved Hide resolved
src/pipeline.ts Outdated Show resolved Hide resolved
mergify bot and others added 2 commits April 28, 2022 19:06
Signed-off-by: github-actions <github-actions@github.com>
@mergify mergify bot merged commit cc434f7 into main Apr 28, 2022
@mergify mergify bot deleted the conroy/pipes branch April 28, 2022 19:16
@@ -421,6 +461,7 @@ export class GitHubWorkflow extends PipelineBase {
contents: github.JobPermission.READ,
idToken: this.useGitHubActionRole ? github.JobPermission.WRITE : github.JobPermission.NONE,
},
environment: this.stackEnvs[stack.stackArtifactId],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaizencc, I just tried the new feature and found one thing.
If ppl use the normal AddStage method, the output deploy.yml will have environment: null. Wonder if we shall skip adding the environment key if this.stackEnvs[stack.stackArtifactId] is null.
Possibliy:

...(this.stackEnvs[stack.stackArtifactId] && {
          environment: this.stackEnvs[stack.stackArtifactId],
        }),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @julianiag, caught me at a good time lol. Does that create an environment for you when you deploy? Or is it simply ignored? I agree it's not great. Maybe I can change it up tomorrow :).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, if you add that in as a PR I will approve it, but you'll have to run yarn build to update the snapshots.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mergify bot pushed a commit that referenced this pull request Apr 29, 2022
…#186)

Based on discussion #178 (comment)

Removes `environment: null` from workflows that did not specify the environment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow user to add manual approval for deploy jobs.
4 participants