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 -->
This commit is contained in:
parent
311de23454
commit
77a3e74e0b
51
.github/scripts/version-bump.sh
vendored
51
.github/scripts/version-bump.sh
vendored
@ -1,14 +1,18 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Version Bump Script
|
# Version Bump Script
|
||||||
# Usage: ./version-bump.sh <bump_type> [base_ref]
|
# Usage: ./version-bump.sh [--ci] <bump_type> [base_ref]
|
||||||
|
# --ci: CI mode - run bump, check for changes, exit 1 if changes needed
|
||||||
# bump_type: patch, minor, or major
|
# bump_type: patch, minor, or major
|
||||||
# base_ref: base reference for diff (default: origin/main)
|
# base_ref: base reference for diff (default: origin/main)
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
|
CI_MODE=false
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "Usage: $0 <bump_type> [base_ref]"
|
echo "Usage: $0 [--ci] <bump_type> [base_ref]"
|
||||||
|
echo " --ci: CI mode - validates versions are already bumped (exits 1 if not)"
|
||||||
echo " bump_type: patch, minor, or major"
|
echo " bump_type: patch, minor, or major"
|
||||||
echo " base_ref: base reference for diff (default: origin/main)"
|
echo " base_ref: base reference for diff (default: origin/main)"
|
||||||
echo ""
|
echo ""
|
||||||
@ -16,6 +20,7 @@ usage() {
|
|||||||
echo " $0 patch # Update versions with patch bump"
|
echo " $0 patch # Update versions with patch bump"
|
||||||
echo " $0 minor # Update versions with minor bump"
|
echo " $0 minor # Update versions with minor bump"
|
||||||
echo " $0 major # Update versions with major bump"
|
echo " $0 major # Update versions with major bump"
|
||||||
|
echo " $0 --ci patch # CI check: verify patch bump has been applied"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +90,7 @@ update_readme_version() {
|
|||||||
in_module_block = 0
|
in_module_block = 0
|
||||||
if (module_has_target_source) {
|
if (module_has_target_source) {
|
||||||
num_lines = split(module_content, lines, "\n")
|
num_lines = split(module_content, lines, "\n")
|
||||||
for (i = 1; i <= num_lines; i++) {
|
for (i = 1; i < num_lines; i++) {
|
||||||
line = lines[i]
|
line = lines[i]
|
||||||
if (line ~ /^[[:space:]]*version[[:space:]]*=/) {
|
if (line ~ /^[[:space:]]*version[[:space:]]*=/) {
|
||||||
match(line, /^[[:space:]]*/)
|
match(line, /^[[:space:]]*/)
|
||||||
@ -115,6 +120,11 @@ update_readme_version() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
|
if [ "${1:-}" = "--ci" ]; then
|
||||||
|
CI_MODE=true
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
|
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
|
||||||
usage
|
usage
|
||||||
fi
|
fi
|
||||||
@ -152,6 +162,8 @@ main() {
|
|||||||
local untagged_modules=""
|
local untagged_modules=""
|
||||||
local has_changes=false
|
local has_changes=false
|
||||||
|
|
||||||
|
declare -a modified_readme_files=()
|
||||||
|
|
||||||
while IFS= read -r module_path; do
|
while IFS= read -r module_path; do
|
||||||
if [ -z "$module_path" ]; then continue; fi
|
if [ -z "$module_path" ]; then continue; fi
|
||||||
|
|
||||||
@ -202,6 +214,7 @@ main() {
|
|||||||
|
|
||||||
if update_readme_version "$readme_path" "$namespace" "$module_name" "$new_version"; then
|
if update_readme_version "$readme_path" "$namespace" "$module_name" "$new_version"; then
|
||||||
updated_readmes="$updated_readmes\n- $namespace/$module_name"
|
updated_readmes="$updated_readmes\n- $namespace/$module_name"
|
||||||
|
modified_readme_files+=("$readme_path")
|
||||||
has_changes=true
|
has_changes=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -210,19 +223,22 @@ main() {
|
|||||||
|
|
||||||
done <<< "$modules"
|
done <<< "$modules"
|
||||||
|
|
||||||
# Always run formatter to ensure consistent formatting
|
if [ ${#modified_readme_files[@]} -gt 0 ]; then
|
||||||
echo "🔧 Running formatter to ensure consistent formatting..."
|
echo "🔧 Formatting modified README files..."
|
||||||
if command -v bun > /dev/null 2>&1; then
|
if command -v bun > /dev/null 2>&1; then
|
||||||
bun fmt > /dev/null 2>&1 || echo "⚠️ Warning: bun fmt failed, but continuing..."
|
for readme_file in "${modified_readme_files[@]}"; do
|
||||||
else
|
bun run prettier --write "$readme_file" 2> /dev/null || true
|
||||||
echo "⚠️ Warning: bun not found, skipping formatting"
|
done
|
||||||
|
else
|
||||||
|
echo "⚠️ Warning: bun not found, skipping formatting"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
fi
|
fi
|
||||||
echo ""
|
|
||||||
|
|
||||||
echo "📋 Summary:"
|
echo "📋 Summary:"
|
||||||
echo "Bump Type: $bump_type"
|
echo "Bump Type: $bump_type"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Modules Updated:"
|
echo "Modules Processed:"
|
||||||
echo -e "$bumped_modules"
|
echo -e "$bumped_modules"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
@ -239,6 +255,19 @@ main() {
|
|||||||
echo ""
|
echo ""
|
||||||
fi
|
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
|
if [ "$has_changes" = true ]; then
|
||||||
echo "✅ Version bump completed successfully!"
|
echo "✅ Version bump completed successfully!"
|
||||||
echo "📝 README files have been updated with new versions."
|
echo "📝 README files have been updated with new versions."
|
||||||
|
|||||||
71
.github/workflows/version-bump.yaml
vendored
71
.github/workflows/version-bump.yaml
vendored
@ -55,62 +55,35 @@ jobs:
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
- name: Check version bump requirements
|
- name: Check version bump
|
||||||
id: version-check
|
run: ./.github/scripts/version-bump.sh --ci "${{ steps.bump-type.outputs.type }}" origin/main
|
||||||
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
|
|
||||||
|
|
||||||
{
|
- name: Comment on PR - Version bump required
|
||||||
echo "output<<EOF"
|
if: failure()
|
||||||
cat "$output_file"
|
|
||||||
echo "EOF"
|
|
||||||
} >> $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: Comment on PR - Failure
|
|
||||||
if: failure() && steps.version-check.outputs.versions_up_to_date == 'false'
|
|
||||||
uses: actions/github-script@v8
|
uses: actions/github-script@v8
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
script: |
|
script: |
|
||||||
const output = `${{ steps.version-check.outputs.output }}`;
|
|
||||||
const bumpType = `${{ steps.bump-type.outputs.type }}`;
|
const bumpType = `${{ steps.bump-type.outputs.type }}`;
|
||||||
|
|
||||||
let comment = `## ❌ Version Bump Validation Failed\n\n`;
|
const comment = [
|
||||||
comment += `**Bump Type:** \`${bumpType}\`\n\n`;
|
'## Version Bump Required',
|
||||||
comment += `Module versions need to be updated but haven't been bumped yet.\n\n`;
|
'',
|
||||||
comment += `**Required Actions:**\n`;
|
'One or more modules in this PR need their versions updated.',
|
||||||
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`;
|
'**To fix this:**',
|
||||||
comment += `3. Push the changes: \`git push\`\n\n`;
|
'1. Run the version bump script locally:',
|
||||||
comment += `### Script Output:\n\`\`\`\n${output}\n\`\`\`\n\n`;
|
' ```bash',
|
||||||
comment += `> Please update the module versions and push the changes to continue.`;
|
` ./.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({
|
github.rest.issues.createComment({
|
||||||
issue_number: context.issue.number,
|
issue_number: context.issue.number,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user