|
| 1 | +# .github/workflows/main.yml (Python) |
| 2 | +name: Release Python SDK |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: [master] |
| 7 | + paths: |
| 8 | + - '.changelog/v*.md' |
| 9 | + |
| 10 | +jobs: |
| 11 | + release: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + permissions: |
| 14 | + contents: write |
| 15 | + id-token: write # Required for PyPI trusted publishing |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout |
| 19 | + uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + fetch-depth: 0 |
| 22 | + |
| 23 | + - name: Setup Python |
| 24 | + uses: actions/setup-python@v5 |
| 25 | + with: |
| 26 | + python-version: '3.11' |
| 27 | + |
| 28 | + - name: Extract Version |
| 29 | + id: version |
| 30 | + run: | |
| 31 | + VERSION=$(grep -oP "version\s*=\s*['\"]?\K[^'\"]+" pyproject.toml 2>/dev/null) |
| 32 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 33 | + echo "tag=v$VERSION" >> $GITHUB_OUTPUT |
| 34 | +
|
| 35 | + - name: Install Dependencies |
| 36 | + run: | |
| 37 | + python -m pip install --upgrade pip |
| 38 | + pip install build twine |
| 39 | +
|
| 40 | + - name: Build Package |
| 41 | + run: python -m build |
| 42 | + |
| 43 | + - name: Create Tag |
| 44 | + run: | |
| 45 | + git config user.name "github-actions[bot]" |
| 46 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 47 | + git tag -a ${{ steps.version.outputs.tag }} -m "Release ${{ steps.version.outputs.tag }}" |
| 48 | + git push origin ${{ steps.version.outputs.tag }} |
| 49 | +
|
| 50 | + - name: Read Changelog |
| 51 | + id: changelog |
| 52 | + run: | |
| 53 | + CHANGELOG_FILE=".changelog/${{ steps.version.outputs.tag }}.md" |
| 54 | + if [ -f "$CHANGELOG_FILE" ]; then |
| 55 | + delimiter="$(openssl rand -hex 8)" |
| 56 | + echo "content<<$delimiter" >> $GITHUB_OUTPUT |
| 57 | + cat "$CHANGELOG_FILE" >> $GITHUB_OUTPUT |
| 58 | + echo "" >> $GITHUB_OUTPUT |
| 59 | + echo "$delimiter" >> $GITHUB_OUTPUT |
| 60 | + else |
| 61 | + echo "content=Release ${{ steps.version.outputs.tag }}" >> $GITHUB_OUTPUT |
| 62 | + fi |
| 63 | +
|
| 64 | + - name: Create Release |
| 65 | + uses: softprops/action-gh-release@v1 |
| 66 | + with: |
| 67 | + tag_name: ${{ steps.version.outputs.tag }} |
| 68 | + name: Release ${{ steps.version.outputs.tag }} |
| 69 | + body: ${{ steps.changelog.outputs.content }} |
| 70 | + |
| 71 | + - name: Publish to PyPI |
| 72 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 73 | + with: |
| 74 | + password: ${{ secrets.PYPI_API_TOKEN }} |
| 75 | + |
0 commit comments