diff --git a/.gitattributes b/.gitattributes index 79936bd..d24e7b5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10,6 +10,7 @@ /.github/workflows/pull-request-lint.yml linguist-generated /.github/workflows/release.yml linguist-generated /.github/workflows/upgrade-cdktf.yml linguist-generated +/.github/workflows/upgrade-jsii-typescript.yml linguist-generated /.github/workflows/upgrade-main.yml linguist-generated /.gitignore linguist-generated /.npmignore linguist-generated diff --git a/.github/workflows/upgrade-jsii-typescript.yml b/.github/workflows/upgrade-jsii-typescript.yml new file mode 100644 index 0000000..d685f42 --- /dev/null +++ b/.github/workflows/upgrade-jsii-typescript.yml @@ -0,0 +1,52 @@ +# ~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen". + +name: upgrade-jsii-typescript +on: + workflow_dispatch: + inputs: + new_version: + description: New JSII/TypeScript version (e.g. "5.4.0"), without carets or tildes + required: true + default: 5.5.0 + type: string +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} +jobs: + upgrade: + name: Upgrade JSII & TypeScript + runs-on: ubuntu-latest + permissions: + contents: read + env: + CI: "true" + CHECKPOINT_DISABLE: "1" + NEW_VERSION: ${{ inputs.new_version }} + steps: + - name: Checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + - name: Setup Node.js + uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af + - name: Install + run: yarn install + - name: Run upgrade script + run: scripts/update-jsii-typescript.sh $NEW_VERSION + - name: Get values for pull request + id: latest_version + run: |- + NEW_VERSION_SHORT=$(cut -d "." -f 1,2 <<< "$NEW_VERSION") + echo "value=$NEW_VERSION" >> $GITHUB_OUTPUT + echo "short=$NEW_VERSION_SHORT" >> $GITHUB_OUTPUT + - name: Create Pull Request + uses: peter-evans/create-pull-request@67ccf781d68cd99b580ae25a5c18a1cc84ffff1f + with: + commit-message: "chore: upgrade jsii & typescript to v${{ steps.latest_version.outputs.short }}" + branch: auto/upgrade-jsii-ts-${{ steps.latest_version.outputs.short }} + base: main + title: "chore: upgrade jsii & typescript to v${{ steps.latest_version.outputs.short }}" + body: "This PR increases the version of JSII and TypeScript to `~${{ steps.latest_version.outputs.value }}`, presumably because the previous version is close to EOL or no longer supported. Support timeline: https://github.com/aws/jsii-compiler/blob/main/README.md#gear-maintenance--support" + labels: auto-approve,automerge,automated + token: ${{ secrets.PROJEN_GITHUB_TOKEN }} + author: team-tf-cdk + committer: team-tf-cdk + signoff: true + delete-branch: true diff --git a/.gitignore b/.gitignore index 8d7e2d0..281c194 100644 --- a/.gitignore +++ b/.gitignore @@ -52,4 +52,5 @@ tsconfig.json !/.github/workflows/auto-approve.yml !/.github/workflows/automerge.yml !/.github/workflows/upgrade-cdktf.yml +!/.github/workflows/upgrade-jsii-typescript.yml !/.projenrc.ts diff --git a/.projen/deps.json b/.projen/deps.json index 295dba9..3f7af5b 100644 --- a/.projen/deps.json +++ b/.projen/deps.json @@ -14,6 +14,10 @@ "version": "ts5.4", "type": "build" }, + { + "name": "@types/semver", + "type": "build" + }, { "name": "@typescript-eslint/eslint-plugin", "version": "^8", @@ -95,6 +99,10 @@ "name": "projen", "type": "build" }, + { + "name": "semver", + "type": "build" + }, { "name": "ts-jest", "type": "build" diff --git a/.projen/files.json b/.projen/files.json index 608e625..85ddc70 100644 --- a/.projen/files.json +++ b/.projen/files.json @@ -8,6 +8,7 @@ ".github/workflows/pull-request-lint.yml", ".github/workflows/release.yml", ".github/workflows/upgrade-cdktf.yml", + ".github/workflows/upgrade-jsii-typescript.yml", ".github/workflows/upgrade-main.yml", ".gitignore", ".prettierignore", diff --git a/.projen/tasks.json b/.projen/tasks.json index 66f2dc9..3903b7e 100644 --- a/.projen/tasks.json +++ b/.projen/tasks.json @@ -285,13 +285,13 @@ }, "steps": [ { - "exec": "npx npm-check-updates@16 --upgrade --target=minor --peer --no-deprecated --dep=dev,peer,prod,optional --filter=@types/jest,eslint-config-prettier,eslint-import-resolver-typescript,eslint-plugin-import,eslint-plugin-prettier,jest,jsii-diff,jsii-pacmak,prettier,projen,ts-jest" + "exec": "npx npm-check-updates@16 --upgrade --target=minor --peer --no-deprecated --dep=dev,peer,prod,optional --filter=@types/jest,@types/semver,eslint-config-prettier,eslint-import-resolver-typescript,eslint-plugin-import,eslint-plugin-prettier,jest,jsii-diff,jsii-pacmak,prettier,projen,semver,ts-jest" }, { "exec": "yarn install --check-files" }, { - "exec": "yarn upgrade @cdktf/provider-random @types/jest @types/node @typescript-eslint/eslint-plugin @typescript-eslint/parser commit-and-tag-version constructs eslint-config-prettier eslint-import-resolver-typescript eslint-plugin-import eslint-plugin-prettier eslint jest jest-junit jsii-diff jsii-docgen jsii-pacmak jsii-rosetta jsii prettier projen ts-jest ts-node typescript @cdktf/provider-null cdktf" + "exec": "yarn upgrade @cdktf/provider-random @types/jest @types/node @types/semver @typescript-eslint/eslint-plugin @typescript-eslint/parser commit-and-tag-version constructs eslint-config-prettier eslint-import-resolver-typescript eslint-plugin-import eslint-plugin-prettier eslint jest jest-junit jsii-diff jsii-docgen jsii-pacmak jsii-rosetta jsii prettier projen semver ts-jest ts-node typescript @cdktf/provider-null cdktf" }, { "exec": "npx projen" diff --git a/.projenrc.ts b/.projenrc.ts index a86b7b0..d241765 100644 --- a/.projenrc.ts +++ b/.projenrc.ts @@ -10,6 +10,7 @@ import { AutoApprove } from "./projenrc/auto-approve"; import { Automerge } from "./projenrc/automerge"; import { CustomizedLicense } from "./projenrc/customized-license"; import { UpgradeCDKTF } from "./projenrc/upgrade-cdktf"; +import { UpgradeJSIIAndTypeScript } from "./projenrc/upgrade-jsii-typescript"; const name = "cdktf-local-exec"; @@ -28,6 +29,8 @@ const githubActionPinnedVersions = { }; const constructsVersion = "10.3.0"; +/** JSII and TSII should always use the same major/minor version range */ +const typescriptVersion = "~5.4.0"; const project = new ConstructLibraryCdktf({ author: "HashiCorp", @@ -53,8 +56,8 @@ const project = new ConstructLibraryCdktf({ }, projenrcTs: true, prettier: true, - jsiiVersion: "~5.4.0", - typescriptVersion: "~5.4.0", // should always be the same major/minor as JSII + typescriptVersion, + jsiiVersion: typescriptVersion, publishToPypi: { distName: name, module: name.replace(/-/g, "_"), @@ -67,13 +70,19 @@ new CustomizedLicense(project); new AutoApprove(project); new Automerge(project); new UpgradeCDKTF(project); +new UpgradeJSIIAndTypeScript(project, typescriptVersion); project.addPeerDeps( "cdktf@>=0.20.0", "@cdktf/provider-null@>=10.0.0", "constructs@>=" + constructsVersion ); -project.addDevDeps("ts-node@10.9.1", "@cdktf/provider-random@>=11.0.0"); +project.addDevDeps( + "semver", + "@types/semver", + "ts-node@10.9.1", + "@cdktf/provider-random@>=11.0.0" +); project.addPackageIgnore("scripts"); project.addPackageIgnore("projenrc"); diff --git a/package.json b/package.json index 8f5bf9c..74822f6 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "@cdktf/provider-random": ">=11.0.0", "@types/jest": "^29", "@types/node": "ts5.4", + "@types/semver": "^7.5.8", "@typescript-eslint/eslint-plugin": "^8", "@typescript-eslint/parser": "^8", "cdktf": "0.20.0", @@ -59,6 +60,7 @@ "jsii-rosetta": "~5.4.0", "prettier": "^2.8.8", "projen": "^0.91.5", + "semver": "^7.6.3", "ts-jest": "^29", "ts-node": "10.9.1", "typescript": "~5.4.0" diff --git a/projenrc/upgrade-jsii-typescript.ts b/projenrc/upgrade-jsii-typescript.ts new file mode 100644 index 0000000..bb89f9b --- /dev/null +++ b/projenrc/upgrade-jsii-typescript.ts @@ -0,0 +1,108 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: MPL-2.0 + */ + +import { javascript } from "projen"; +import { JobPermission } from "projen/lib/github/workflows-model"; +import * as semver from "semver"; + +/** + * Helper script for upgrading JSII and TypeScript in the right way. + * This currently isn't automated (the workflow must be manually run) + * because there is no way to programmatically determine the EOL date + * of a JSII version range. This can be found at: + * https://github.com/aws/jsii-compiler/blob/main/README.md#gear-maintenance--support + */ +export class UpgradeJSIIAndTypeScript { + constructor(project: javascript.NodeProject, typescriptVersion: string) { + const workflow = project.github?.addWorkflow("upgrade-jsii-typescript"); + if (!workflow) throw new Error("no workflow defined"); + + const plainVersion = typescriptVersion.replace("~", ""); + const defaultVersion = semver.inc(plainVersion, "minor"); + + workflow.on({ + workflowDispatch: { + inputs: { + newVersion: { + description: `New JSII/TypeScript version (e.g. "${plainVersion}"), without carets or tildes`, + required: true, + default: defaultVersion, + type: "string", + }, + }, + }, + }); + + (workflow.concurrency as any) = { + group: "${{ github.workflow }}-${{ github.ref }}", + }; + + workflow.addJobs({ + upgrade: { + name: "Upgrade JSII & TypeScript", + runsOn: ["ubuntu-latest"], + steps: [ + { + name: "Checkout", + uses: "actions/checkout@v3", + }, + { + name: "Setup Node.js", + uses: "actions/setup-node@v3", + }, + { + name: "Install", + run: "yarn install", + }, + { + name: "Run upgrade script", + run: "scripts/update-jsii-typescript.sh $NEW_VERSION", + }, + { + name: "Get values for pull request", + id: "latest_version", + run: [ + `NEW_VERSION_SHORT=$(cut -d "." -f 1,2 <<< "$NEW_VERSION")`, + `echo "value=$NEW_VERSION" >> $GITHUB_OUTPUT`, + `echo "short=$NEW_VERSION_SHORT" >> $GITHUB_OUTPUT`, + ].join("\n"), + }, + { + name: "Create Pull Request", + uses: "peter-evans/create-pull-request@v3", + with: { + "commit-message": + "chore: upgrade jsii & typescript to v${{ steps.latest_version.outputs.short }}", + branch: + "auto/upgrade-jsii-ts-${{ steps.latest_version.outputs.short }}", + base: "main", + title: + "chore: upgrade jsii & typescript to v${{ steps.latest_version.outputs.short }}", + body: [ + "This PR increases the version of JSII and TypeScript to `~${{ steps.latest_version.outputs.value }}`, ", + "presumably because the previous version is close to EOL or no longer supported. Support timeline: ", + "https://github.com/aws/jsii-compiler/blob/main/README.md#gear-maintenance--support", + ].join(" "), + labels: "auto-approve,automerge,automated", + token: "${{ secrets.PROJEN_GITHUB_TOKEN }}", + author: "team-tf-cdk ", + committer: "team-tf-cdk ", + signoff: true, + "delete-branch": true, + }, + }, + ], + env: { + CI: "true", + CHECKPOINT_DISABLE: "1", + NEW_VERSION: "${{ inputs.new_version }}", // should be newVersion but Projen converts it to snake_case + }, + permissions: { + contents: JobPermission.READ, + }, + }, + }); + } +} diff --git a/scripts/update-jsii-typescript.sh b/scripts/update-jsii-typescript.sh new file mode 100755 index 0000000..2bf594b --- /dev/null +++ b/scripts/update-jsii-typescript.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +set -ex + +PROJECT_ROOT=$(cd "$(dirname "${BASH_SOURCE:-$0}")/.." && pwd) +NEW_VERSION=$1 + +if [ -z "$NEW_VERSION" ]; then + echo "Usage: $0 " + exit 1 +fi + +echo "Updating JSII & TypeScript version to $NEW_VERSION" +yarn +sed -i "s/typescriptVersion = \".*\";/typescriptVersion = \"~$NEW_VERSION\";/" "$PROJECT_ROOT/.projenrc.ts" +CI=0 npx projen + +echo "Done" diff --git a/yarn.lock b/yarn.lock index 52f0611..7da6d60 100644 --- a/yarn.lock +++ b/yarn.lock @@ -844,6 +844,11 @@ resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.4.tgz#56e2cc26c397c038fab0e3a917a12d5c5909e901" integrity sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA== +"@types/semver@^7.5.8": + version "7.5.8" + resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.8.tgz#8268a8c57a3e4abd25c165ecd36237db7948a55e" + integrity sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ== + "@types/stack-utils@^2.0.0": version "2.0.3" resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.3.tgz#6209321eb2c1712a7e7466422b8cb1fc0d9dd5d8"