Update README.md #12
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: Release | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.11' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install setuptools wheel semver | |
- name: Get current version | |
id: get_version | |
run: | | |
echo "CURRENT_VERSION=$(python setup.py --version)" >> $GITHUB_ENV | |
- name: Bump version | |
id: bump_version | |
run: | | |
CURRENT_VERSION=$(python setup.py --version) | |
echo "Current version: $CURRENT_VERSION" | |
# Increment version based on the commit message | |
# Commit message should contain [major], [minor], or [patch] to indicate the version bump | |
if [[ "${{ github.event.head_commit.message }}" == *"[major]"* ]]; then | |
NEW_VERSION=$(python -c "import semver; print(semver.VersionInfo.parse('$CURRENT_VERSION').bump_major())") | |
elif [[ "${{ github.event.head_commit.message }}" == *"[minor]"* ]]; then | |
NEW_VERSION=$(python -c "import semver; print(semver.VersionInfo.parse('$CURRENT_VERSION').bump_minor())") | |
else | |
NEW_VERSION=$(python -c "import semver; print(semver.VersionInfo.parse('$CURRENT_VERSION').bump_patch())") | |
fi | |
echo "New version: $NEW_VERSION" | |
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV | |
# Update setup.py with the new version | |
sed -i "s/version='$CURRENT_VERSION'/version='$NEW_VERSION'/" setup.py | |
# Commit the version bump | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
git add setup.py | |
git commit -m "Bump version to $NEW_VERSION" | |
- name: Push changes | |
run: git push origin main | |
- name: Create and push tag | |
run: | | |
git tag "v${{ env.NEW_VERSION }}" | |
git push origin "v${{ env.NEW_VERSION }}" | |
- name: Build package | |
run: | | |
python setup.py sdist bdist_wheel | |
ls dist | |
pypi-publish: | |
name: Upload release to PyPI | |
runs-on: ubuntu-latest | |
environment: release | |
permissions: | |
id-token: write | |
needs: release | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.11' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install setuptools wheel | |
- name: Retrieve the distributions | |
run: | | |
python setup.py sdist bdist_wheel | |
- name: Publish package distributions to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
user: "__token__" | |
password: ${{ secrets.PYPI_API_TOKEN }} |