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(cli): always exit with 0 on cdk diff (under feature flag) #4721

Merged
merged 6 commits into from
Nov 28, 2019

Conversation

jogold
Copy link
Contributor

@jogold jogold commented Oct 28, 2019

Use cdk diff --fail to exit with 1 if there's a diff.

Related to #4650 and #4708

BREAKING CHANGE: cdk diffnow exits with 0 even when there's a diff, use --fail to exit with 1. To enable this feature for old projects, add the context key "aws-cdk:diffNoFail": "true" in your cdk.json file.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

Use `cdk diff --no-fail` to exit with 0 even when there is a diff.

To avoid a CLI breaking change, the default remains to fail on diff.

Related to aws#4650 and aws#4708
@mergify
Copy link
Contributor

mergify bot commented Oct 28, 2019

Thanks so much for taking the time to contribute to the AWS CDK ❤️

We will shortly assign someone to review this pull request and help get it
merged. In the meantime, please take a minute to make sure you follow this
checklist
:

  • PR title type(scope): text
    • type: fix, feat, refactor go into CHANGELOG, chore is hidden
    • scope: name of module without aws- or cdk- prefix or postfix (e.g. s3 instead of aws-s3-deployment)
    • text: use all lower-case, do not end with a period, do not include issue refs
  • PR Description
    • Rationale: describe rationale of change and approach taken
    • Issues: indicate issues fixed via: fixes #xxx or closes #xxx
    • Breaking?: last paragraph: BREAKING CHANGE: <describe what changed + link for details>
  • Testing
    • Unit test added. Prefer to add a new test rather than modify existing tests
    • CLI or init templates change? Re-run/add CLI integration tests
  • Documentation
    • README: update module README to describe new features
    • API docs: public APIs must be documented. Copy from official AWS docs when possible
    • Design: for significant features, follow design process

1 similar comment
@mergify
Copy link
Contributor

mergify bot commented Oct 28, 2019

Thanks so much for taking the time to contribute to the AWS CDK ❤️

We will shortly assign someone to review this pull request and help get it
merged. In the meantime, please take a minute to make sure you follow this
checklist
:

  • PR title type(scope): text
    • type: fix, feat, refactor go into CHANGELOG, chore is hidden
    • scope: name of module without aws- or cdk- prefix or postfix (e.g. s3 instead of aws-s3-deployment)
    • text: use all lower-case, do not end with a period, do not include issue refs
  • PR Description
    • Rationale: describe rationale of change and approach taken
    • Issues: indicate issues fixed via: fixes #xxx or closes #xxx
    • Breaking?: last paragraph: BREAKING CHANGE: <describe what changed + link for details>
  • Testing
    • Unit test added. Prefer to add a new test rather than modify existing tests
    • CLI or init templates change? Re-run/add CLI integration tests
  • Documentation
    • README: update module README to describe new features
    • API docs: public APIs must be documented. Copy from official AWS docs when possible
    • Design: for significant features, follow design process

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@shivlaks
Copy link
Contributor

now that we have the feature-flags I think we should leverage it to introduce the capability you initially wanted to introduce in #4650

thoughts?

@jogold jogold requested a review from eladb as a code owner November 12, 2019 15:26
@jogold jogold changed the title feat(cli): add --no-fail option to diff feat(cli): always exit with 0 on cdk diff (under feature flag) Nov 12, 2019
@jogold
Copy link
Contributor Author

jogold commented Nov 12, 2019

@eladb can you have a look at my first attempt to use the feature flags (as suggested by @shivlaks)?

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@@ -185,7 +187,8 @@ async function initCommandLine() {
exclusively: args.exclusively,
templatePath: args.template,
strict: args.strict,
contextLines: args.contextLines
contextLines: args.contextLines,
fail: args.fail || !configuration.context.get(cxapi.ENABLE_DIFF_NO_FAIL),
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this also work if this is defined in in cdk.context.json?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes:

this.context = new Context(
this.commandLineContext,
this.projectConfig.subSettings([CONTEXT_KEY]).makeReadOnly(),
this.projectContext);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DISABLE_DIFF_FAIL instead of ENABLE_DIFF_NO_FAIL, I'm not very happy with the name here...

packages/aws-cdk/lib/cdk-toolkit.ts Show resolved Hide resolved
@mergify
Copy link
Contributor

mergify bot commented Nov 28, 2019

Thank you for contributing! Your pull request is now being automatically merged.

1 similar comment
@mergify
Copy link
Contributor

mergify bot commented Nov 28, 2019

Thank you for contributing! Your pull request is now being automatically merged.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 3ffd810 into aws:master Nov 28, 2019
@jogold jogold deleted the diff-no-fail branch November 28, 2019 08:39
@shivlaks shivlaks mentioned this pull request Dec 12, 2019
2 tasks
mergify bot pushed a commit that referenced this pull request Apr 19, 2020
…7401)

Rationale: we missed this entry from #4721 presumably because there isn't a newline after `BREAKING CHANGE:` before the rest of the text in the commit body
njlynch added a commit that referenced this pull request Dec 6, 2021
In v1, the original behavior was that `cdk diff` exited 0 on a clean diff (no
changes), and exited 1 on changes. #4721 introduced a new feature flag to always
have `cdk diff` exit 0. As is standard, the "default" for the flag was `false`,
but the future behavior was `true`, meaning any new CDK project created after
that release (v1.19.0) defaulted to always exiting 0.

In v2, the feature flag was expired, meaning users could no longer set
it. Typically, the behavior (`FeatureFlags.isEnabled`) checks and errors if an
expired flag is explicitly set, and always returns true for expired flags
otherwise. However, the CDK CLI helper function did not contain this
functionality. That means for current v2 projects, the v1-ported default value
is used (false). This means `cdk diff` *always* exits 1 when there's a diff, and
there's no way for a user to disable this behavior.

This change updates the CLI behavior to default to true for expired flags, same
as any other feature flag check; this means `cdk diff` will return to exiting 0,
as v1 apps have been doing for years. The `FeatureFlags.isEnabled` method can't
be used, as it requires a Construct node.

I also took the liberty of explicitly setting the "default" to true for all
expired flags, so any other direct access of the flag (not using the FeatureFlag
library) will have the same consistent behavior.
njlynch added a commit that referenced this pull request Dec 6, 2021
In v1, the original behavior was that `cdk diff` exited 0 on a clean diff (no
changes), and exited 1 on changes. #4721 introduced a new feature flag to always
have `cdk diff` exit 0. As is standard, the "default" for the flag was `false`,
but the future behavior was `true`, meaning any new CDK project created after
that release (v1.19.0) defaulted to always exiting 0.

In v2, the feature flag was expired, meaning users could no longer set
it. Typically, the behavior (`FeatureFlags.isEnabled`) checks and errors if an
expired flag is explicitly set, and always returns true for expired flags
otherwise. However, the CDK CLI helper function did not contain this
functionality. That means for current v2 projects, the v1-ported default value
is used (false). This means `cdk diff` *always* exits 1 when there's a diff, and
there's no way for a user to disable this behavior.

This change updates the CLI behavior to default to true for expired flags, same
as any other feature flag check; this means `cdk diff` will return to exiting 0,
as v1 apps have been doing for years. The `FeatureFlags.isEnabled` method can't
be used, as it requires a Construct node.

I also took the liberty of explicitly setting the "default" to true for all
expired flags, so any other direct access of the flag (not using the FeatureFlag
library) will have the same consistent behavior.
njlynch added a commit that referenced this pull request Dec 6, 2021
In v1, the original behavior was that `cdk diff` exited 0 on a clean diff (no
changes), and exited 1 on changes. #4721 introduced a new feature flag to always
have `cdk diff` exit 0. As is standard, the "default" for the flag was `false`,
but the future behavior was `true`, meaning any new CDK project created after
that release (v1.19.0) defaulted to always exiting 0.

In v2, the feature flag was expired, meaning users could no longer set
it. Typically, the behavior (`FeatureFlags.isEnabled`) checks and errors if an
expired flag is explicitly set, and always returns true for expired flags
otherwise. However, the CDK CLI helper function did not contain this
functionality. That means for current v2 projects, the v1-ported default value
is used (false). This means `cdk diff` *always* exits 1 when there's a diff, and
there's no way for a user to disable this behavior.

This change updates the CLI behavior to default to true for expired flags, same
as any other feature flag check; this means `cdk diff` will return to exiting 0,
as v1 apps have been doing for years. The `FeatureFlags.isEnabled` method can't
be used, as it requires a Construct node.

I also took the liberty of explicitly setting the "default" to true for all
expired flags, so any other direct access of the flag (not using the FeatureFlag
library) will have the same consistent behavior.
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.

4 participants