@@ -35,13 +35,28 @@ jobs:
3535 outputs :
3636 version : ${{ steps.bump.outputs.version }}
3737 branch : ${{ steps.bump.outputs.branch }}
38+ dist_tag : ${{ steps.release-meta.outputs.dist_tag }}
39+ base_branch : ${{ steps.release-meta.outputs.base_branch }}
3840
3941 steps :
40- - name : Validate running from main
42+ - name : Determine release metadata
43+ id : release-meta
4144 run : |
42- if [[ "${{ github.ref }}" != "refs/heads/main" ]]; then
43- echo "⚠️ WARNING: Running from ${{ github.ref }}"
44- echo "⚠️ Production releases should only run from main branch"
45+ BRANCH_NAME="${{ github.ref_name }}"
46+ VERSION_BUMP="${{ github.event.inputs.bump_type }}"
47+
48+ if [[ "$BRANCH_NAME" == "main" ]]; then
49+ echo "dist_tag=latest" >> $GITHUB_OUTPUT
50+ echo "base_branch=main" >> $GITHUB_OUTPUT
51+ else
52+ if [[ "$VERSION_BUMP" != "preview" && "$VERSION_BUMP" != "preview-major" && "$VERSION_BUMP" != "prerelease" ]]; then
53+ echo "❌ ERROR: Only preview, preview-major, and prerelease bump types are allowed from non-main branches."
54+ echo "Current branch: $BRANCH_NAME, bump type: $VERSION_BUMP"
55+ exit 1
56+ fi
57+ echo "dist_tag=preview" >> $GITHUB_OUTPUT
58+ echo "base_branch=$BRANCH_NAME" >> $GITHUB_OUTPUT
59+ echo "ℹ️ Publishing preview release from branch: $BRANCH_NAME"
4560 fi
4661
4762 - name : Checkout code
@@ -177,46 +192,39 @@ jobs:
177192 env :
178193 GH_TOKEN : ${{ github.token }}
179194 NEW_VERSION : ${{ steps.bump.outputs.version }}
180- GITHUB_REF : ${{ github.ref }}
195+ BASE_BRANCH : ${{ steps.release-meta.outputs.base_branch }}
196+ DIST_TAG : ${{ steps.release-meta.outputs.dist_tag }}
181197 GITHUB_ACTOR : ${{ github.actor }}
182198 run : |
183199 BRANCH_NAME="release/v$NEW_VERSION"
184200
185- WARNING_TEXT=""
186- if [ "$GITHUB_REF" != "refs/heads/main" ]; then
187- WARNING_TEXT="**WARNING**: Not running from main branch!"
188- else
189- WARNING_TEXT="✅ Running from main branch"
201+ RELEASE_TYPE="Production"
202+ if [ "$DIST_TAG" != "latest" ]; then
203+ RELEASE_TYPE="Preview (npm tag: $DIST_TAG)"
190204 fi
191205
192206 gh pr create \
193- --base main \
207+ --base "$BASE_BRANCH" \
194208 --head "$BRANCH_NAME" \
195209 --title "Release v$NEW_VERSION" \
196- --body "## 🚀 Release v$NEW_VERSION
210+ --body "## Release v$NEW_VERSION
197211
198212 This PR was automatically created by the release workflow.
199213
200- ### ⚠️ Pre-merge Checklist
214+ **Release type:** $RELEASE_TYPE
215+ **Base branch:** $BASE_BRANCH
216+
217+ ### Pre-merge Checklist
201218 - [ ] Review CHANGELOG.md - ensure it has meaningful release notes
202219 - [ ] Verify version numbers are correct in all files
203220 - [ ] All CI checks are passing
204221
205- ### 📝 How to improve changelog
206- If the auto-generated changelog isn't good enough:
207- 1. Edit CHANGELOG.md in this PR
208- 2. Commit the changes
209- 3. Then approve and merge
210-
211- ### 🔄 Release Process
222+ ### Release Process
212223 After merging this PR:
213224 1. Package will be built and tested
214225 2. **Manual approval required** before publishing to npm
215226 3. GitHub release and tag created after publication
216227
217- ### 🚨 Running from: $GITHUB_REF
218- $WARNING_TEXT
219-
220228 ---
221229 *Triggered by @$GITHUB_ACTOR*"
222230
@@ -311,7 +319,6 @@ jobs:
311319 name : Publish to npm
312320 needs : [prepare-release, release-approval]
313321 runs-on : ubuntu-latest
314- if : github.ref == 'refs/heads/main'
315322 environment :
316323 name : npm-publish
317324 url : https://www.npmjs.com/package/@aws/agentcore
@@ -320,14 +327,15 @@ jobs:
320327 contents : write # Required to push git tags
321328
322329 steps :
323- - name : Checkout latest main (AFTER PR merge)
330+ - name : Checkout base branch (AFTER PR merge)
324331 uses : actions/checkout@v6
325332 with :
326- ref : main
333+ ref : ${{ needs.prepare-release.outputs.base_branch }}
327334 fetch-depth : 0
328335
329336 - name : Verify we have the merged code
330337 run : |
338+ echo "Branch: ${{ needs.prepare-release.outputs.base_branch }}"
331339 echo "Current version in package.json:"
332340 cat package.json | grep '"version"'
333341 echo ""
@@ -362,24 +370,25 @@ jobs:
362370 env :
363371 VERSION : ${{ steps.version.outputs.version }}
364372 EXPECTED_VERSION : ${{ needs.prepare-release.outputs.version }}
373+ BASE_BRANCH : ${{ needs.prepare-release.outputs.base_branch }}
365374 run : |
366- echo "Version in main branch : $VERSION"
375+ echo "Version in $BASE_BRANCH : $VERSION"
367376 echo "Expected version from PR: $EXPECTED_VERSION"
368377
369378 if [ "$VERSION" != "$EXPECTED_VERSION" ]; then
370379 echo ""
371380 echo "❌ ERROR: Version mismatch!"
372381 echo ""
373382 echo "The release PR has NOT been merged yet."
374- echo "Main branch has: $VERSION"
383+ echo "$BASE_BRANCH has: $VERSION"
375384 echo "Release PR has: $EXPECTED_VERSION"
376385 echo ""
377- echo "👉 Please MERGE the release PR first, then approve this deployment."
386+ echo "Please MERGE the release PR first, then approve this deployment."
378387 echo ""
379388 exit 1
380389 fi
381390
382- echo "✅ Version matches - PR was merged correctly"
391+ echo "Version matches - PR was merged correctly"
383392
384393 - name : Install dependencies
385394 run : npm ci
@@ -388,10 +397,13 @@ jobs:
388397 run : npm run build
389398
390399 - name : Publish to npm (using OIDC trusted publishing)
400+ env :
401+ DIST_TAG : ${{ needs.prepare-release.outputs.dist_tag }}
391402 run : |
392403 echo "Publishing with OIDC trusted publishing..."
393404 echo "No NPM_TOKEN needed - using GitHub OIDC"
394- npm publish --access public --provenance --tag latest
405+ echo "Dist tag: $DIST_TAG"
406+ npm publish --access public --provenance --tag "$DIST_TAG"
395407
396408 - name : Create and push tag
397409 env :
0 commit comments