Skip to content

Commit 5bdf009

Browse files
sundargthbSundar Raghavan
andauthored
ci: migrate PyPI publishing to OIDC Trusted Publishing (aws#363)
Co-authored-by: Sundar Raghavan <sdraghav@amazon.com>
1 parent cd86ebd commit 5bdf009

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

.github/workflows/release-publish.yml

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ jobs:
8080
name: pypi
8181
url: https://pypi.org/project/bedrock-agentcore/
8282

83+
# id-token: write is required for OIDC Trusted Publishing.
84+
# This replaces the PYPI_API_TOKEN secret
85+
permissions:
86+
id-token: write
87+
contents: write
88+
8389
steps:
8490
- uses: actions/checkout@v6
8591
with:
@@ -91,30 +97,27 @@ jobs:
9197
name: dist
9298
path: dist/
9399

94-
- name: Verify PyPI token exists
95-
env:
96-
PYPI_TOKEN_SET: ${{ secrets.PYPI_API_TOKEN != '' }}
97-
run: |
98-
if [ "$PYPI_TOKEN_SET" != "true" ]; then
99-
echo "❌ ERROR: PYPI_API_TOKEN not configured!"
100-
exit 1
101-
fi
102-
echo "✓ PyPI token is configured"
103-
104-
- name: Check if version exists on PyPI
100+
# Uses the PyPI JSON API — stable and versioned.
101+
# pip index versions output format is not guaranteed stable across
102+
# pip versions and should not be used in CI.
103+
- name: Check if version already exists on PyPI
105104
env:
106105
VERSION: ${{ needs.build.outputs.version }}
107106
run: |
108-
if pip index versions bedrock-agentcore | grep -q "^Available versions.*$VERSION"; then
107+
PYPI_VERSIONS=$(curl -sf https://pypi.org/pypi/bedrock-agentcore/json \
108+
| python3 -c "import sys, json; releases = json.load(sys.stdin)['releases']; print('\n'.join(releases.keys()))")
109+
110+
if echo "$PYPI_VERSIONS" | grep -qx "$VERSION"; then
109111
echo "❌ ERROR: Version $VERSION already exists on PyPI!"
110112
exit 1
111113
fi
112114
echo "✓ Version $VERSION is not on PyPI, safe to publish"
113115
116+
# automatically detects and uses Trusted Publishing via OIDC when
117+
# no token is provided and id-token: write permission is set.
114118
- name: Publish to PyPI
115119
uses: pypa/gh-action-pypi-publish@release/v1
116120
with:
117-
password: ${{ secrets.PYPI_API_TOKEN }}
118121
skip-existing: false
119122
verbose: true
120123

@@ -124,7 +127,9 @@ jobs:
124127
run: |
125128
echo "Waiting for package to be available on PyPI..."
126129
for i in {1..10}; do
127-
if pip index versions bedrock-agentcore | grep -q "$VERSION"; then
130+
PYPI_VERSIONS=$(curl -sf https://pypi.org/pypi/bedrock-agentcore/json \
131+
| python3 -c "import sys, json; releases = json.load(sys.stdin)['releases']; print('\n'.join(releases.keys()))" 2>/dev/null)
132+
if echo "$PYPI_VERSIONS" | grep -qx "$VERSION"; then
128133
echo "✓ Package version $VERSION is now available on PyPI"
129134
break
130135
fi

0 commit comments

Comments
 (0)