Merge pull request #12 from cloudspannerecosystem/version-bump #48
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish Python π distributions π¦ to PyPI and TestPyPI | |
on: | |
push: | |
branches: | |
- main | |
# This job should be kept in sync with the job in `build-test.yml`, | |
# except the version in that file should actually publish the built artifacts, | |
# not just validate that they build. | |
jobs: | |
build-n-publish: | |
name: Build and publish Python π distributions π¦ to PyPI and TestPyPI | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out Repo | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 2 # Enough to compute the diff for the current 'push' | |
- name: Check for Version Change | |
id: version | |
run: | | |
if [ -n "$(git cat-file -p HEAD | grep ^parent | cut -d' ' -f2 | xargs git diff | grep '^+version =')" ]; then | |
echo "version_changed=true" >> "$GITHUB_OUTPUT" | |
else | |
echo "version_changed=false" >> "$GITHUB_OUTPUT" | |
fi | |
- name: Set up Python | |
if: steps.version.outputs.version_changed == 'true' | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.x" | |
- name: Install pypa/build | |
if: steps.version.outputs.version_changed == 'true' | |
run: >- | |
python3 -m | |
pip install | |
build | |
--user | |
- name: Build a binary wheel and a source tarball | |
if: steps.version.outputs.version_changed == 'true' | |
run: >- | |
cat pyproject.toml ; | |
python3 -m | |
build | |
--sdist | |
--wheel | |
--outdir dist/ | |
. | |
- name: Publish distribution π¦ to Test PyPI | |
if: steps.version.outputs.version_changed == 'true' | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
password: ${{ secrets.TEST_PYPI_API_TOKEN }} | |
repository-url: https://test.pypi.org/legacy/ | |
- name: Publish distribution π¦ to PyPI | |
if: steps.version.outputs.version_changed == 'true' | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
password: ${{ secrets.PYPI_API_TOKEN }} |