Skip to content

Commit 77a3e74

Browse files
feat: enhance version bump script and CI workflow with ci mode (#615)
## Description Add CI mode to version bump script to output Pass or Fail with a less verbose comment when it fails <!-- Briefly describe what this PR does and why --> ## Type of Change - [ ] New module - [ ] New template - [ ] Bug fix - [ ] Feature/enhancement - [ ] Documentation - [X] Other ## Testing & Validation - [X] Tests pass (`bun test`) - [X] Code formatted (`bun fmt`) - [X] Changes tested locally ## Related Issues <!-- Link related issues or write "None" if not applicable -->
1 parent 311de23 commit 77a3e74

File tree

2 files changed

+62
-60
lines changed

2 files changed

+62
-60
lines changed

.github/scripts/version-bump.sh

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
#!/bin/bash
22

33
# Version Bump Script
4-
# Usage: ./version-bump.sh <bump_type> [base_ref]
4+
# Usage: ./version-bump.sh [--ci] <bump_type> [base_ref]
5+
# --ci: CI mode - run bump, check for changes, exit 1 if changes needed
56
# bump_type: patch, minor, or major
67
# base_ref: base reference for diff (default: origin/main)
78

89
set -euo pipefail
910

11+
CI_MODE=false
12+
1013
usage() {
11-
echo "Usage: $0 <bump_type> [base_ref]"
14+
echo "Usage: $0 [--ci] <bump_type> [base_ref]"
15+
echo " --ci: CI mode - validates versions are already bumped (exits 1 if not)"
1216
echo " bump_type: patch, minor, or major"
1317
echo " base_ref: base reference for diff (default: origin/main)"
1418
echo ""
1519
echo "Examples:"
1620
echo " $0 patch # Update versions with patch bump"
1721
echo " $0 minor # Update versions with minor bump"
1822
echo " $0 major # Update versions with major bump"
23+
echo " $0 --ci patch # CI check: verify patch bump has been applied"
1924
exit 1
2025
}
2126

@@ -85,7 +90,7 @@ update_readme_version() {
8590
in_module_block = 0
8691
if (module_has_target_source) {
8792
num_lines = split(module_content, lines, "\n")
88-
for (i = 1; i <= num_lines; i++) {
93+
for (i = 1; i < num_lines; i++) {
8994
line = lines[i]
9095
if (line ~ /^[[:space:]]*version[[:space:]]*=/) {
9196
match(line, /^[[:space:]]*/)
@@ -115,6 +120,11 @@ update_readme_version() {
115120
}
116121

117122
main() {
123+
if [ "${1:-}" = "--ci" ]; then
124+
CI_MODE=true
125+
shift
126+
fi
127+
118128
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
119129
usage
120130
fi
@@ -152,6 +162,8 @@ main() {
152162
local untagged_modules=""
153163
local has_changes=false
154164

165+
declare -a modified_readme_files=()
166+
155167
while IFS= read -r module_path; do
156168
if [ -z "$module_path" ]; then continue; fi
157169

@@ -202,6 +214,7 @@ main() {
202214

203215
if update_readme_version "$readme_path" "$namespace" "$module_name" "$new_version"; then
204216
updated_readmes="$updated_readmes\n- $namespace/$module_name"
217+
modified_readme_files+=("$readme_path")
205218
has_changes=true
206219
fi
207220

@@ -210,19 +223,22 @@ main() {
210223

211224
done <<< "$modules"
212225

213-
# Always run formatter to ensure consistent formatting
214-
echo "🔧 Running formatter to ensure consistent formatting..."
215-
if command -v bun > /dev/null 2>&1; then
216-
bun fmt > /dev/null 2>&1 || echo "⚠️ Warning: bun fmt failed, but continuing..."
217-
else
218-
echo "⚠️ Warning: bun not found, skipping formatting"
226+
if [ ${#modified_readme_files[@]} -gt 0 ]; then
227+
echo "🔧 Formatting modified README files..."
228+
if command -v bun > /dev/null 2>&1; then
229+
for readme_file in "${modified_readme_files[@]}"; do
230+
bun run prettier --write "$readme_file" 2> /dev/null || true
231+
done
232+
else
233+
echo "⚠️ Warning: bun not found, skipping formatting"
234+
fi
235+
echo ""
219236
fi
220-
echo ""
221237

222238
echo "📋 Summary:"
223239
echo "Bump Type: $bump_type"
224240
echo ""
225-
echo "Modules Updated:"
241+
echo "Modules Processed:"
226242
echo -e "$bumped_modules"
227243
echo ""
228244

@@ -239,6 +255,19 @@ main() {
239255
echo ""
240256
fi
241257

258+
if [ "$CI_MODE" = true ]; then
259+
echo "🔍 Comparing files to committed versions..."
260+
if git diff --quiet; then
261+
echo "✅ PASS: All versions match - no changes needed"
262+
exit 0
263+
else
264+
echo "❌ FAIL: Module versions need to be updated"
265+
echo ""
266+
echo "Run './.github/scripts/version-bump.sh $bump_type' locally and commit the changes"
267+
exit 1
268+
fi
269+
fi
270+
242271
if [ "$has_changes" = true ]; then
243272
echo "✅ Version bump completed successfully!"
244273
echo "📝 README files have been updated with new versions."

.github/workflows/version-bump.yaml

Lines changed: 22 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -55,62 +55,35 @@ jobs:
5555
;;
5656
esac
5757
58-
- name: Check version bump requirements
59-
id: version-check
60-
run: |
61-
output_file=$(mktemp)
62-
if ./.github/scripts/version-bump.sh "${{ steps.bump-type.outputs.type }}" origin/main > "$output_file" 2>&1; then
63-
echo "Script completed successfully"
64-
else
65-
echo "Script failed"
66-
cat "$output_file"
67-
exit 1
68-
fi
69-
70-
{
71-
echo "output<<EOF"
72-
cat "$output_file"
73-
echo "EOF"
74-
} >> $GITHUB_OUTPUT
75-
76-
cat "$output_file"
77-
78-
if git diff --quiet; then
79-
echo "versions_up_to_date=true" >> $GITHUB_OUTPUT
80-
echo "✅ All module versions are already up to date"
81-
else
82-
echo "versions_up_to_date=false" >> $GITHUB_OUTPUT
83-
echo "❌ Module versions need to be updated"
84-
echo "Files that would be changed:"
85-
git diff --name-only
86-
echo ""
87-
echo "Diff preview:"
88-
git diff
89-
90-
git checkout .
91-
git clean -fd
92-
93-
exit 1
94-
fi
58+
- name: Check version bump
59+
run: ./.github/scripts/version-bump.sh --ci "${{ steps.bump-type.outputs.type }}" origin/main
9560

96-
- name: Comment on PR - Failure
97-
if: failure() && steps.version-check.outputs.versions_up_to_date == 'false'
61+
- name: Comment on PR - Version bump required
62+
if: failure()
9863
uses: actions/github-script@v8
9964
with:
10065
github-token: ${{ secrets.GITHUB_TOKEN }}
10166
script: |
102-
const output = `${{ steps.version-check.outputs.output }}`;
10367
const bumpType = `${{ steps.bump-type.outputs.type }}`;
10468
105-
let comment = `## ❌ Version Bump Validation Failed\n\n`;
106-
comment += `**Bump Type:** \`${bumpType}\`\n\n`;
107-
comment += `Module versions need to be updated but haven't been bumped yet.\n\n`;
108-
comment += `**Required Actions:**\n`;
109-
comment += `1. Run the version bump script locally: \`./.github/scripts/version-bump.sh ${bumpType}\`\n`;
110-
comment += `2. Commit the changes: \`git add . && git commit -m "chore: bump module versions (${bumpType})"\`\n`;
111-
comment += `3. Push the changes: \`git push\`\n\n`;
112-
comment += `### Script Output:\n\`\`\`\n${output}\n\`\`\`\n\n`;
113-
comment += `> Please update the module versions and push the changes to continue.`;
69+
const comment = [
70+
'## Version Bump Required',
71+
'',
72+
'One or more modules in this PR need their versions updated.',
73+
'',
74+
'**To fix this:**',
75+
'1. Run the version bump script locally:',
76+
' ```bash',
77+
` ./.github/scripts/version-bump.sh ${bumpType}`,
78+
' ```',
79+
'2. Commit the changes:',
80+
' ```bash',
81+
` git add . && git commit -m "chore: bump module versions (${bumpType})"`,
82+
' ```',
83+
'3. Push your changes',
84+
'',
85+
'The CI will automatically re-run once you push the updated versions.'
86+
].join('\n');
11487
11588
github.rest.issues.createComment({
11689
issue_number: context.issue.number,

0 commit comments

Comments
 (0)