|
| 1 | +name: Upload Python Package |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [master] |
| 6 | + paths: |
| 7 | + - 'setup.py' |
| 8 | + |
| 9 | +jobs: |
| 10 | + deploy: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + id-token: write # needed for Trusted Publishing |
| 14 | + contents: read |
| 15 | + |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Check version bump |
| 20 | + id: version_check |
| 21 | + run: | |
| 22 | + NEW_VERSION=$(python -c "import re; print(re.search(r\"version='([^']+)'\", open('setup.py').read()).group(1))") |
| 23 | + echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT" |
| 24 | + pip install ecell4 2>/dev/null && \ |
| 25 | + CURRENT_VERSION=$(pip show ecell4 | grep ^Version | awk '{print $2}') || \ |
| 26 | + CURRENT_VERSION="0.0.0" |
| 27 | + if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then |
| 28 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
| 29 | + else |
| 30 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 31 | + fi |
| 32 | +
|
| 33 | + - name: Set up Python |
| 34 | + if: steps.version_check.outputs.changed == 'true' |
| 35 | + uses: actions/setup-python@v5 |
| 36 | + with: |
| 37 | + python-version: '3.x' |
| 38 | + |
| 39 | + - name: Install build tooling |
| 40 | + if: steps.version_check.outputs.changed == 'true' |
| 41 | + run: | |
| 42 | + python -m pip install --upgrade pip |
| 43 | + pip install build |
| 44 | +
|
| 45 | + - name: Build |
| 46 | + if: steps.version_check.outputs.changed == 'true' |
| 47 | + run: python -m build |
| 48 | + |
| 49 | + - name: Publish to PyPI |
| 50 | + if: steps.version_check.outputs.changed == 'true' |
| 51 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 52 | + |
| 53 | + - name: Create GitHub Release |
| 54 | + if: steps.version_check.outputs.changed == 'true' |
| 55 | + env: |
| 56 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 57 | + run: | |
| 58 | + VERSION=${{ steps.version_check.outputs.version }} |
| 59 | + git tag "v${VERSION}" |
| 60 | + git push origin "v${VERSION}" |
| 61 | + gh release create "v${VERSION}" dist/* \ |
| 62 | + --title "v${VERSION}" \ |
| 63 | + --generate-notes |
0 commit comments