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

chore(ci): add workflow for upgrading jsii & typescript #255

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes

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

52 changes: 52 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.

8 changes: 8 additions & 0 deletions .projen/deps.json

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.

4 changes: 2 additions & 2 deletions .projen/tasks.json

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

15 changes: 12 additions & 3 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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",
Expand All @@ -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, "_"),
Expand All @@ -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("[email protected]", "@cdktf/provider-random@>=11.0.0");
project.addDevDeps(
"semver",
"@types/semver",
"[email protected]",
"@cdktf/provider-random@>=11.0.0"
);

project.addPackageIgnore("scripts");
project.addPackageIgnore("projenrc");
Expand Down
2 changes: 2 additions & 0 deletions package.json

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

108 changes: 108 additions & 0 deletions projenrc/upgrade-jsii-typescript.ts
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
committer: "team-tf-cdk <[email protected]>",
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,
},
},
});
}
}
20 changes: 20 additions & 0 deletions scripts/update-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"
5 changes: 5 additions & 0 deletions yarn.lock

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

Loading