-
Notifications
You must be signed in to change notification settings - Fork 45
194 lines (160 loc) · 6.82 KB
/
Copy pathrelease-python-sdk.yml
File metadata and controls
194 lines (160 loc) · 6.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
name: Release Python SDK
on:
release:
types: [published]
permissions:
contents: read
id-token: write
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install uv
uses: astral-sh/setup-uv@v2
- name: Install dev dependencies with uv
working-directory: python-sdk
run: |
uv sync --group dev
- name: Install python-sdk package (editable)
working-directory: python-sdk
run: |
uv pip install -e .
- name: Run tests with pytest and coverage
working-directory: python-sdk
run: |
uv run pytest --cov=exospherehost --cov-report=xml --cov-report=term-missing -v --junitxml=pytest-report.xml
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: exospherehost/exospherehost
files: python-sdk/coverage.xml
flags: python-sdk-unittests
name: python-sdk-coverage-report
fail_ci_if_error: true
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: python-sdk-test-results
path: python-sdk/pytest-report.xml
retention-days: 30
publish:
runs-on: ubuntu-latest
needs: test
defaults:
run:
working-directory: python-sdk
if: github.repository == 'exospherehost/exospherehost'
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v6
name: Install uv
- run: uv python install
- run: uv sync --locked --dev
- name: Update version to release tag
run: |
# Extract version from tag (remove 'v' or 'V' prefix if present)
RELEASE_VERSION="${{ github.ref_name }}"
# Handle empty or invalid tags
if [[ -z "$RELEASE_VERSION" ]]; then
echo "ERROR: Release tag is empty"
exit 1
fi
# Remove 'v' or 'V' prefix (case insensitive)
if [[ $RELEASE_VERSION =~ ^[vV] ]]; then
RELEASE_VERSION="${RELEASE_VERSION#?}" # Remove first character
fi
# Validate the extracted version is not empty
if [[ -z "$RELEASE_VERSION" ]]; then
echo "ERROR: Invalid tag format - version part is empty"
exit 1
fi
# Update the version file
echo "version = \"$RELEASE_VERSION\"" > exospherehost/_version.py
echo "Updated version to $RELEASE_VERSION for release"
- name: Verify version format
run: |
uv run python -c "
import sys
sys.path.append('.')
from exospherehost._version import version
import re
# Check if version matches semantic versioning pattern
if not re.match(r'^\d+\.\d+\.\d+$', version):
print(f'ERROR: Version {version} does not match semantic versioning pattern (x.y.z)')
sys.exit(1)
# Ensure it's not a beta version (should not contain 'b')
if 'b' in version:
print(f'ERROR: Release version {version} contains beta indicator. Release versions should not be beta.')
sys.exit(1)
print(f'Version {version} is valid for release publishing')
"
- name: Generate requirements file for SBOM
run: |
uv export --locked --format=requirements-txt --output-file=requirements.txt
echo "Generated requirements.txt for SBOM creation from lockfile"
- name: Install SBOM generation tools
run: |
uv tool install cyclonedx-bom
uv tool install pip-audit
- name: Generate SBOM with CycloneDX
run: |
uv tool run cyclonedx-py requirements --format json --output-file sbom-cyclonedx.json requirements.txt
uv tool run cyclonedx-py requirements --format xml --output-file sbom-cyclonedx.xml requirements.txt
echo "Generated CycloneDX SBOM in JSON and XML formats"
- name: Generate vulnerability report with pip-audit
run: |
uv tool run pip-audit --format json --output vulnerability-report.json --requirement requirements.txt || true
echo "Generated vulnerability report (non-blocking)"
- name: Create SBOM summary
run: |
echo "## Software Bill of Materials (SBOM)" > sbom-summary.md
echo "" >> sbom-summary.md
echo "This release includes the following supply chain security artifacts:" >> sbom-summary.md
echo "" >> sbom-summary.md
echo "- **Provenance**: Cryptographic proof of build integrity using GitHub's OIDC tokens" >> sbom-summary.md
echo "- **SBOM**: Complete dependency inventory in CycloneDX format" >> sbom-summary.md
echo "- **Vulnerability Report**: Security scan results for all dependencies" >> sbom-summary.md
echo "" >> sbom-summary.md
echo "### Dependencies Count:" >> sbom-summary.md
echo "- Direct dependencies: $(grep -c '^[^#]' requirements.txt || echo '0')" >> sbom-summary.md
echo "- Total dependencies (including transitive): $(wc -l < requirements.txt)" >> sbom-summary.md
echo "" >> sbom-summary.md
echo "### Verification:" >> sbom-summary.md
echo "You can verify this package's provenance on PyPI using:" >> sbom-summary.md
echo '```bash' >> sbom-summary.md
echo 'pip install sigstore' >> sbom-summary.md
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
echo '```' >> sbom-summary.md
- run: uv build
- name: Publish to PyPI with provenance
run: uv publish --provenance
- name: Upload SBOM artifacts
uses: actions/upload-artifact@v4
with:
name: sbom-artifacts-${{ github.ref_name }}
path: |
python-sdk/sbom-cyclonedx.json
python-sdk/sbom-cyclonedx.xml
python-sdk/requirements.txt
python-sdk/vulnerability-report.json
python-sdk/sbom-summary.md
retention-days: 90
- name: Add SBOM to release assets
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
python-sdk/sbom-cyclonedx.json
python-sdk/sbom-cyclonedx.xml
python-sdk/sbom-summary.md
python-sdk/vulnerability-report.json
body_path: python-sdk/sbom-summary.md
append_body: true