forked from ThirdKeyAI/SchemaPin
-
Notifications
You must be signed in to change notification settings - Fork 0
239 lines (202 loc) · 6.89 KB
/
Copy pathrelease-pypi.yml
File metadata and controls
239 lines (202 loc) · 6.89 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
name: Release PyPI Package
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
tag:
description: 'Release tag (e.g., v1.1.0)'
required: true
type: string
test_pypi_only:
description: 'Publish to Test PyPI only'
required: false
type: boolean
default: false
dry_run:
description: 'Dry run (skip actual publish)'
required: false
type: boolean
default: false
jobs:
release-pypi:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Install package dependencies
run: |
cd python
pip install -e ".[dev]"
- name: Run tests
run: |
cd python
python -m pytest tests/ -v
- name: Run ruff checks
run: |
cd python
ruff check .
- name: Run bandit security checks
run: |
cd python
bandit -r . --exclude tests/
- name: Check version consistency
run: |
cd python
PY_VERSION=$(grep '^version = ' pyproject.toml | cut -d'"' -f2)
cd ../javascript
JS_VERSION=$(node -p "require('./package.json').version")
if [ "$PY_VERSION" != "$JS_VERSION" ]; then
echo "Version mismatch: Python=$PY_VERSION, JS=$JS_VERSION"
exit 1
fi
echo "Version consistency check passed: $PY_VERSION"
- name: Build package
run: |
cd python
python -m build
- name: Check package
run: |
cd python
twine check dist/*
- name: Test package installation
run: |
cd python
# Create virtual environment for testing
python -m venv test_env
source test_env/bin/activate
# Install built package
pip install dist/*.whl
# Test basic functionality
python -c "
import schemapin
from schemapin.crypto import KeyManager
from schemapin.core import SchemaPinCore
# Test basic functionality
private_key, public_key = KeyManager.generate_keypair()
core = SchemaPinCore()
schema = {'test': 'schema'}
canonical = core.canonicalize_schema(schema)
print('✅ Package installation test passed')
"
# Test CLI tools
schemapin-keygen --help
schemapin-sign --help
schemapin-verify --help
- name: Check if version exists on PyPI
run: |
cd python
PACKAGE_NAME=$(grep '^name = ' pyproject.toml | cut -d'"' -f2)
VERSION=$(grep '^version = ' pyproject.toml | cut -d'"' -f2)
echo "Checking if version $VERSION of $PACKAGE_NAME exists on PyPI..."
# Check if version exists on PyPI by looking in the "Available versions" line
if pip index versions "$PACKAGE_NAME" 2>/dev/null | grep "Available versions:" | grep -q "\b$VERSION\b"; then
echo "❌ Version $VERSION already exists on PyPI"
exit 1
else
echo "✅ Version $VERSION is available for publishing"
fi
- name: Publish to Test PyPI (dry run)
if: ${{ github.event.inputs.dry_run == 'true' }}
run: |
cd python
echo "Dry run - would publish to Test PyPI:"
ls -la dist/
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
- name: Publish to Test PyPI
if: ${{ github.event.inputs.dry_run != 'true' }}
run: |
cd python
twine upload --repository testpypi dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
- name: Test installation from Test PyPI
if: ${{ github.event.inputs.dry_run != 'true' }}
run: |
# Wait for package to be available
sleep 60
# Create fresh environment
python -m venv test_testpypi
source test_testpypi/bin/activate
# Install from Test PyPI
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ schemapin
# Test functionality
python -c "
import schemapin
from schemapin.crypto import KeyManager
print('✅ Test PyPI installation successful')
"
- name: Publish to PyPI (production)
if: ${{ github.event.inputs.dry_run != 'true' && github.event.inputs.test_pypi_only != 'true' }}
run: |
cd python
twine upload dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
- name: Test installation from PyPI
if: ${{ github.event.inputs.dry_run != 'true' && github.event.inputs.test_pypi_only != 'true' }}
run: |
# Wait for package to be available
sleep 60
# Create fresh environment
python -m venv test_pypi
source test_pypi/bin/activate
# Install from PyPI
pip install schemapin
# Test functionality
python -c "
import schemapin
from schemapin.crypto import KeyManager
print('✅ PyPI installation successful')
"
- name: Create GitHub Release
if: ${{ github.event.inputs.dry_run != 'true' && startsWith(github.ref, 'refs/tags/') }}
run: |
PRERELEASE=""
if [[ "${{ github.ref_name }}" == *"alpha"* ]] || [[ "${{ github.ref_name }}" == *"beta"* ]] || [[ "${{ github.ref_name }}" == *"rc"* ]]; then
PRERELEASE="--prerelease"
fi
gh release create ${{ github.ref_name }} \
--title "Release ${{ github.ref_name }}" \
--notes "## PyPI Package Release
Published \`schemapin==${{ github.ref_name }}\` to PyPI.
### Installation
\`\`\`bash
pip install schemapin
\`\`\`
### CLI Tools
\`\`\`bash
schemapin-keygen --help
schemapin-sign --help
schemapin-verify --help
\`\`\`
### Changes
See [CHANGELOG.md](./CHANGELOG.md) for details." \
$PRERELEASE
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Required secrets to configure in GitHub repository settings:
# - PYPI_API_TOKEN: PyPI API token with upload permissions
# Generate at: https://pypi.org/manage/account/token/
# Should have "Entire account" scope or specific project scope
# - TEST_PYPI_API_TOKEN: Test PyPI API token with upload permissions
# Generate at: https://test.pypi.org/manage/account/token/
# Should have "Entire account" scope or specific project scope