refactor: consolidate version extraction logic and update workflow validation

Extracted version extraction logic from workflows into a centralized script for better reusability and consistency. Updated validation output naming for clarity.

Changes:
- Add extract_version.sh for centralized version extraction
- Remove update_version.sh (functionality integrated into workflows)
- Update validate_semver.sh output: release_type → is_prerelease
- Refactor docker-release.yml to use extract_version.sh
- Refactor github-release.yml to use centralized scripts
- Add version duplication check in version-release.yml

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
github-actions[bot]
2025-10-27 10:56:33 +11:00
parent f972a9507e
commit 08dab4ca6b
6 changed files with 87 additions and 229 deletions

View File

@@ -24,31 +24,13 @@ jobs:
- name: Extract version from branch and version.py
id: extract
run: |
# Extract version from branch name (release/1.2.3 -> 1.2.3)
BRANCH_VERSION="${GITHUB_REF#refs/heads/release/}"
echo "Branch version: $BRANCH_VERSION"
# Extract version from branch name and validate against version.py
.github/scripts/extract_version.sh "${{ github.ref }}"
# Read version from version.py
FILE_VERSION=$(grep -oP '__version__ = "\K[^"]+' src/version.py)
echo "File version: $FILE_VERSION"
# Verify they match
if [ "$BRANCH_VERSION" != "$FILE_VERSION" ]; then
echo "Error: Branch version ($BRANCH_VERSION) does not match version.py ($FILE_VERSION)"
exit 1
fi
VERSION="$BRANCH_VERSION"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
# Check if pre-release (contains hyphen)
if echo "$VERSION" | grep -q '-'; then
echo "is_prerelease=true" >> "$GITHUB_OUTPUT"
echo "Detected pre-release version: $VERSION"
else
echo "is_prerelease=false" >> "$GITHUB_OUTPUT"
echo "Detected stable release version: $VERSION"
fi
- name: Validate version format
run: |
# Validate version is proper SemVer and set prerelease flag
.github/scripts/validate_semver.sh "${{ steps.extract.outputs.version }}"
docker-build:
name: Build & Push Docker Images

View File

@@ -29,32 +29,11 @@ jobs:
- name: Extract version from branch
id: extract
run: |
# Extract version from branch name (release/1.2.3 -> 1.2.3)
BRANCH_NAME="${{ github.event.workflow_run.head_branch }}"
VERSION="${BRANCH_NAME#release/}"
echo "Branch version: $VERSION"
run: .github/scripts/extract_version.sh "${{ github.event.workflow_run.head_branch }}"
# Read version from version.py
FILE_VERSION=$(grep -oP '__version__ = "\K[^"]+' src/version.py)
echo "File version: $FILE_VERSION"
# Verify they match
if [ "$VERSION" != "$FILE_VERSION" ]; then
echo "Error: Branch version ($VERSION) does not match version.py ($FILE_VERSION)"
exit 1
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
# Check if pre-release (contains hyphen)
if echo "$VERSION" | grep -q '-'; then
echo "is_prerelease=true" >> "$GITHUB_OUTPUT"
echo "Detected pre-release version: $VERSION"
else
echo "is_prerelease=false" >> "$GITHUB_OUTPUT"
echo "Detected stable release version: $VERSION"
fi
- name: Validate version format
id: validate
run: .github/scripts/validate_semver.sh "${{ steps.extract.outputs.version }}"
- name: Extract release notes
id: release-notes
@@ -66,5 +45,5 @@ jobs:
tag_name: v${{ steps.extract.outputs.version }}
name: Release ${{ steps.extract.outputs.version }}
body_path: release_notes.md
prerelease: ${{ steps.extract.outputs.is_prerelease }}
prerelease: ${{ steps.validate.outputs.is_prerelease }}
draft: false

View File

@@ -26,10 +26,18 @@ jobs:
with:
token: ${{ secrets.PUBLISHER_TOKEN }}
- name: Configure Git
- name: Validate version format
id: validate
run: .github/scripts/validate_semver.sh "${{ github.event.inputs.version }}"
- name: Check if input version
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
CURRENT_VERSION=$(grep -oP '(?<=__version__ = ")[^"]+' src/version.py)
INPUT_VERSION="${{ github.event.inputs.version }}"
if [ "$CURRENT_VERSION" = "$INPUT_VERSION" ]; then
echo "Error: Input version '$INPUT_VERSION' is the same as the current version"
exit 1
fi
- name: Check if branch exists
run: |
@@ -45,7 +53,11 @@ jobs:
- name: Create release branch and update version
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
VERSION="${{ steps.validate.outputs.version }}"
# Update version.py
mv -f src/version.py src/last_version.py
echo "__version__ = \"$VERSION\"" > src/version.py