Skip to content

Commit 586ec1a

Browse files
committed
Enhance publish and release workflows for Python SDK
- Updated publish-python-sdk.yml and release-python-sdk.yml to generate requirements.txt from the lockfile for improved dependency management. - Added version checks before publishing to PyPI to prevent overwriting existing versions. - Included version output for installed SBOM generation tools to ensure transparency in the CI process.
1 parent de419d9 commit 586ec1a

2 files changed

Lines changed: 34 additions & 6 deletions

File tree

.github/workflows/publish-python-sdk.yml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,17 @@ jobs:
9292
9393
- name: Generate requirements file for SBOM
9494
run: |
95-
uv export --format=requirements-txt --output-file=requirements.txt
96-
echo "Generated requirements.txt for SBOM creation"
95+
uv export --locked --format=requirements-txt --output-file=requirements.txt
96+
echo "Generated requirements.txt for SBOM creation from lockfile"
9797
9898
- name: Install SBOM generation tools
9999
run: |
100100
uv tool install cyclonedx-bom
101+
echo "Installed cyclonedx-bom version:"
102+
uv tool run cyclonedx-bom --version
101103
uv tool install pip-audit
104+
echo "Installed pip-audit version:"
105+
uv tool run pip-audit --version
102106
103107
- name: Generate SBOM with CycloneDX
104108
run: |
@@ -113,7 +117,30 @@ jobs:
113117
- run: uv build
114118

115119
- name: Publish to PyPI with provenance
116-
run: uv publish --provenance
120+
run: |
121+
# Get the current version
122+
VERSION=$(uv run python -c "
123+
import sys
124+
sys.path.append('.')
125+
from exospherehost._version import version
126+
print(version)
127+
")
128+
129+
echo "Checking if exospherehost version $VERSION already exists on PyPI..."
130+
131+
# Query PyPI JSON API to check if version exists
132+
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "https://pypi.org/pypi/exospherehost/$VERSION/json")
133+
134+
if [ "$HTTP_STATUS" = "200" ]; then
135+
echo "Version $VERSION already exists on PyPI. Skipping publish."
136+
exit 0
137+
elif [ "$HTTP_STATUS" = "404" ]; then
138+
echo "Version $VERSION not found on PyPI. Proceeding with publish."
139+
uv publish --provenance
140+
else
141+
echo "Unexpected HTTP status $HTTP_STATUS when checking PyPI. Proceeding with publish."
142+
uv publish --provenance
143+
fi
117144
118145
- name: Upload SBOM artifacts
119146
uses: actions/upload-artifact@v4

.github/workflows/release-python-sdk.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ jobs:
124124
125125
- name: Generate requirements file for SBOM
126126
run: |
127-
uv export --format=requirements-txt --output-file=requirements.txt
128-
echo "Generated requirements.txt for SBOM creation"
127+
uv export --locked --format=requirements-txt --output-file=requirements.txt
128+
echo "Generated requirements.txt for SBOM creation from lockfile"
129129
130130
- name: Install SBOM generation tools
131131
run: |
@@ -161,7 +161,7 @@ jobs:
161161
echo "You can verify this package's provenance on PyPI using:" >> sbom-summary.md
162162
echo '```bash' >> sbom-summary.md
163163
echo 'pip install sigstore' >> sbom-summary.md
164-
echo 'python -m sigstore verify --bundle <bundle-file> exospherehost==${{ github.ref_name }}' >> sbom-summary.md
164+
echo 'python -m sigstore verify --bundle <bundle-file> exospherehost==${{ startsWith(github.ref_name, 'v') && substring(github.ref_name, 1) || github.ref_name }}' >> sbom-summary.md
165165
echo '```' >> sbom-summary.md
166166
167167
- run: uv build
@@ -189,5 +189,6 @@ jobs:
189189
python-sdk/sbom-cyclonedx.json
190190
python-sdk/sbom-cyclonedx.xml
191191
python-sdk/sbom-summary.md
192+
python-sdk/vulnerability-report.json
192193
body_path: python-sdk/sbom-summary.md
193194
append_body: true

0 commit comments

Comments
 (0)