Skip to content

Official Release and Publish #4

Official Release and Publish

Official Release and Publish #4

Workflow file for this run

# File: .github/workflows/release-and-publish.yml
name: Official Release and Publish
on:
workflow_dispatch:
inputs:
version_increment:
description: 'Version to increment (patch/minor/major)'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
jobs:
release-and-publish:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install semver build
# Determine the new version based on the current version and the selected increment
- name: Determine new version
id: version
run: |
current_version=$(grep -oP "__version__\s*=\s*['\"]?\K[^'\"']+" uniclip/__init__.py || echo "0.0.0")
echo "Current version: $current_version"
# Use semver to increment the version
if [ "${{ github.event.inputs.version_increment }}" == "major" ]; then
new_version=$(python -c "import semver; print(semver.VersionInfo.parse('$current_version').bump_major())")
elif [ "${{ github.event.inputs.version_increment }}" == "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" >> "$GITHUB_OUTPUT"
echo "New version: $new_version"
# Update the version in __init__.py
- name: Update version
run: |
sed -i "s/__version__\s*=\s*['\"].*['\"]/__version__ = '${{ steps.version.outputs.new_version }}'/" uniclip/__init__.py
# Commit the version update
- name: Commit version update
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add uniclip/__init__.py
git commit -m "Bump version to ${{ steps.version.outputs.new_version }}"
# Push the changes
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
# Create the official release
- name: Create Official Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.version.outputs.new_version }}
release_name: Release ${{ steps.version.outputs.new_version }}
draft: false
prerelease: false
# Update README
- name: Update README
run: |
sed -i "s/Current version: .*/Current version: ${{ steps.version.outputs.new_version }}/" README.md
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add README.md
git commit -m "Update version in README to ${{ steps.version.outputs.new_version }}"
git push
# Build the package
- name: Build package
run: python -m build
# Publish the package to PyPI
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
# Debug information
- name: Debug information
run: |
echo "GitHub Ref: ${{ github.ref }}"
echo "GitHub Event Name: ${{ github.event_name }}"
echo "Release Tag: v${{ steps.version.outputs.new_version }}"