Skip to content

Commit 32c3c06

Browse files
authored
feat(scripts): extend bundle to support injectable output and version suffix (#1389)
1 parent 6044796 commit 32c3c06

2 files changed

Lines changed: 63 additions & 25 deletions

File tree

.github/workflows/prerelease-tarball.yml

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717
prerelease-tarball:
1818
runs-on: ubuntu-latest
1919
timeout-minutes: 15
20+
env:
21+
TARBALL_BASE: agentcore-cli-prerelease
2022
steps:
2123
- uses: actions/checkout@v6
2224
- uses: actions/setup-node@v6
@@ -37,23 +39,23 @@ jobs:
3739
env:
3840
CDK_REPO_TOKEN: ${{ steps.app-token.outputs.token }}
3941
CDK_REPO: ${{ secrets.CDK_REPO_NAME }}
42+
- name: Compute version suffix
43+
id: version
44+
run: |
45+
CLI_SHA=$(git rev-parse --short=5 HEAD)
46+
CDK_SHA=$(git -C /tmp/cdk-repo rev-parse --short=5 HEAD)
47+
SUFFIX="${CLI_SHA}-${CDK_SHA}"
48+
echo "suffix=$SUFFIX" >> $GITHUB_OUTPUT
49+
echo "Version suffix: $SUFFIX"
4050
- run: npm run bundle
4151
env:
4252
AGENTCORE_CDK_PATH: /tmp/cdk-repo
43-
- name: Get tarball info
44-
id: tarball
45-
run: |
46-
GA_TARBALL=$(ls *-[0-9]*[0-9].tgz 2>/dev/null | grep -v preview | head -1 | xargs basename)
47-
PREVIEW_TARBALL=$(ls *preview*.tgz | head -1 | xargs basename)
48-
echo "ga_name=$GA_TARBALL" >> $GITHUB_OUTPUT
49-
echo "preview_name=$PREVIEW_TARBALL" >> $GITHUB_OUTPUT
50-
echo "GA tarball: $GA_TARBALL"
51-
echo "Preview tarball: $PREVIEW_TARBALL"
53+
AGENTCORE_TARBALL_OUTPUT: ${{ env.TARBALL_BASE }}
54+
AGENTCORE_TARBALL_VERSION_SUFFIX: ${{ steps.version.outputs.suffix }}
5255
- name: Create or update prerelease
5356
env:
5457
GH_TOKEN: ${{ steps.app-token.outputs.token }}
55-
GA_TARBALL: ${{ steps.tarball.outputs.ga_name }}
56-
PREVIEW_TARBALL: ${{ steps.tarball.outputs.preview_name }}
58+
VERSION_SUFFIX: ${{ steps.version.outputs.suffix }}
5759
run: |
5860
TAG="prerelease"
5961
@@ -62,19 +64,21 @@ jobs:
6264
6365
# Create a new pre-release with both tarballs
6466
gh release create "$TAG" \
65-
"${GA_TARBALL}" \
66-
"${PREVIEW_TARBALL}" \
67+
"${TARBALL_BASE}.tgz" \
68+
"${TARBALL_BASE}-preview.tgz" \
6769
--title "Prerelease" \
6870
--notes "Auto-generated tarballs from the latest commit on main.
6971
72+
Version: \`${VERSION_SUFFIX}\` (cli-cdk)
73+
7074
**GA build** (no harness features):
7175
\`\`\`
72-
npm install -g https://github.com/aws/agentcore-cli/releases/download/prerelease/${GA_TARBALL}
76+
npm install -g https://github.com/aws/agentcore-cli/releases/download/prerelease/${TARBALL_BASE}.tgz
7377
\`\`\`
7478
7579
**Preview build** (harness features enabled):
7680
\`\`\`
77-
npm install -g https://github.com/aws/agentcore-cli/releases/download/prerelease/${PREVIEW_TARBALL}
81+
npm install -g https://github.com/aws/agentcore-cli/releases/download/prerelease/${TARBALL_BASE}-preview.tgz
7882
\`\`\`" \
7983
--prerelease \
8084
--target "${{ github.sha }}"

scripts/bundle.mjs

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
* npm run bundle
1515
*
1616
* Environment variables:
17-
* AGENTCORE_CDK_PATH — absolute path to the agentcore-l3-cdk-constructs repo
17+
* AGENTCORE_CDK_PATH — path to the agentcore-l3-cdk-constructs repo.
18+
* Falls back to ../agentcore-l3-cdk-constructs, then clones from GitHub.
19+
* AGENTCORE_TARBALL_OUTPUT — output path (without .tgz) for the GA tarball.
20+
* Preview tarball gets '-preview' appended. Relative to cwd.
21+
* AGENTCORE_TARBALL_VERSION_SUFFIX — version prerelease suffix (e.g. "abc12-def34").
22+
* Defaults to a timestamp if not set.
1823
*/
1924
import { execFileSync } from 'node:child_process';
2025
import * as fs from 'node:fs';
@@ -83,7 +88,12 @@ log('Starting bundle process...');
8388

8489
const now = new Date();
8590
const timestamp = now.toISOString().replace(/[-:T]/g, '').slice(0, 14);
86-
log(`Bundle timestamp: ${timestamp}`);
91+
const versionSuffix = process.env.AGENTCORE_TARBALL_VERSION_SUFFIX || timestamp;
92+
if (!/^[\w.-]+$/.test(versionSuffix)) {
93+
console.error(`ERROR: Invalid version suffix: ${versionSuffix}`);
94+
process.exit(1);
95+
}
96+
log(`Bundle version suffix: ${versionSuffix}`);
8797

8898
// Helper to bump a package version with a unique e2e timestamp tag.
8999
// Saves the original version so it can be restored after packing.
@@ -93,7 +103,7 @@ function bumpVersion(pkgDir) {
93103
const originalVersion = pkg.version;
94104
const baseVersion = originalVersion.split('-')[0];
95105
const prerelease = originalVersion.includes('-') ? originalVersion.split('-').slice(1).join('-') : '';
96-
const tag = prerelease ? `${prerelease}-${timestamp}` : timestamp;
106+
const tag = prerelease ? `${prerelease}-${versionSuffix}` : versionSuffix;
97107
pkg.version = `${baseVersion}-${tag}`;
98108
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkg, null, 2) + '\n');
99109
log(`Bumped ${pkg.name} version: ${originalVersion} -> ${pkg.version}`);
@@ -106,6 +116,18 @@ function restoreVersion({ pkgJsonPath, originalVersion }) {
106116
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkg, null, 2) + '\n');
107117
}
108118

119+
/**
120+
* If AGENTCORE_TARBALL_OUTPUT is set, return a resolved path using it as base.
121+
* Appends '-preview' suffix for preview builds. Always appends .tgz.
122+
*/
123+
function resolveTarballPath(tarballPath, { preview = false } = {}) {
124+
const envPath = process.env.AGENTCORE_TARBALL_OUTPUT;
125+
if (!envPath) return tarballPath;
126+
const suffix = preview ? '-preview' : '';
127+
const base = envPath.replace(/\.tgz$/, '');
128+
return path.resolve(`${base}${suffix}.tgz`);
129+
}
130+
109131
// Step 1: Resolve and build CDK constructs
110132
const cdkPath = resolveCdkPath();
111133

@@ -160,11 +182,16 @@ if (!fs.existsSync(cliTarballPath)) {
160182
console.error(`ERROR: Expected GA tarball at ${cliTarballPath} but not found.`);
161183
process.exit(1);
162184
}
163-
log(`Done! GA Tarball: ${cliTarballPath}`);
164-
log(`Install with: npm install -g ${cliTarballPath}`);
165-
log('When you run agentcore create, the bundled CDK constructs will be installed automatically.');
166185

167-
const gaTarballPath = cliTarballPath;
186+
const gaTarballPath = resolveTarballPath(cliTarballPath);
187+
if (gaTarballPath !== cliTarballPath) {
188+
fs.mkdirSync(path.dirname(gaTarballPath), { recursive: true });
189+
fs.renameSync(cliTarballPath, gaTarballPath);
190+
log(`Renamed tarball to: ${gaTarballPath}`);
191+
}
192+
log(`Done! GA Tarball: ${gaTarballPath}`);
193+
log(`Install with: npm install -g ${gaTarballPath}`);
194+
log('When you run agentcore create, the bundled CDK constructs will be installed automatically.');
168195

169196
// Step 6: Rebuild CLI with BUILD_PREVIEW=1
170197
log('Rebuilding CLI with BUILD_PREVIEW=1 for preview tarball...');
@@ -176,7 +203,7 @@ function bumpPreviewVersion(pkgDir) {
176203
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
177204
const originalVersion = pkg.version;
178205
const baseVersion = originalVersion.split('-')[0];
179-
pkg.version = `${baseVersion}-preview-${timestamp}`;
206+
pkg.version = `${baseVersion}-preview-${versionSuffix}`;
180207
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkg, null, 2) + '\n');
181208
log(`Bumped ${pkg.name} version: ${originalVersion} -> ${pkg.version}`);
182209
return { pkgJsonPath, originalVersion, bumpedVersion: pkg.version };
@@ -200,9 +227,16 @@ if (!fs.existsSync(previewTarballPath)) {
200227
process.exit(1);
201228
}
202229

230+
const finalPreviewPath = resolveTarballPath(previewTarballPath, { preview: true });
231+
if (finalPreviewPath !== previewTarballPath) {
232+
fs.mkdirSync(path.dirname(finalPreviewPath), { recursive: true });
233+
fs.renameSync(previewTarballPath, finalPreviewPath);
234+
log(`Renamed tarball to: ${finalPreviewPath}`);
235+
}
236+
203237
// Final output
204238
log(`GA tarball: ${gaTarballPath}`);
205-
log(`Preview tarball: ${previewTarballPath}`);
239+
log(`Preview tarball: ${finalPreviewPath}`);
206240
log(`Install GA: npm install -g ${gaTarballPath}`);
207-
log(`Install Preview: npm install -g ${previewTarballPath}`);
241+
log(`Install Preview: npm install -g ${finalPreviewPath}`);
208242
log('When you run agentcore create, the bundled CDK constructs will be installed automatically.');

0 commit comments

Comments
 (0)