@@ -33,13 +33,28 @@ jobs:
3333 outputs :
3434 version : ${{ steps.bump.outputs.version }}
3535 branch : ${{ steps.bump.outputs.branch }}
36+ dist_tag : ${{ steps.release-meta.outputs.dist_tag }}
37+ base_branch : ${{ steps.release-meta.outputs.base_branch }}
3638
3739 steps :
38- - name : Validate running from main
40+ - name : Determine release metadata
41+ id : release-meta
3942 run : |
40- if [[ "${{ github.ref }}" != "refs/heads/main" ]]; then
41- echo "⚠️ WARNING: Running from ${{ github.ref }}"
42- echo "⚠️ Production releases should only run from main branch"
43+ BRANCH_NAME="${{ github.ref_name }}"
44+ VERSION_BUMP="${{ github.event.inputs.bump_type }}"
45+
46+ if [[ "$BRANCH_NAME" == "main" ]]; then
47+ echo "dist_tag=latest" >> $GITHUB_OUTPUT
48+ echo "base_branch=main" >> $GITHUB_OUTPUT
49+ else
50+ if [[ "$VERSION_BUMP" != "prerelease" ]]; then
51+ echo "❌ ERROR: Only the prerelease bump type is allowed from non-main branches."
52+ echo "Current branch: $BRANCH_NAME, bump type: $VERSION_BUMP"
53+ exit 1
54+ fi
55+ echo "dist_tag=preview" >> $GITHUB_OUTPUT
56+ echo "base_branch=$BRANCH_NAME" >> $GITHUB_OUTPUT
57+ echo "ℹ️ Publishing preview release from branch: $BRANCH_NAME"
4358 fi
4459
4560 - name : Checkout code
@@ -149,46 +164,39 @@ jobs:
149164 env :
150165 GH_TOKEN : ${{ github.token }}
151166 NEW_VERSION : ${{ steps.bump.outputs.version }}
152- GITHUB_REF : ${{ github.ref }}
167+ BASE_BRANCH : ${{ steps.release-meta.outputs.base_branch }}
168+ DIST_TAG : ${{ steps.release-meta.outputs.dist_tag }}
153169 GITHUB_ACTOR : ${{ github.actor }}
154170 run : |
155171 BRANCH_NAME="release/v$NEW_VERSION"
156172
157- WARNING_TEXT=""
158- if [ "$GITHUB_REF" != "refs/heads/main" ]; then
159- WARNING_TEXT="**WARNING**: Not running from main branch!"
160- else
161- WARNING_TEXT="✅ Running from main branch"
173+ RELEASE_TYPE="Production"
174+ if [ "$DIST_TAG" != "latest" ]; then
175+ RELEASE_TYPE="Preview (npm tag: $DIST_TAG)"
162176 fi
163177
164178 gh pr create \
165- --base main \
179+ --base "$BASE_BRANCH" \
166180 --head "$BRANCH_NAME" \
167181 --title "Release v$NEW_VERSION" \
168- --body "## 🚀 Release v$NEW_VERSION
182+ --body "## Release v$NEW_VERSION
169183
170184 This PR was automatically created by the release workflow.
171185
172- ### ⚠️ Pre-merge Checklist
186+ **Release type:** $RELEASE_TYPE
187+ **Base branch:** $BASE_BRANCH
188+
189+ ### Pre-merge Checklist
173190 - [ ] Review CHANGELOG.md - ensure it has meaningful release notes
174191 - [ ] Verify version numbers are correct in all files
175192 - [ ] All CI checks are passing
176193
177- ### 📝 How to improve changelog
178- If the auto-generated changelog isn't good enough:
179- 1. Edit CHANGELOG.md in this PR
180- 2. Commit the changes
181- 3. Then approve and merge
182-
183- ### 🔄 Release Process
194+ ### Release Process
184195 After merging this PR:
185196 1. Package will be built and tested
186197 2. **Manual approval required** before publishing to npm
187198 3. GitHub release and tag created after publication
188199
189- ### 🚨 Running from: $GITHUB_REF
190- $WARNING_TEXT
191-
192200 ---
193201 *Triggered by @$GITHUB_ACTOR*"
194202
@@ -283,7 +291,6 @@ jobs:
283291 name : Publish to npm
284292 needs : [prepare-release, release-approval]
285293 runs-on : ubuntu-latest
286- if : github.ref == 'refs/heads/main'
287294 environment :
288295 name : npm-publish
289296 url : https://www.npmjs.com/package/@aws/agentcore
@@ -292,14 +299,15 @@ jobs:
292299 contents : write # Required to push git tags
293300
294301 steps :
295- - name : Checkout latest main (AFTER PR merge)
302+ - name : Checkout base branch (AFTER PR merge)
296303 uses : actions/checkout@v6
297304 with :
298- ref : main
305+ ref : ${{ needs.prepare-release.outputs.base_branch }}
299306 fetch-depth : 0
300307
301308 - name : Verify we have the merged code
302309 run : |
310+ echo "Branch: ${{ needs.prepare-release.outputs.base_branch }}"
303311 echo "Current version in package.json:"
304312 cat package.json | grep '"version"'
305313 echo ""
@@ -334,24 +342,25 @@ jobs:
334342 env :
335343 VERSION : ${{ steps.version.outputs.version }}
336344 EXPECTED_VERSION : ${{ needs.prepare-release.outputs.version }}
345+ BASE_BRANCH : ${{ needs.prepare-release.outputs.base_branch }}
337346 run : |
338- echo "Version in main branch : $VERSION"
347+ echo "Version in $BASE_BRANCH : $VERSION"
339348 echo "Expected version from PR: $EXPECTED_VERSION"
340349
341350 if [ "$VERSION" != "$EXPECTED_VERSION" ]; then
342351 echo ""
343352 echo "❌ ERROR: Version mismatch!"
344353 echo ""
345354 echo "The release PR has NOT been merged yet."
346- echo "Main branch has: $VERSION"
355+ echo "$BASE_BRANCH has: $VERSION"
347356 echo "Release PR has: $EXPECTED_VERSION"
348357 echo ""
349- echo "👉 Please MERGE the release PR first, then approve this deployment."
358+ echo "Please MERGE the release PR first, then approve this deployment."
350359 echo ""
351360 exit 1
352361 fi
353362
354- echo "✅ Version matches - PR was merged correctly"
363+ echo "Version matches - PR was merged correctly"
355364
356365 - name : Install dependencies
357366 run : npm ci
@@ -360,10 +369,13 @@ jobs:
360369 run : npm run build
361370
362371 - name : Publish to npm (using OIDC trusted publishing)
372+ env :
373+ DIST_TAG : ${{ needs.prepare-release.outputs.dist_tag }}
363374 run : |
364375 echo "Publishing with OIDC trusted publishing..."
365376 echo "No NPM_TOKEN needed - using GitHub OIDC"
366- npm publish --access public --provenance --tag latest
377+ echo "Dist tag: $DIST_TAG"
378+ npm publish --access public --provenance --tag "$DIST_TAG"
367379
368380 - name : Create and push tag
369381 env :
0 commit comments