Skip to content

Commit 8be6aad

Browse files
authored
feat(cli): update Go init templates to v1.23.0 and add post-install tidy (#768)
This PR updates the Go init templates and adds automatic dependency management: ## Changes - **Go version**: Updated from 1.18 to 1.23.0 in both app and sample-app templates - **jsii-runtime-go**: Updated from v1.29.0 to v1.112.0 for latest compatibility - **Post-install automation**: Added `postInstallGo` function that automatically runs `go mod tidy` after project initialization - **Integration test**: Updated to run `go mod tidy` after module replacement for proper dependency resolution ## Benefits - Users get the latest stable Go version (1.23.0) - Latest jsii runtime with bug fixes and improvements - Automatic dependency management eliminates manual `go mod tidy` step - Better developer experience for Go CDK projects ## Testing - Integration tests updated and should pass with the new flow - Post-install step gracefully handles network unavailability --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent 2877f4c commit 8be6aad

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

packages/@aws-cdk-testing/cli-integ/tests/init-go/init-go.integtest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import { integTest, withTemporaryDirectory, ShellHelper, withPackages } from '..
2020
}
2121

2222
await shell.shell(['go', 'mod', 'edit', '-replace', `github.com/aws/aws-cdk-go/awscdk/v2=${dir}/go/awscdk`]);
23+
await shell.shell(['go', 'mod', 'tidy']);
2324
}
2425

25-
await shell.shell(['go', 'mod', 'tidy']);
2626
await shell.shell(['go', 'test']);
2727
await shell.shell(['cdk', 'synth']);
2828
})));

packages/aws-cdk/lib/commands/init/init.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ async function postInstall(ioHelper: IoHelper, language: string, canUseNetwork:
390390
return postInstallJava(ioHelper, canUseNetwork, workDir);
391391
case 'python':
392392
return postInstallPython(ioHelper, workDir);
393+
case 'go':
394+
return postInstallGo(ioHelper, canUseNetwork, workDir);
393395
}
394396
}
395397

@@ -441,6 +443,20 @@ async function postInstallPython(ioHelper: IoHelper, cwd: string) {
441443
}
442444
}
443445

446+
async function postInstallGo(ioHelper: IoHelper, canUseNetwork: boolean, cwd: string) {
447+
if (!canUseNetwork) {
448+
await ioHelper.defaults.warn('Please run \'go mod tidy\'!');
449+
return;
450+
}
451+
452+
await ioHelper.defaults.info(`Executing ${chalk.green('go mod tidy')}...`);
453+
try {
454+
await execute(ioHelper, 'go', ['mod', 'tidy'], { cwd });
455+
} catch (e: any) {
456+
await ioHelper.defaults.warn('\'go mod tidy\' failed: ' + formatErrorMessage(e));
457+
}
458+
}
459+
444460
/**
445461
* @param dir - a directory to be checked
446462
* @returns true if ``dir`` is within a git repository.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module %name%
22

3-
go 1.18
3+
go 1.23.0
44

55
require (
66
github.com/aws/aws-cdk-go/awscdk/v2 v%cdk-version%
77
github.com/aws/constructs-go/constructs/v10 v10.0.5
8-
github.com/aws/jsii-runtime-go v1.29.0
8+
github.com/aws/jsii-runtime-go v1.112.0
99
)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module %name%
22

3-
go 1.18
3+
go 1.23.0
44

55
require (
66
github.com/aws/aws-cdk-go/awscdk/v2 v%cdk-version%
77
github.com/aws/constructs-go/constructs/v10 v10.0.5
8-
github.com/aws/jsii-runtime-go v1.29.0
8+
github.com/aws/jsii-runtime-go v1.112.0
99
)

0 commit comments

Comments
 (0)