- update to correct version #14
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
# This workflow will upload a Python Package using Twine when a release is created | |
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries | |
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
name: Upload Python Package | |
on: | |
push: | |
branches: | |
- main | |
release: | |
types: [published] | |
permissions: | |
contents: write | |
jobs: | |
create-release: | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up Python | |
uses: actions/setup-python@v3 | |
with: | |
python-version: '3.x' | |
- name: Update version | |
id: update_version | |
run: | | |
# Read current version | |
CURRENT_VERSION=$(cat version.txt) | |
echo "Current version: $CURRENT_VERSION" | |
# Split version into parts | |
IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION" | |
MAJOR="${VERSION_PARTS[0]}" | |
MINOR="${VERSION_PARTS[1]}" | |
PATCH="${VERSION_PARTS[2]}" | |
# Increment patch version | |
NEW_PATCH=$((PATCH + 1)) | |
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH" | |
echo "New version: $NEW_VERSION" | |
# Update version.txt with new version | |
echo "$NEW_VERSION" > version.txt | |
# Set output for later steps | |
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
- name: Commit version update | |
run: | | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
git add version.txt | |
git commit -m "Bump version to ${{ steps.update_version.outputs.version }}" | |
git push | |
- name: Create Release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: v${{ steps.update_version.outputs.version }} | |
release_name: Release v${{ steps.update_version.outputs.version }} | |
draft: false | |
prerelease: false | |
deploy: | |
runs-on: ubuntu-latest | |
needs: [create-release] | |
if: github.event_name == 'push' || github.event_name == 'release' | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: main | |
- name: Set up Python | |
uses: actions/setup-python@v3 | |
with: | |
python-version: '3.x' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install build | |
- name: Build package | |
run: python -m build | |
- name: Publish package | |
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 | |
with: | |
user: __token__ | |
password: ${{ secrets.PYPI_API_TOKEN }} |