-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from renxida/better-versioning
Streamline CI/CD Workflows and Improve Version Management
- Loading branch information
Showing
3 changed files
with
96 additions
and
91 deletions.
There are no files selected for viewing
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 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
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 }}" |
This file was deleted.
Oops, something went wrong.