From 79d0ea0ae39786bb3de17d5cedc43460cc22aa48 Mon Sep 17 00:00:00 2001 From: Nara Kasbergen Date: Thu, 9 Jan 2025 19:15:33 +0100 Subject: [PATCH] chore(ci): update required version of constructs when cdktf is upgraded --- .github/MAINTENANCE.md | 1 - .github/workflows/upgrade-cdktf.yml | 5 ++++- .projenrc.ts | 2 +- README.md | 2 +- projenrc/upgrade-cdktf.ts | 5 ++++- scripts/update-cdktf.sh | 13 ++++++++++--- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.github/MAINTENANCE.md b/.github/MAINTENANCE.md index 551e665..4f2da16 100644 --- a/.github/MAINTENANCE.md +++ b/.github/MAINTENANCE.md @@ -34,7 +34,6 @@ The following Actions either need to be manually triggered or require significan 2. Update the [object](https://github.com/cdktf/cdktf-multi-stack-tfe/blob/10616ec183618c636849b09f034b1d0e45d59855/.projenrc.ts#L20-L31) 3. Run `npx projen` 4. Create a new PR with the title `chore(deps): update pinned versions of GitHub Actions` -- **`constructs` library upgrades**: Because `constructs` is a peer dependency, the `upgrade-main` script described above will _never_ increment its version; this will always need to be done manually by [editing](https://github.com/cdktf/cdktf-multi-stack-tfe/blob/10616ec183618c636849b09f034b1d0e45d59855/.projenrc.ts#L15) `.projenrc.ts`. This could _in theory_ be (semi)automated like some of our other upgrade workflows described above for things like CDKTF, Node, and JSII, but in practice we currently have no logic or criteria that governs when `constructs` should be updated; as such, creating a custom workflow for it felt like more effort than it's really worth. Also worth noting: Unlike many of our other Projen-based projects, this one does not have a script that automatically upgrades Node.js because this library does not enforce a `minNodeVersion`. If we did at some point want to start enforcing a `minNodeVersion`, we should copy over the `upgrade-node` script that our other Projen projects use. diff --git a/.github/workflows/upgrade-cdktf.yml b/.github/workflows/upgrade-cdktf.yml index 09f35d7..fd09baf 100644 --- a/.github/workflows/upgrade-cdktf.yml +++ b/.github/workflows/upgrade-cdktf.yml @@ -33,11 +33,14 @@ jobs: run: |- CDKTF_VERSION=$(yarn info cdktf --json | jq -r '.data.version') CDKTF_VERSION_SHORT=$(cut -d "." -f 2 <<< "$CDKTF_VERSION") + CONSTRUCTS_VERSION=$(yarn info cdktf --json | jq -r '.data.peerDependencies.constructs') + CONSTRUCTS_VERSION_EXACT=$(cut -d "^" -f 2 <<< "$CONSTRUCTS_VERSION") echo "value=$CDKTF_VERSION" >> $GITHUB_OUTPUT echo "short=$CDKTF_VERSION_SHORT" >> $GITHUB_OUTPUT + echo "constructs=$CONSTRUCTS_VERSION_EXACT" >> $GITHUB_OUTPUT - name: Run upgrade script if: steps.current_version.outputs.short != steps.latest_version.outputs.short - run: scripts/update-cdktf.sh ${{ steps.latest_version.outputs.value }} + run: scripts/update-cdktf.sh ${{ steps.latest_version.outputs.value }} ${{ steps.latest_version.outputs.constructs }} - name: Create draft pull request if: steps.current_version.outputs.short != steps.latest_version.outputs.short uses: peter-evans/create-pull-request@67ccf781d68cd99b580ae25a5c18a1cc84ffff1f diff --git a/.projenrc.ts b/.projenrc.ts index bb6accd..4073b87 100644 --- a/.projenrc.ts +++ b/.projenrc.ts @@ -13,7 +13,7 @@ import { UpgradeJSIIAndTypeScript } from "./projenrc/upgrade-jsii-typescript"; const cdktfVersion = ">=0.20.0"; const constructVersion = "^10.3.0"; -/** JSII and TSII should always use the same major/minor version range */ +/** JSII and TS should always use the same major/minor version range */ const typescriptVersion = "~5.5.0"; const name = "cdktf-multi-stack-tfe"; diff --git a/README.md b/README.md index 48955d9..436951b 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ By using the software in this repository, you acknowledge that: ## Compatibility - `cdktf` >= 0.20.0 -- `constructs` >= 10.0.107 +- `constructs` >= 10.3.0 ## Usage diff --git a/projenrc/upgrade-cdktf.ts b/projenrc/upgrade-cdktf.ts index 95bdcd3..a885cb0 100644 --- a/projenrc/upgrade-cdktf.ts +++ b/projenrc/upgrade-cdktf.ts @@ -54,8 +54,11 @@ export class UpgradeCDKTF { run: [ `CDKTF_VERSION=$(yarn info cdktf --json | jq -r '.data.version')`, `CDKTF_VERSION_SHORT=$(cut -d "." -f 2 <<< "$CDKTF_VERSION")`, + `CONSTRUCTS_VERSION=$(yarn info cdktf --json | jq -r '.data.peerDependencies.constructs')`, + `CONSTRUCTS_VERSION_EXACT=$(cut -d "^" -f 2 <<< "$CONSTRUCTS_VERSION")`, // strip the caret off the beginning `echo "value=$CDKTF_VERSION" >> $GITHUB_OUTPUT`, `echo "short=$CDKTF_VERSION_SHORT" >> $GITHUB_OUTPUT`, + `echo "constructs=$CONSTRUCTS_VERSION_EXACT" >> $GITHUB_OUTPUT`, ].join("\n"), // IMPORTANT: the above behavior changed in Yarn 2+; `yarn info` instead gives the version of the installed package // If/when we upgrade we'll likely want to switch to `yarn npm info`: https://yarnpkg.com/cli/npm/info @@ -63,7 +66,7 @@ export class UpgradeCDKTF { { name: "Run upgrade script", if: "steps.current_version.outputs.short != steps.latest_version.outputs.short", - run: "scripts/update-cdktf.sh ${{ steps.latest_version.outputs.value }}", + run: "scripts/update-cdktf.sh ${{ steps.latest_version.outputs.value }} ${{ steps.latest_version.outputs.constructs }}", }, { name: "Create draft pull request", diff --git a/scripts/update-cdktf.sh b/scripts/update-cdktf.sh index 7de9232..789716a 100755 --- a/scripts/update-cdktf.sh +++ b/scripts/update-cdktf.sh @@ -6,16 +6,23 @@ set -ex PROJECT_ROOT=$(cd "$(dirname "${BASH_SOURCE:-$0}")/.." && pwd) CDKTF_VERSION=$1 +CONSTRUCTS_VERSION=$2 if [ -z "$CDKTF_VERSION" ]; then - echo "Usage: $0 " + echo "Usage: $0 " + exit 1 +fi +if [ -z "$CONSTRUCTS_VERSION" ]; then + echo "Usage: $0 " exit 1 fi -echo "Updating to cdktf version $CDKTF_VERSION" +echo "Updating to cdktf version $CDKTF_VERSION and constructs version $CONSTRUCTS_VERSION" yarn -sed -i "s/const cdktfVersion = \".*\";/const cdktfVersion = \">=$CDKTF_VERSION\";/" "$PROJECT_ROOT/.projenrc.ts" +sed -i "s/cdktfVersion = \".*\";/cdktfVersion = \">=$CDKTF_VERSION\";/" "$PROJECT_ROOT/.projenrc.ts" +sed -i "s/constructsVersion = \".*\";/constructsVersion = \"$CONSTRUCTS_VERSION\";/" "$PROJECT_ROOT/.projenrc.ts" CI=0 npx projen echo "Updating README" sed -i 's/`cdktf` >= .*/`cdktf` >= '"$CDKTF_VERSION"'/' "$PROJECT_ROOT/README.md" +sed -i 's/`constructs` >= .*/`constructs` >= '"$CONSTRUCTS_VERSION"'/' "$PROJECT_ROOT/README.md"