Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 97 additions & 48 deletions .github/workflows/version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@ name: version management
on:
workflow_dispatch:
inputs:
release_level:
bump:
type: choice
description: Release level (none, patch, minor, major)
description: Version bump
required: true
options: [none, patch, minor, major]
prerelease:
stage:
type: choice
description: Whether it's a prerelease
description: Release stage
required: true
options: [alpha, beta, rc, release]
local:
type: string
required: false
description: "Local metadata (alpha only)"

permissions:
contents: write
Expand All @@ -27,74 +23,129 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Validate version bump inputs
run: |
BUMP="${{ github.event.inputs.bump }}"
STAGE="${{ github.event.inputs.stage }}"

if [ "$BUMP" = "none" ] && [ "$STAGE" != "release" ]; then
echo "Invalid input: prerelease stage '$STAGE' requires a version bump"
exit 1
fi

- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup project
uses: ./.github/actions/project-setup

- name: Install cargo-goose
run: cargo install cargo-goose

- name: Get current version
id: current_version
run: |
echo "version=$(cat pyproject.toml | grep '^version = ".*"' | cut -d'"' -f2)" >> $GITHUB_OUTPUT
VERSION=$(cargo metadata --no-deps --format-version=1 \
| jq -r '.packages[]
| select(.name == "encoderfile-core")
| .version')

- name: Setup project
uses: ./.github/actions/project-setup
[ -n "$VERSION" ] || { echo "encoderfile-core not found"; exit 1; }

echo "version=$VERSION" >> "$GITHUB_OUTPUT"

- name: Compute prerelease metadata
id: prerelease_meta
run: |
echo "meta=$(git rev-parse --short=7 HEAD)" >> "$GITHUB_OUTPUT"

- name: Bump version
id: bump
run: |
NEW_VERSION=$(uv run scripts/bump_version.py \
"${{ github.event.inputs.release_level }}" \
"${{ github.event.inputs.prerelease }}" \
--local "${{ github.event.inputs.local }}" \
--start ".")

echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT

BUMP="${{ github.event.inputs.bump }}"
STAGE="${{ github.event.inputs.stage }}"
META="${{ steps.prerelease_meta.outputs.meta }}"

if [ "$BUMP" != "none" ]; then
if [ "$STAGE" = "release" ]; then
cargo goose bump version "$BUMP"
else
cargo goose bump version "$BUMP" "$STAGE"
fi
else
case "$STAGE" in
alpha|beta|rc)
cargo goose bump prerelease "$STAGE"
;;
release)
cargo goose bump release
;;
*)
echo "Invalid stage: $STAGE"
exit 1
;;
esac
fi

- name: Get new version
id: new_version
run: |
VERSION=$(cargo metadata --no-deps --format-version=1 \
| jq -r '.packages[]
| select(.name == "encoderfile-core")
| .version')

[ -n "$VERSION" ] || { echo "encoderfile-core not found"; exit 1; }

echo "version=$VERSION" >> "$GITHUB_OUTPUT"

- name: Abort if version did not change
run: |
if [ "${{ steps.current_version.outputs.version }}" = "${{ steps.new_version.outputs.version }}" ]; then
echo "Version did not change; aborting"
exit 1
fi

- name: Update Cargo.lock
run: cargo update encoderfile-core encoderfile --precise ${{ steps.bump.outputs.version }}

- name: Update uv.lock
run: uv lock
run: cargo generate-lockfile

# Generate appropriate labels based on release type
- name: Generate PR labels
id: generate_labels
run: |
BUMP="${{ github.event.inputs.bump }}"
STAGE="${{ github.event.inputs.stage }}"

LABELS="auto-generated\nversion-bump"

RELEASE_LEVEL="${{ github.event.inputs.release_level }}"
PRERELEASE="${{ github.event.inputs.prerelease }}"
[ "$BUMP" != "none" ] && LABELS="$LABELS\n$BUMP"

# Add the base release level (patch/minor/major)
if [ "$RELEASE_LEVEL" != "none" ]; then
LABELS="$LABELS\n$RELEASE_LEVEL"
fi
case "$STAGE" in
alpha|beta|rc)
LABELS="$LABELS\n$STAGE\nprerelease"
;;
release)
LABELS="$LABELS\nrelease"
;;
esac

# Add prerelease label if appropriate
if [ "$PRERELEASE" != "release" ]; then
LABELS="$LABELS\n$PRERELEASE\nprerelease"
else
LABELS="$LABELS\nrelease"
fi

echo "labels<<EOF" >> $GITHUB_OUTPUT
echo -e "$LABELS" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "labels<<EOF" >> "$GITHUB_OUTPUT"
echo -e "$LABELS" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"

- name: Create Pull Request
id: create_pr
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "version: bump version 🚀 ${{ steps.bump.outputs.version }}"
title: "version: Version Bump 🚀 ${{ steps.bump.outputs.version }}"
commit-message: "version: bump version 🚀 ${{ steps.new_version.outputs.version }}"
title: "version: Version Bump 🚀 ${{ steps.new_version.outputs.version }}"
body: |
## 🎉 Version Bump 🎉

This PR bumps the version from ${{ steps.current_version.outputs.version }} to ${{ steps.bump.outputs.version }}.
Version bumped from ${{ steps.current_version.outputs.version }}
to ${{ steps.new_version.outputs.version }}.

### 🔄 Changes
- 📝 Updated version in pyproject.toml
- 📝 Updated version in Cargo.toml
- 🔒 Updated Cargo.lock

✨ This PR was automatically generated by the Version Management workflow ✨
Expand All @@ -104,8 +155,6 @@ jobs:
base: main
delete-branch: true
add-paths: |
pyproject.toml
Cargo.lock
uv.lock
**/Cargo.toml
labels: ${{ steps.generate_labels.outputs.labels }}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.3.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13"
dependencies = [ "pip>=25.2", "protobuf>=6.33.0", "pydantic>=2.12.4", "toml>=0.10.2",]
dependencies = [ "pip>=25.2", "protobuf>=6.33.0"]

[dependency-groups]
dev = [ "pre-commit>=4.3.0", "ruff>=0.14.2",]
Expand Down
188 changes: 0 additions & 188 deletions scripts/bump_version.py

This file was deleted.

Loading
Loading