Skip to content

Commit

Permalink
Merge pull request #4 from renxida/better-versioning
Browse files Browse the repository at this point in the history
Streamline CI/CD Workflows and Improve Version Management
  • Loading branch information
renxida authored Jun 28, 2024
2 parents fb260f1 + 5616ecf commit dbccaa2
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ jobs:
python -m pip install --upgrade pip
pip install semver
# Determine the current release version and create the nightly version
- name: Determine nightly version
id: version
run: |
# Get the current version from __init__.py
current_version=$(grep -oP "__version__\s*=\s*['\"]?\K[^'\"']+" uniclip/__init__.py || echo "0.0.0")
IFS='.' read -r major minor patch <<< "$current_version"
prerelease=$(echo "$patch" | grep -oP '[-+].*$' || echo "")
patch=$(echo "$patch" | grep -oP '^\d+' || echo "0")
nightly_version="${major}.${minor}.${patch}-nightly.${GITHUB_RUN_NUMBER}${prerelease}"
echo "nightly_version=$nightly_version" >> "$GITHUB_OUTPUT"
echo "Current version: $current_version"
# Create the nightly version: current_version+nightly.GITHUB_RUN_NUMBER
nightly_version="${current_version}+nightly.${GITHUB_RUN_NUMBER}"
echo "nightly_version=$nightly_version" >> "$GITHUB_OUTPUT"
echo "Nightly version: $nightly_version"
- name: Create Nightly Release
Expand All @@ -47,4 +48,4 @@ jobs:
tag_name: nightly-v${{ steps.version.outputs.nightly_version }}
release_name: Nightly Release ${{ steps.version.outputs.nightly_version }}
draft: false
prerelease: true
prerelease: true
101 changes: 89 additions & 12 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,113 @@
# File: .github/workflows/publish.yml
# File: .github/workflows/release-and-publish.yml

name: Official Release and Publish

name: Publish Python Package
on:
release:
types: [published]
tags:
- 'v*.*.*' # This ensures it only runs on official release tags
workflow_dispatch:
inputs:
version_increment:
description: 'Version to increment (patch/minor/major)'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major

jobs:
deploy:
release-and-publish:
runs-on: ubuntu-latest
permissions:
contents: read
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 build
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 "action@github.com"
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 "action@github.com"
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
- name: List distribution files
run: ls -l dist/

# 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: ${{ github.event.release.tag_name }}"
echo "Release Tag: v${{ steps.version.outputs.new_version }}"
73 changes: 0 additions & 73 deletions .github/workflows/release.yml

This file was deleted.

0 comments on commit dbccaa2

Please sign in to comment.