jimaku-dl/.gitea/workflows/create-release.yml
sudacode ad11faf1b0
Some checks failed
Tests / test (ubuntu-latest, 3.8) (push) Failing after 24m2s
Tests / test (ubuntu-latest, 3.10) (push) Failing after 24m4s
Tests / test (ubuntu-latest, 3.9) (push) Failing after 10m52s
Tests / test (macos-latest, 3.10) (push) Has been cancelled
Tests / test (macos-latest, 3.8) (push) Has been cancelled
Tests / test (macos-latest, 3.9) (push) Has been cancelled
Tests / test (windows-latest, 3.10) (push) Has been cancelled
Tests / test (windows-latest, 3.8) (push) Has been cancelled
Tests / test (windows-latest, 3.9) (push) Has been cancelled
update
2025-03-08 23:52:40 -08:00

141 lines
4.5 KiB
YAML

name: Create Release and Publish
on:
workflow_dispatch:
inputs:
version_bump:
description: "Type of version bump"
required: true
default: "patch"
type: choice
options:
- patch
- minor
- major
custom_version:
description: "Custom version (if specified, ignores version_bump)"
required: false
push:
tags:
- "v*.*.*"
jobs:
create-release:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Check out code
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 setuptools wheel semver
- name: Determine current version
id: current_version
run: |
CURRENT_VERSION=$(grep -E "__version__\s*=\s*['\"]([^'\"]+)['\"]" src/jimaku_dl/cli.py | cut -d'"' -f2)
echo "Current version: $CURRENT_VERSION"
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
- name: Calculate new version
id: new_version
run: |
if [ -n "${{ github.event.inputs.custom_version }}" ]; then
NEW_VERSION="${{ github.event.inputs.custom_version }}"
echo "Using custom version: $NEW_VERSION"
else
BUMP_TYPE="${{ github.event.inputs.version_bump }}"
CURRENT="${{ env.CURRENT_VERSION }}"
if [ "$BUMP_TYPE" = "patch" ]; then
MAJOR=$(echo $CURRENT | cut -d. -f1)
MINOR=$(echo $CURRENT | cut -d. -f2)
PATCH=$(echo $CURRENT | cut -d. -f3)
NEW_PATCH=$((PATCH + 1))
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
elif [ "$BUMP_TYPE" = "minor" ]; then
MAJOR=$(echo $CURRENT | cut -d. -f1)
MINOR=$(echo $CURRENT | cut -d. -f2)
NEW_MINOR=$((MINOR + 1))
NEW_VERSION="$MAJOR.$NEW_MINOR.0"
elif [ "$BUMP_TYPE" = "major" ]; then
MAJOR=$(echo $CURRENT | cut -d. -f1)
NEW_MAJOR=$((MAJOR + 1))
NEW_VERSION="$NEW_MAJOR.0.0"
else
echo "Invalid bump type: $BUMP_TYPE"
exit 1
fi
echo "Bumping $BUMP_TYPE version: $CURRENT → $NEW_VERSION"
fi
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
- name: Update version in files
run: |
# Update version in cli.py instead of __init__.py
sed -i "s/__version__ = \"${{ env.CURRENT_VERSION }}\"/__version__ = \"${{ env.NEW_VERSION }}\"/g" src/jimaku_dl/cli.py
# Still update setup.cfg if it exists
if [ -f "setup.cfg" ]; then
sed -i "s/version = ${{ env.CURRENT_VERSION }}/version = ${{ env.NEW_VERSION }}/g" setup.cfg
fi
echo "Updated version to ${{ env.NEW_VERSION }} in code files"
- name: Generate changelog
id: changelog
run: |
PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$PREV_TAG" ]; then
CHANGELOG=$(git log --pretty=format:"* %s (%h)" --no-merges)
else
CHANGELOG=$(git log $PREV_TAG..HEAD --pretty=format:"* %s (%h)" --no-merges)
fi
if [ -z "$CHANGELOG" ]; then
CHANGELOG="* Bug fixes and improvements"
fi
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Commit version changes
run: |
git config --local user.email "action@gitea.suda.codes"
git config --local user.name "Gitea Action"
git add src/jimaku_dl/cli.py
if [ -f "setup.cfg" ]; then
git add setup.cfg
fi
git commit -m "Bump version to ${{ env.NEW_VERSION }}"
git tag -a "v${{ env.NEW_VERSION }}" -m "Release v${{ env.NEW_VERSION }}"
git push --follow-tags
- name: Create Gitea Release
id: create_release
uses: softprops/action-gh-release@v1
with:
tag_name: "v${{ env.NEW_VERSION }}"
name: "Release v${{ env.NEW_VERSION }}"
body: |
## Changes in this release
${{ steps.changelog.outputs.CHANGELOG }}
draft: false
prerelease: false
token: ${{ secrets.ACCESS_KEY }}