From f972a9507e8c1acc330889f62a607c1fe8d8cfe8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 26 Oct 2025 21:34:50 +1100 Subject: [PATCH] refactor: streamline release workflows and extract validation to scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Simplify github-release workflow by removing auto-generation and linting steps - Extract SemVer validation from inline workflow to dedicated script - Add production environment protection to version-release workflow - Create reusable validation and update scripts in .github/scripts/ - Update release notes for v1.1.1 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .github/scripts/update_version.sh | 174 ++++++++++++++++++++++++++ .github/scripts/validate_semver.sh | 71 +++++++++++ .github/workflows/github-release.yml | 11 +- .github/workflows/version-release.yml | 24 +--- RELEASE_NOTES.md | 10 +- 5 files changed, 255 insertions(+), 35 deletions(-) create mode 100755 .github/scripts/update_version.sh create mode 100755 .github/scripts/validate_semver.sh diff --git a/.github/scripts/update_version.sh b/.github/scripts/update_version.sh new file mode 100755 index 0000000..0cc9730 --- /dev/null +++ b/.github/scripts/update_version.sh @@ -0,0 +1,174 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Script: update_version.sh +# Description: Updates project version, creates release branch and tag +# Usage: update_version.sh [--skip-push] + +# Color codes for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Script directory +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" + +# Display usage information +usage() { + echo "Usage: $0 [--skip-push]" + echo "" + echo "Updates the project version, creates a release branch, and creates a git tag." + echo "" + echo "Arguments:" + echo " Version string in SemVer format (e.g., 1.2.3, 2.0.0-rc.1)" + echo "" + echo "Options:" + echo " --skip-push Skip pushing changes to remote (useful for local testing)" + echo "" + echo "Examples:" + echo " $0 1.2.3" + echo " $0 2.0.0-rc.1" + echo " $0 1.0.0-beta --skip-push" + exit 1 +} + +# Check if version argument is provided +if [ $# -eq 0 ]; then + echo -e "${RED}Error: No version specified${NC}" + usage +fi + +VERSION="$1" +SKIP_PUSH=false + +# Parse optional flags +shift +while [ $# -gt 0 ]; do + case "$1" in + --skip-push) + SKIP_PUSH=true + shift + ;; + *) + echo -e "${RED}Error: Unknown option: $1${NC}" + usage + ;; + esac +done + +# Validate version format using validate_semver.sh +echo -e "${BLUE}Validating version format...${NC}" +if ! "$SCRIPT_DIR/validate_semver.sh" "$VERSION" > /dev/null; then + echo -e "${RED}Version validation failed${NC}" + exit 1 +fi + +# Determine current branch +CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) +RELEASE_BRANCH="release/$VERSION" + +echo -e "${BLUE}Current branch: $CURRENT_BRANCH${NC}" +echo -e "${BLUE}Target release branch: $RELEASE_BRANCH${NC}" + +# Check if release branch already exists +if git show-ref --verify --quiet "refs/heads/$RELEASE_BRANCH"; then + echo -e "${RED}Error: Branch '$RELEASE_BRANCH' already exists locally${NC}" + exit 1 +fi + +# Check if remote branch exists (if we're not skipping push) +if [ "$SKIP_PUSH" = false ]; then + if git ls-remote --heads origin "$RELEASE_BRANCH" | grep -q "$RELEASE_BRANCH"; then + echo -e "${RED}Error: Branch '$RELEASE_BRANCH' already exists on remote${NC}" + exit 1 + fi +fi + +# Check if tag already exists +if git rev-parse "v$VERSION" >/dev/null 2>&1; then + echo -e "${RED}Error: Tag 'v$VERSION' already exists${NC}" + exit 1 +fi + +# Update version.py +echo -e "${BLUE}Updating version.py...${NC}" +VERSION_FILE="$PROJECT_ROOT/src/version.py" + +if [ ! -f "$VERSION_FILE" ]; then + echo -e "${RED}Error: Version file not found: $VERSION_FILE${NC}" + exit 1 +fi + +# Backup old version +BACKUP_FILE="$PROJECT_ROOT/src/last_version.py" +mv -f "$VERSION_FILE" "$BACKUP_FILE" + +# Write new version +echo "__version__ = \"$VERSION\"" > "$VERSION_FILE" + +echo -e "${GREEN}✓ Updated version to $VERSION${NC}" + +# Commit version change +echo -e "${BLUE}Committing version change...${NC}" +git add "$VERSION_FILE" +git commit -m "chore: bump version to $VERSION" + +if [ "$SKIP_PUSH" = false ]; then + echo -e "${BLUE}Pushing to current branch ($CURRENT_BRANCH)...${NC}" + git push origin "$CURRENT_BRANCH" + echo -e "${GREEN}✓ Pushed version update to $CURRENT_BRANCH${NC}" +else + echo -e "${YELLOW}⊘ Skipping push to current branch${NC}" +fi + +# Create release branch +echo -e "${BLUE}Creating release branch '$RELEASE_BRANCH'...${NC}" +git checkout -b "$RELEASE_BRANCH" +echo -e "${GREEN}✓ Created branch '$RELEASE_BRANCH'${NC}" + +# Push release branch +if [ "$SKIP_PUSH" = false ]; then + echo -e "${BLUE}Pushing release branch...${NC}" + git push origin "$RELEASE_BRANCH" + echo -e "${GREEN}✓ Pushed branch '$RELEASE_BRANCH'${NC}" +else + echo -e "${YELLOW}⊘ Skipping push of release branch${NC}" +fi + +# Create tag +echo -e "${BLUE}Creating tag 'v$VERSION'...${NC}" +git tag "v$VERSION" +echo -e "${GREEN}✓ Created tag 'v$VERSION'${NC}" + +# Push tag +if [ "$SKIP_PUSH" = false ]; then + echo -e "${BLUE}Pushing tag...${NC}" + git push origin "v$VERSION" + echo -e "${GREEN}✓ Pushed tag 'v$VERSION'${NC}" +else + echo -e "${YELLOW}⊘ Skipping push of tag${NC}" +fi + +# Summary +echo "" +echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" +echo -e "${GREEN}✅ Version update completed successfully!${NC}" +echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" +echo -e "${GREEN} Version: $VERSION${NC}" +echo -e "${GREEN} Branch: $RELEASE_BRANCH${NC}" +echo -e "${GREEN} Tag: v$VERSION${NC}" + +if [ "$SKIP_PUSH" = false ]; then + echo -e "${GREEN} Remote status: Pushed${NC}" + echo "" + echo -e "${BLUE}The publish workflow should now build Docker images and create the GitHub release.${NC}" +else + echo -e "${YELLOW} Remote status: Not pushed (--skip-push)${NC}" + echo "" + echo -e "${YELLOW}Note: Changes are only local. Push manually when ready.${NC}" +fi + +exit 0 diff --git a/.github/scripts/validate_semver.sh b/.github/scripts/validate_semver.sh new file mode 100755 index 0000000..0dfa67f --- /dev/null +++ b/.github/scripts/validate_semver.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Script: validate_semver.sh +# Description: Validates version strings against SemVer specification +# Usage: validate_semver.sh + +# Color codes for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +NC='\033[0m' # No Color + +# Display usage information +usage() { + echo "Usage: $0 " + echo "" + echo "Validates a version string against SemVer specification." + echo "" + echo "Examples:" + echo " $0 1.2.3" + echo " $0 2.0.0-rc.1" + echo " $0 1.0.0-beta.2+build.123" + exit 1 +} + +# Check if version argument is provided +if [ $# -eq 0 ]; then + echo -e "${RED}Error: No version specified${NC}" + usage +fi + +VERSION="$1" + +# SemVer regex from https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string +SEMVER_REGEX='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$' + +# Validate version format +if ! echo "$VERSION" | grep -Pq "$SEMVER_REGEX"; then + echo -e "${RED}Error: Version '$VERSION' is not valid SemVer format${NC}" + echo "" + echo "Valid SemVer format examples:" + echo " - Stable releases: 1.2.3, 2.0.0, 10.5.8" + echo " - Pre-releases: 2.0.0-rc.1, 1.0.0-alpha, 1.0.0-beta.2" + echo " - With build metadata: 1.0.0-beta.2+build.123, 1.2.3+20130313144700" + echo "" + echo "Format: MAJOR.MINOR.PATCH[-PRERELEASE][+BUILD]" + exit 1 +fi + +# Determine release type +if echo "$VERSION" | grep -q '-'; then + echo -e "${YELLOW}✓ Detected pre-release version: $VERSION${NC}" + echo "type=prerelease" +else + echo -e "${GREEN}✓ Detected stable release version: $VERSION${NC}" + echo "type=stable" +fi + +# Output version for GitHub Actions if GITHUB_OUTPUT is set +if [ -n "${GITHUB_OUTPUT:-}" ]; then + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + + if echo "$VERSION" | grep -q '-'; then + echo "release_type=prerelease" >> "$GITHUB_OUTPUT" + else + echo "release_type=stable" >> "$GITHUB_OUTPUT" + fi +fi + +exit 0 diff --git a/.github/workflows/github-release.yml b/.github/workflows/github-release.yml index a306b48..2b00230 100644 --- a/.github/workflows/github-release.yml +++ b/.github/workflows/github-release.yml @@ -56,16 +56,7 @@ jobs: echo "Detected stable release version: $VERSION" fi - - name: Auto-generate release notes if missing - run: .github/scripts/generate_release_notes.sh -v "${{ steps.extract.outputs.version }}" -k "${{ secrets.GEMINI_API_KEY }}" -p - - - uses: DavidAnson/markdownlint-cli2-action@v20 - with: - fix: true - globs: '**/*.md' - continue-on-error: true - - - name: Generate release notes + - name: Extract release notes id: release-notes run: .github/scripts/extract_release_notes.sh "${{ steps.extract.outputs.version }}" diff --git a/.github/workflows/version-release.yml b/.github/workflows/version-release.yml index e574bd9..b15911e 100644 --- a/.github/workflows/version-release.yml +++ b/.github/workflows/version-release.yml @@ -18,31 +18,9 @@ jobs: create-release-branch: name: Create Release Branch runs-on: ubuntu-latest + environment: prod steps: - - name: Validate SemVer format - id: validate - run: | - VERSION="${{ github.event.inputs.version }}" - - # SemVer regex: https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string - SEMVER_REGEX='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$' - - if ! echo "$VERSION" | grep -Pq "$SEMVER_REGEX"; then - echo "Error: Version '$VERSION' is not valid SemVer format" - echo "Examples: 1.2.3, 2.0.0-rc.1, 1.0.0-beta.2+build.123" - exit 1 - fi - - echo "version=$VERSION" >> "$GITHUB_OUTPUT" - - # Check if pre-release (contains hyphen) - if echo "$VERSION" | grep -q '-'; then - echo "Detected pre-release version: $VERSION" - else - echo "Detected stable release version: $VERSION" - fi - - name: Checkout code uses: actions/checkout@v5 with: diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 8378629..3d59f80 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,6 +1,8 @@ -# Release Notes - v1.1.0 +# Release Notes - v1.1.1 -We're excited to roll out v1.1.0, a major update focused entirely on making Twitch Drops Miner accessible to users around the globe by introducing comprehensive internationalization (i18n) support and dynamic language switching. This release also brings crucial bug fixes for stability and cleaner code under the hood. +We're excited to roll out v1.1.1, a major update focused entirely on making Twitch Drops Miner accessible to users around the globe by introducing comprehensive internationalization (i18n) support and dynamic language switching. This release also brings crucial bug fixes for stability and cleaner code under the hood. + +## For 1.1.0 ### 🌍 Global Language Support (i18n) @@ -24,3 +26,7 @@ While these changes are mostly internal, they result in a faster, more stable ap - **Modernized Translation Engine**: We completely refactored the internal translation system (Translator class) to be faster, cleaner, and easier to maintain. - **Client Code Cleanup**: Removed unused or legacy code components, including the `ReloadRequest` exception, leading to a lighter, more efficient client application. + +## For 1.1.1 + +Workflow fix and upgrade