Skip to content

Commit 1bdddf6

Browse files
sundargthbSundar Raghavan
andauthored
chore: improve GitHub Actions workflow input handling (#117)
* chore: improve GitHub Actions workflow input handling Update release workflow to follow GitHub's recommended practices for handling workflow inputs. Changes include: - Use environment variables for workflow dispatch inputs - Apply consistent quoting for shell variables - Align with GitHub Actions security hardening guidelines * fix trailing whitespace --------- Co-authored-by: Sundar Raghavan <[email protected]>
1 parent a87bc30 commit 1bdddf6

File tree

1 file changed

+46
-24
lines changed

1 file changed

+46
-24
lines changed

.github/workflows/release.yml

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,23 @@ jobs:
6565
6666
- name: Bump version
6767
id: bump
68+
env:
69+
CHANGELOG_INPUT: ${{ github.event.inputs.changelog }}
70+
BUMP_TYPE: ${{ github.event.inputs.bump_type }}
6871
run: |
6972
chmod +x scripts/bump_version.py
7073
7174
# If no custom changelog, provide guidance
72-
if [ -z "${{ github.event.inputs.changelog }}" ]; then
75+
if [ -z "$CHANGELOG_INPUT" ]; then
7376
echo "ℹ️ No custom changelog provided. Will auto-generate from commits."
7477
echo "💡 Tip: Provide a meaningful changelog message for better release notes"
7578
fi
7679
77-
if [ -n "${{ github.event.inputs.changelog }}" ]; then
78-
python scripts/bump_version.py ${{ github.event.inputs.bump_type }} \
79-
--changelog "${{ github.event.inputs.changelog }}"
80+
if [ -n "$CHANGELOG_INPUT" ]; then
81+
python scripts/bump_version.py "$BUMP_TYPE" \
82+
--changelog "$CHANGELOG_INPUT"
8083
else
81-
python scripts/bump_version.py ${{ github.event.inputs.bump_type }}
84+
python scripts/bump_version.py "$BUMP_TYPE"
8285
fi
8386
8487
uv lock --no-progress
@@ -88,8 +91,10 @@ jobs:
8891
echo "New version: $NEW_VERSION"
8992
9093
- name: Create release branch and PR
94+
env:
95+
NEW_VERSION: ${{ steps.bump.outputs.version }}
9196
run: |
92-
BRANCH_NAME="release/v${{ steps.bump.outputs.version }}"
97+
BRANCH_NAME="release/v$NEW_VERSION"
9398
9499
if git ls-remote --exit-code --heads origin $BRANCH_NAME; then
95100
echo "⚠️ Branch $BRANCH_NAME already exists. Deleting it first..."
@@ -102,29 +107,39 @@ jobs:
102107
103108
git checkout -b $BRANCH_NAME
104109
git add -A
105-
git commit -m "chore: bump version to ${{ steps.bump.outputs.version }}
110+
git commit -m "chore: bump version to $NEW_VERSION
106111
107112
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
108113
109114
git push origin $BRANCH_NAME
110115
111116
COMMITTED_VERSION=$(git show HEAD:pyproject.toml | grep -m1 -oP '^version = "\K[^"]+')
112-
if [ "$COMMITTED_VERSION" != "${{ steps.bump.outputs.version }}" ]; then
117+
if [ "$COMMITTED_VERSION" != "$NEW_VERSION" ]; then
113118
echo "❌ ERROR: Version not committed correctly!"
114119
exit 1
115120
fi
116121
117122
- name: Create Pull Request
118123
env:
119124
GH_TOKEN: ${{ github.token }}
125+
NEW_VERSION: ${{ steps.bump.outputs.version }}
126+
GITHUB_REF: ${{ github.ref }}
127+
GITHUB_ACTOR: ${{ github.actor }}
120128
run: |
121-
BRANCH_NAME="release/v${{ steps.bump.outputs.version }}"
129+
BRANCH_NAME="release/v$NEW_VERSION"
130+
131+
WARNING_TEXT=""
132+
if [ "$GITHUB_REF" != "refs/heads/main" ]; then
133+
WARNING_TEXT="**WARNING**: Not running from main branch!"
134+
else
135+
WARNING_TEXT="✅ Running from main branch"
136+
fi
122137
123138
gh pr create \
124139
--base main \
125-
--head $BRANCH_NAME \
126-
--title "Release v${{ steps.bump.outputs.version }}" \
127-
--body "## 🚀 Release v${{ steps.bump.outputs.version }}
140+
--head "$BRANCH_NAME" \
141+
--title "Release v$NEW_VERSION" \
142+
--body "## 🚀 Release v$NEW_VERSION
128143
129144
This PR was automatically created by the release workflow.
130145
@@ -145,11 +160,11 @@ jobs:
145160
2. **Manual approval required** before publishing to PyPI
146161
3. GitHub release and tag created after PyPI publication
147162
148-
### 🚨 Running from: ${{ github.ref }}
149-
${{ github.ref != 'refs/heads/main' && '**WARNING**: Not running from main branch!' || '✅ Running from main branch' }}
163+
### 🚨 Running from: $GITHUB_REF
164+
$WARNING_TEXT
150165
151166
---
152-
*Triggered by @${{ github.actor }}*"
167+
*Triggered by @$GITHUB_ACTOR*"
153168
154169
test-and-build:
155170
name: Test and Build
@@ -162,8 +177,9 @@ jobs:
162177
ref: release/v${{ needs.prepare-release.outputs.version }}
163178

164179
- name: Verify version before build
180+
env:
181+
EXPECTED_VERSION: ${{ needs.prepare-release.outputs.version }}
165182
run: |
166-
EXPECTED_VERSION="${{ needs.prepare-release.outputs.version }}"
167183
ACTUAL_VERSION=$(grep -m1 -oP '^version = "\K[^"]+' pyproject.toml)
168184
169185
echo "Expected version: $EXPECTED_VERSION"
@@ -252,8 +268,10 @@ jobs:
252268
path: dist/
253269

254270
- name: Verify PyPI token exists
271+
env:
272+
PYPI_TOKEN_SET: ${{ secrets.PYPI_API_TOKEN != '' }}
255273
run: |
256-
if [ -z "${{ secrets.PYPI_API_TOKEN }}" ]; then
274+
if [ "$PYPI_TOKEN_SET" != "true" ]; then
257275
echo "❌ ERROR: PYPI_API_TOKEN not configured!"
258276
echo "Please add your PyPI API token to GitHub Secrets"
259277
exit 1
@@ -267,9 +285,9 @@ jobs:
267285
echo "version=$VERSION" >> $GITHUB_OUTPUT
268286
269287
- name: Check if version exists on PyPI
288+
env:
289+
VERSION: ${{ steps.version.outputs.version }}
270290
run: |
271-
VERSION="${{ steps.version.outputs.version }}"
272-
273291
# Check if version already exists on PyPI
274292
if pip index versions bedrock-agentcore | grep -q "^Available versions.*$VERSION"; then
275293
echo "❌ ERROR: Version $VERSION already exists on PyPI!"
@@ -283,15 +301,14 @@ jobs:
283301
- name: Publish to PyPI
284302
uses: pypa/gh-action-pypi-publish@release/v1
285303
with:
286-
# MUST specify password to avoid Trusted Publishing issues
287304
password: ${{ secrets.PYPI_API_TOKEN }}
288305
skip-existing: false
289306
verbose: true
290307

291308
- name: Wait for PyPI availability
309+
env:
310+
VERSION: ${{ steps.version.outputs.version }}
292311
run: |
293-
VERSION="${{ steps.version.outputs.version }}"
294-
295312
echo "Waiting for package to be available on PyPI..."
296313
for i in {1..10}; do
297314
if pip index versions bedrock-agentcore | grep -q "$VERSION"; then
@@ -303,14 +320,19 @@ jobs:
303320
done
304321
305322
- name: Create and push tag
323+
env:
324+
VERSION: ${{ steps.version.outputs.version }}
306325
run: |
307326
git config --global user.name "github-actions[bot]"
308327
git config --global user.email "github-actions[bot]@users.noreply.github.com"
309-
git tag -a v${{ steps.version.outputs.version }} -m "Release v${{ steps.version.outputs.version }}"
310-
git push origin v${{ steps.version.outputs.version }}
328+
git tag -a "v$VERSION" -m "Release v$VERSION"
329+
git push origin "v$VERSION"
311330
312331
- name: Create GitHub Release
313332
uses: softprops/action-gh-release@v2
333+
env:
334+
VERSION: ${{ steps.version.outputs.version }}
335+
GITHUB_REPOSITORY: ${{ github.repository }}
314336
with:
315337
tag_name: v${{ steps.version.outputs.version }}
316338
name: Bedrock AgentCore SDK v${{ steps.version.outputs.version }}

0 commit comments

Comments
 (0)