From eb0537479767c0e5c5253adc03c6a979e98cc35e Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Wed, 17 Dec 2025 15:24:19 -0600 Subject: [PATCH] feat: add CI mode to version bump script - Add --ci flag to version-bump.sh for CI validation - CI mode runs version bump, formats files, then checks git diff - Exit 0 if no changes (versions already correct), exit 1 if changes needed - Update workflow to use --ci flag and post cleaner failure comment - Fix awk script to avoid adding extra blank lines - Run prettier on modified README files for consistent formatting --- .github/scripts/version-bump.sh | 51 ++++++++++++++++----- .github/workflows/version-bump.yaml | 71 +++++++++-------------------- 2 files changed, 62 insertions(+), 60 deletions(-) diff --git a/.github/scripts/version-bump.sh b/.github/scripts/version-bump.sh index f84a7f894..ec078fccd 100755 --- a/.github/scripts/version-bump.sh +++ b/.github/scripts/version-bump.sh @@ -1,14 +1,18 @@ #!/bin/bash # Version Bump Script -# Usage: ./version-bump.sh [base_ref] +# Usage: ./version-bump.sh [--ci] [base_ref] +# --ci: CI mode - run bump, check for changes, exit 1 if changes needed # bump_type: patch, minor, or major # base_ref: base reference for diff (default: origin/main) set -euo pipefail +CI_MODE=false + usage() { - echo "Usage: $0 [base_ref]" + echo "Usage: $0 [--ci] [base_ref]" + echo " --ci: CI mode - validates versions are already bumped (exits 1 if not)" echo " bump_type: patch, minor, or major" echo " base_ref: base reference for diff (default: origin/main)" echo "" @@ -16,6 +20,7 @@ usage() { echo " $0 patch # Update versions with patch bump" echo " $0 minor # Update versions with minor bump" echo " $0 major # Update versions with major bump" + echo " $0 --ci patch # CI check: verify patch bump has been applied" exit 1 } @@ -85,7 +90,7 @@ update_readme_version() { in_module_block = 0 if (module_has_target_source) { num_lines = split(module_content, lines, "\n") - for (i = 1; i <= num_lines; i++) { + for (i = 1; i < num_lines; i++) { line = lines[i] if (line ~ /^[[:space:]]*version[[:space:]]*=/) { match(line, /^[[:space:]]*/) @@ -115,6 +120,11 @@ update_readme_version() { } main() { + if [ "${1:-}" = "--ci" ]; then + CI_MODE=true + shift + fi + if [ $# -lt 1 ] || [ $# -gt 2 ]; then usage fi @@ -152,6 +162,8 @@ main() { local untagged_modules="" local has_changes=false + declare -a modified_readme_files=() + while IFS= read -r module_path; do if [ -z "$module_path" ]; then continue; fi @@ -202,6 +214,7 @@ main() { if update_readme_version "$readme_path" "$namespace" "$module_name" "$new_version"; then updated_readmes="$updated_readmes\n- $namespace/$module_name" + modified_readme_files+=("$readme_path") has_changes=true fi @@ -210,19 +223,22 @@ main() { done <<< "$modules" - # Always run formatter to ensure consistent formatting - echo "🔧 Running formatter to ensure consistent formatting..." - if command -v bun > /dev/null 2>&1; then - bun fmt > /dev/null 2>&1 || echo "⚠️ Warning: bun fmt failed, but continuing..." - else - echo "⚠️ Warning: bun not found, skipping formatting" + if [ ${#modified_readme_files[@]} -gt 0 ]; then + echo "🔧 Formatting modified README files..." + if command -v bun > /dev/null 2>&1; then + for readme_file in "${modified_readme_files[@]}"; do + bun run prettier --write "$readme_file" 2> /dev/null || true + done + else + echo "⚠️ Warning: bun not found, skipping formatting" + fi + echo "" fi - echo "" echo "📋 Summary:" echo "Bump Type: $bump_type" echo "" - echo "Modules Updated:" + echo "Modules Processed:" echo -e "$bumped_modules" echo "" @@ -239,6 +255,19 @@ main() { echo "" fi + if [ "$CI_MODE" = true ]; then + echo "🔍 Comparing files to committed versions..." + if git diff --quiet; then + echo "✅ PASS: All versions match - no changes needed" + exit 0 + else + echo "❌ FAIL: Module versions need to be updated" + echo "" + echo "Run './.github/scripts/version-bump.sh $bump_type' locally and commit the changes" + exit 1 + fi + fi + if [ "$has_changes" = true ]; then echo "✅ Version bump completed successfully!" echo "📝 README files have been updated with new versions." diff --git a/.github/workflows/version-bump.yaml b/.github/workflows/version-bump.yaml index 7c51d0ef0..aff9e0a14 100644 --- a/.github/workflows/version-bump.yaml +++ b/.github/workflows/version-bump.yaml @@ -55,62 +55,35 @@ jobs: ;; esac - - name: Check version bump requirements - id: version-check - run: | - output_file=$(mktemp) - if ./.github/scripts/version-bump.sh "${{ steps.bump-type.outputs.type }}" origin/main > "$output_file" 2>&1; then - echo "Script completed successfully" - else - echo "Script failed" - cat "$output_file" - exit 1 - fi - - { - echo "output<> $GITHUB_OUTPUT - - cat "$output_file" - - if git diff --quiet; then - echo "versions_up_to_date=true" >> $GITHUB_OUTPUT - echo "✅ All module versions are already up to date" - else - echo "versions_up_to_date=false" >> $GITHUB_OUTPUT - echo "❌ Module versions need to be updated" - echo "Files that would be changed:" - git diff --name-only - echo "" - echo "Diff preview:" - git diff - - git checkout . - git clean -fd - - exit 1 - fi + - name: Check version bump + run: ./.github/scripts/version-bump.sh --ci "${{ steps.bump-type.outputs.type }}" origin/main - - name: Comment on PR - Failure - if: failure() && steps.version-check.outputs.versions_up_to_date == 'false' + - name: Comment on PR - Version bump required + if: failure() uses: actions/github-script@v8 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const output = `${{ steps.version-check.outputs.output }}`; const bumpType = `${{ steps.bump-type.outputs.type }}`; - let comment = `## ❌ Version Bump Validation Failed\n\n`; - comment += `**Bump Type:** \`${bumpType}\`\n\n`; - comment += `Module versions need to be updated but haven't been bumped yet.\n\n`; - comment += `**Required Actions:**\n`; - comment += `1. Run the version bump script locally: \`./.github/scripts/version-bump.sh ${bumpType}\`\n`; - comment += `2. Commit the changes: \`git add . && git commit -m "chore: bump module versions (${bumpType})"\`\n`; - comment += `3. Push the changes: \`git push\`\n\n`; - comment += `### Script Output:\n\`\`\`\n${output}\n\`\`\`\n\n`; - comment += `> Please update the module versions and push the changes to continue.`; + const comment = [ + '## Version Bump Required', + '', + 'One or more modules in this PR need their versions updated.', + '', + '**To fix this:**', + '1. Run the version bump script locally:', + ' ```bash', + ` ./.github/scripts/version-bump.sh ${bumpType}`, + ' ```', + '2. Commit the changes:', + ' ```bash', + ` git add . && git commit -m "chore: bump module versions (${bumpType})"`, + ' ```', + '3. Push your changes', + '', + 'The CI will automatically re-run once you push the updated versions.' + ].join('\n'); github.rest.issues.createComment({ issue_number: context.issue.number,