Skip to content

Commit

Permalink
chore(ci): add workflow for upgrading jsii & typescript (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiehan authored Jan 14, 2025
1 parent 53b9e23 commit 02886a0
Show file tree
Hide file tree
Showing 8 changed files with 379 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitattributes

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 109 additions & 0 deletions .github/workflows/upgrade-jsii-typescript.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .projen/files.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { cdk } from "projen";
import { UpgradeDependenciesSchedule } from "projen/lib/javascript";
import { UpgradeJSIIAndTypeScript } from "./projenrc/upgrade-jsii-typescript";
import { UpgradeNode } from "./projenrc/upgrade-node";
import { AutoApprove } from "./src/auto-approve";
import { Automerge } from "./src/automerge";
Expand All @@ -29,6 +30,8 @@ const githubActionPinnedVersions = {
"peter-evans/create-pull-request": "67ccf781d68cd99b580ae25a5c18a1cc84ffff1f", // v7.0.6
};

/** JSII and TS should always use the same major/minor version range */
const typescriptVersion = "~5.4.0";
const project = new cdk.JsiiProject({
name: "@cdktf/provider-project",
author: "HashiCorp",
Expand All @@ -37,8 +40,8 @@ const project = new cdk.JsiiProject({
authorOrganization: true,
licensed: false, // we do supply our own license file with a custom header
pullRequestTemplate: false,
jsiiVersion: "~5.4.0",
typescriptVersion: "~5.4.0", // should always be the same major/minor as JSII
typescriptVersion,
jsiiVersion: typescriptVersion,
peerDeps: ["projen@^0.87.4", "constructs@^10.4.2"],
deps: ["change-case", "fs-extra"],
bundledDeps: ["change-case", "fs-extra"],
Expand Down Expand Up @@ -107,6 +110,7 @@ new CustomizedLicense(project, 2020);
new LockIssues(project);
new AutoApprove(project);
new Automerge(project);
new UpgradeJSIIAndTypeScript(project, typescriptVersion);
new UpgradeNode(project);

project.addPackageIgnore("projenrc");
Expand Down
42 changes: 42 additions & 0 deletions projenrc/scripts/check-jsii-versions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
const today = new Date();
const oneMonthFromToday = new Date();
oneMonthFromToday.setDate(today.getDate() + 30);
// console.debug("oneMonthFromToday", oneMonthFromToday.toDateString());

/** Return the earliest supported version whose EOS date is at least a month away */
async function getEarliestSupportedVersion() {
// https://github.com/aws/jsii-compiler/blob/main/releases.json
const response = await fetch("https://raw.githubusercontent.com/aws/jsii-compiler/main/releases.json");
const data = await response.json();
const activelySupportedVersions = Object.entries(data.maintenance).filter(([version, supportEndDate]) => {
return new Date(supportEndDate) > oneMonthFromToday;
}).sort((a, b) => {
// Very naive sorting function: treat "5.4" like (int) 54, "5.5" like (int) 55, etc. and compare accordingly
return parseInt(a[0].replace(".", ""), 10) > parseInt(b[0].replace(".", ""), 10);
});

console.debug("Actively supported versions with an EOS date at least 1 month away")
console.debug(Object.fromEntries(activelySupportedVersions));

return activelySupportedVersions[0][0];
}

async function getDesiredVersion() {
const earliestSupportedVersion = await getEarliestSupportedVersion();
console.debug("earliestSupportedVersion", earliestSupportedVersion);

return earliestSupportedVersion;
}

module.exports = async ({github, context, core}) => {
const version = await getDesiredVersion();

core.exportVariable('NEW_JSII_VERSION', version + ".0"); // e.g. "5.4.0"
core.exportVariable('NEW_JSII_VERSION_SHORT', version); // e.g. "5.4"
core.exportVariable('NEW_JSII_VERSION_MAJOR', version.split(".")[0]); // e.g. "5"
core.exportVariable('NEW_JSII_VERSION_MINOR', version.split(".")[1]); // e.g. "4"
}
20 changes: 20 additions & 0 deletions projenrc/scripts/upgrade-jsii-typescript.sh
Original file line number Diff line number Diff line change
@@ -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 <typescript-version>"
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"
Loading

0 comments on commit 02886a0

Please # to comment.