diff --git a/.github/workflows/nightly-release.yml b/.github/workflows/nightly.yml similarity index 79% rename from .github/workflows/nightly-release.yml rename to .github/workflows/nightly.yml index 187360e..fb5dc7c 100644 --- a/.github/workflows/nightly-release.yml +++ b/.github/workflows/nightly.yml @@ -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 @@ -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 \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1996a74..aa8128e 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -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 }}" \ No newline at end of file + echo "Release Tag: v${{ steps.version.outputs.new_version }}" \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 29e4c8e..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,73 +0,0 @@ -# File: .github/workflows/release.yml - -name: Official Release -on: - workflow_dispatch: # This allows manual triggering without inputs - -jobs: - official-release: - runs-on: ubuntu-latest - 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 - - - name: Get latest nightly release - id: latest_nightly - run: | - latest_nightly=$(git describe --tags --match "nightly-v*" --abbrev=0) - echo "latest_nightly=$latest_nightly" >> "$GITHUB_OUTPUT" - - - name: Determine official version - id: version - run: | - nightly_version="${{ steps.latest_nightly.outputs.latest_nightly }}" - official_version=$(echo $nightly_version | sed 's/nightly-v//' | sed 's/-nightly\..*//') - echo "official_version=$official_version" >> "$GITHUB_OUTPUT" - - - name: Update version - run: | - sed -i "s/__version__\s*=\s*['\"].*['\"]/__version__ = '${{ steps.version.outputs.official_version }}'/" uniclip/__init__.py - - - 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.official_version }}" - - - name: Push changes - uses: ad-m/github-push-action@master - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - branch: ${{ github.ref }} - - - 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.official_version }} - release_name: Release ${{ steps.version.outputs.official_version }} - draft: false - prerelease: false - - - name: Update README - run: | - sed -i "s/Current version: .*/Current version: ${{ steps.version.outputs.official_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.official_version }}" - git push \ No newline at end of file