-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: add the ability to deprecate a prebuilt provider (#370)
While this is not technically a breaking change, I want to force this to be released as v0.5.0 so that it's easier to roll back to v0.4.x in case there are any issues with this in testing. At its core, this change is relatively simple: it introduces an `isDeprecated` flag on the config for providers built using this project that defaults to falsy. All the new behavior is controlled by that flag, so it _should_ mean that this is safe to merge, as no new functionality will be triggered for any providers unless/until they are marked as deprecated. (There technically is also a new option called `deprecationDate` -- in practice I don't intend to use that and will just rely on the build date; however, in order to not have the test snapshots be regenerated every day with a new date, I needed a way to force-override the `new Date()` behavior.) If the `isDeprecated` flag is set to `true`, then the following happens: - The "should-release" logic is removed because we want to force one final release - The "provider upgrade" and "upgrade-main" workflows are removed to avoid any accidental updates before the repo is archived - The text in the README will have a disclaimer about the deprecated status of this package added to it, and the sections about Versioning and Contributing that are no longer relevant will be removed - Thanks to #371, these README changes will show up in the Go repository as well - The Go package will be marked as deprecated -- see [here](golang/go#40357) for how this is done in Go - The NPM package will be [marked as deprecated](https://docs.npmjs.com/deprecating-and-undeprecating-packages-or-package-versions/) after the next and final release PyPi and Maven unfortunately don't support deprecating an entire package. NuGet does, but there's no API/CLI for it; it has to be done via the web UI. While it's huge, looking at the test snapshot file might be the best way to visualize the changes. The first example in that file is of a provider that's been marked as deprecated -- in particular, scrolling down to the README will demonstrate what that looks like for a deprecated provider. The other snapshots demonstrate that there shouldn't be any unintentional outcomes for providers that have not been explicitly marked as deprecated. Side note: while I was working on this I realized that hashicorp/terraform-cdk#2575 is very important now because we link to https://cdk.tf/imports a lot to explain how to manually generate bindings, but some of the examples there incorrectly use the prebuilt providers, so I have added that issue to our next release. --------- Signed-off-by: team-tf-cdk <[email protected]> Co-authored-by: team-tf-cdk <[email protected]>
- Loading branch information
1 parent
3880437
commit fbad220
Showing
8 changed files
with
2,436 additions
and
69 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/** | ||
* Copyright (c) HashiCorp, Inc. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
import { JsiiProject } from "projen/lib/cdk"; | ||
import { JobPermission, JobStep } from "projen/lib/github/workflows-model"; | ||
import { PackageInfo } from "./package-info"; | ||
|
||
export interface DeprecatePackagesOptions { | ||
providerName: string; | ||
packageInfo: PackageInfo; | ||
isDeprecated: boolean; | ||
} | ||
|
||
export class DeprecatePackages { | ||
constructor(project: JsiiProject, options: DeprecatePackagesOptions) { | ||
const { providerName, packageInfo, isDeprecated } = options; | ||
|
||
const deprecationMessageForNPM = [ | ||
`See https://cdk.tf/imports for details on how to continue to use the ${providerName} provider`, | ||
`in your CDK for Terraform (CDKTF) projects by generating the bindings locally.`, | ||
].join(" "); | ||
// @see https://github.com/golang/go/issues/40357 | ||
const deprecationMessageForGo = [ | ||
`// Deprecated: HashiCorp is no longer publishing new versions of the prebuilt provider for ${providerName}.`, | ||
`// Previously-published versions of this prebuilt provider will still continue to be available as installable Go modules,`, | ||
`// but these will not be compatible with newer versions of CDK for Terraform and are not eligible for commercial support.`, | ||
`// You can continue to use the ${providerName} provider in your CDK for Terraform projects with newer versions of CDKTF,`, | ||
`// but you will need to generate the bindings locally. See https://cdk.tf/imports for details.`, | ||
].join("\n"); | ||
|
||
const deprecationStep: JobStep = { | ||
name: "Mark the Go module as deprecated", | ||
run: `find '.repo/dist/go' -mindepth 2 -maxdepth 4 -type f -name 'go.mod' | xargs sed -i '1s|^|${deprecationMessageForGo} \n|'`, | ||
continueOnError: true, // @TODO remove this once we confirm it to be working | ||
}; | ||
if (isDeprecated) { | ||
packageInfo.publishToGo?.prePublishSteps?.splice(-1, 0, deprecationStep); | ||
} | ||
|
||
const releaseWorkflow = project.github?.tryFindWorkflow("release"); | ||
if (!releaseWorkflow) { | ||
throw new Error("Could not find release workflow, aborting"); | ||
} | ||
|
||
releaseWorkflow.addJobs({ | ||
deprecate: { | ||
name: "Deprecate the package in package managers if needed", | ||
runsOn: ["ubuntu-latest"], | ||
needs: ["release", "release_npm"], | ||
steps: [ | ||
{ | ||
name: "Checkout", | ||
uses: "actions/checkout@v4", | ||
}, | ||
{ | ||
name: "Install", | ||
run: "yarn install", | ||
}, | ||
{ | ||
name: "Check deprecation status", | ||
id: "check_status", | ||
run: [ | ||
`IS_DEPRECATED=$(npm pkg get cdktf.isDeprecated | tr -d '"')`, | ||
`echo "is_deprecated=$IS_DEPRECATED"`, // for easier debugging | ||
`echo "is_deprecated=$IS_DEPRECATED" >> $GITHUB_OUTPUT`, | ||
].join("\n"), | ||
}, | ||
{ | ||
name: "Deprecate the package on NPM", | ||
if: "steps.check_status.outputs.is_deprecated", | ||
run: `npm deprecate ${packageInfo.npm.name} "${deprecationMessageForNPM}"`, | ||
env: { | ||
NPM_REGISTRY: project.package.npmRegistry, | ||
NPM_TOKEN: | ||
"${{ secrets." + `${project.package.npmTokenSecret} }}`, | ||
}, | ||
}, | ||
// Unfortunately, PyPi has no mechanism to mark a package as deprecated: https://github.com/pypi/warehouse/issues/345 | ||
// Maven also never moved past the proposal stage: https://github.com/p4em/artifact-deprecation | ||
// NuGet supports deprecation, but only via the web UI: https://learn.microsoft.com/en-us/nuget/nuget-org/deprecate-packages | ||
// Go deprecation is handled in the "Publish to Go" step (see line 37) | ||
], | ||
permissions: { | ||
contents: JobPermission.READ, | ||
}, | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.