version-update.ymlโข6.3 kB
name: Version Update Assistant
on:
workflow_dispatch:
inputs:
version:
description: 'New version number (e.g., 1.6.5)'
required: true
type: string
release_notes:
description: 'Release notes (optional)'
required: false
type: string
create_pr:
description: 'Create pull request'
required: true
type: boolean
default: true
jobs:
update-version:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: '20.x'
cache: 'npm'
- name: Validate version format
shell: bash
env:
VERSION: ${{ inputs.version }}
run: |
if ! echo "$VERSION" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?$'; then
echo "โ Invalid version format: $VERSION"
echo "Version must follow semantic versioning (e.g., 1.6.5 or 1.6.5-beta.1)"
exit 1
fi
- name: Get current version
id: current_version
shell: bash
run: |
CURRENT=$(node -p "require('./package.json').version")
echo "current=$CURRENT" >> $GITHUB_OUTPUT
echo "Current version: $CURRENT"
- name: Check if version is newer
shell: bash
env:
CURRENT: ${{ steps.current_version.outputs.current }}
NEW: ${{ inputs.version }}
run: |
# Simple version comparison (works for most cases)
if [ "$CURRENT" = "$NEW" ]; then
echo "โ ๏ธ Version $NEW is the same as current version"
exit 1
fi
echo "โ
Updating from $CURRENT to $NEW"
- name: Update version in codebase
shell: bash
env:
VERSION: ${{ inputs.version }}
RELEASE_NOTES: ${{ inputs.release_notes }}
run: |
# Run the version update script with environment variables to prevent command injection
if [ -n "${RELEASE_NOTES}" ]; then
node scripts/update-version.mjs "${VERSION}" --notes "${RELEASE_NOTES}"
else
node scripts/update-version.mjs "${VERSION}"
fi
- name: Run tests
shell: bash
run: |
npm ci
npm test -- --maxWorkers=4
- name: Create Pull Request
if: inputs.create_pr
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: chore/update-version-${{ inputs.version }}
commit-message: |
chore: bump version to ${{ inputs.version }}
Updates version from ${{ steps.current_version.outputs.current }} to ${{ inputs.version }}
${{ inputs.release_notes }}
This is an automated version update.
committer: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
title: "chore: bump version to ${{ inputs.version }}"
body: |
## Version Update
This PR updates the version from `${{ steps.current_version.outputs.current }}` to `${{ inputs.version }}`.
### Release Notes
${{ inputs.release_notes || 'No release notes provided.' }}
### Files Updated
- package.json
- package-lock.json
- README.md
- CHANGELOG.md
- Documentation files
- Version constants
### Checklist
- [x] Version numbers updated
- [x] Tests passing
- [ ] Changelog reviewed
- [ ] Ready for release
---
*This is an automated pull request created by the Version Update workflow.*
labels: |
chore
version-update
automated
- name: Direct commit (no PR)
if: '!inputs.create_pr'
shell: bash
env:
NEW_VERSION: ${{ inputs.version }}
OLD_VERSION: ${{ steps.current_version.outputs.current }}
RELEASE_NOTES: ${{ inputs.release_notes }}
GITHUB_REF: ${{ github.ref }}
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add -A
# Create commit message safely using environment variables
printf "chore: bump version to %s\n\nUpdates version from %s to %s\n\n%s" \
"${NEW_VERSION}" "${OLD_VERSION}" "${NEW_VERSION}" "${RELEASE_NOTES}" | \
git commit -F -
git push origin "${GITHUB_REF}"
- name: Summary
shell: bash
env:
NEW_VERSION: ${{ inputs.version }}
OLD_VERSION: ${{ steps.current_version.outputs.current }}
RELEASE_NOTES: ${{ inputs.release_notes }}
CREATE_PR: ${{ inputs.create_pr }}
GITHUB_REF: ${{ github.ref }}
run: |
echo "## โ
Version Update Complete" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Previous version**: ${OLD_VERSION}" >> $GITHUB_STEP_SUMMARY
echo "- **New version**: ${NEW_VERSION}" >> $GITHUB_STEP_SUMMARY
if [ "${CREATE_PR}" = "true" ]; then
echo "- **Pull Request**: Created on branch \`chore/update-version-${NEW_VERSION}\`" >> $GITHUB_STEP_SUMMARY
else
echo "- **Committed to**: ${GITHUB_REF}" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
if [ -n "${RELEASE_NOTES}" ]; then
echo "### Release Notes" >> $GITHUB_STEP_SUMMARY
echo "${RELEASE_NOTES}" >> $GITHUB_STEP_SUMMARY
fi