mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-11 13:08:51 +01:00
- Now correctly determines the base version for version bumping:
- Uses the version from an existing version bump PR if available.
- Falls back to `package.json` version if no existing PR is found.
- Ensures that the version is bumped based on the labels of the newly merged PR.
- Closes an existing version bump PR before creating a new one to prevent duplicates.
- Removed the redundant branch creation step as `create-pull-request@v7` fully manages it.
- Ensures that every new version bump PR correctly increments beyond the last one.
This improves automation reliability and prevents version conflicts. 🚀
110 lines
No EOL
3.8 KiB
YAML
110 lines
No EOL
3.8 KiB
YAML
name: Semantic Version Bump (via Labels)
|
|
|
|
on:
|
|
pull_request:
|
|
types:
|
|
- closed
|
|
|
|
jobs:
|
|
versioning:
|
|
if: github.event.pull_request.merged == true && github.base_ref == 'main'
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: write
|
|
pull-requests: write
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Install dependencies
|
|
run: npm install -g semver jq
|
|
|
|
- name: Get last version from package.json
|
|
id: version
|
|
run: |
|
|
LAST_VERSION=$(jq -r '.version' package.json)
|
|
echo "Last version: $LAST_VERSION"
|
|
echo "LAST_VERSION=$LAST_VERSION" >> $GITHUB_ENV
|
|
|
|
- name: Check if an existing version bump PR exists
|
|
id: check_existing_pr
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
EXISTING_PR=$(gh pr list --state open --json number,title --jq '.[] | select(.title | contains("chore(version)")) | {number: .number, title: .title}')
|
|
EXISTING_PR_NUMBER=$(echo "$EXISTING_PR" | jq -r '.number')
|
|
EXISTING_PR_VERSION=$(echo "$EXISTING_PR" | grep -oP '\d+\.\d+\.\d+' | head -n 1)
|
|
|
|
if [[ -n "$EXISTING_PR_NUMBER" ]]; then
|
|
echo "Closing existing PR #$EXISTING_PR_NUMBER"
|
|
gh pr close "$EXISTING_PR_NUMBER" --comment "🚀 Auto-closing this PR in favor of a new version bump."
|
|
echo "EXISTING_PR_NUMBER=$EXISTING_PR_NUMBER" >> $GITHUB_ENV
|
|
fi
|
|
|
|
if [[ -n "$EXISTING_PR_VERSION" ]]; then
|
|
echo "EXISTING_PR_VERSION=$EXISTING_PR_VERSION" >> $GITHUB_ENV
|
|
fi
|
|
|
|
- name: Determine new version based on PR labels
|
|
id: bump_version
|
|
env:
|
|
PR_LABELS: ${{ join(github.event.pull_request.labels.*.name, ' ') }}
|
|
BASE_VERSION: ${{ env.EXISTING_PR_VERSION || env.LAST_VERSION }}
|
|
run: |
|
|
echo "Labels on PR: $PR_LABELS"
|
|
echo "Base version: $BASE_VERSION"
|
|
|
|
MAJOR=false
|
|
MINOR=false
|
|
PATCH=false
|
|
|
|
if echo "$PR_LABELS" | grep -qi "💥 breaking change"; then
|
|
MAJOR=true
|
|
fi
|
|
if echo "$PR_LABELS" | grep -qi "✨ feat"; then
|
|
MINOR=true
|
|
fi
|
|
if echo "$PR_LABELS" | grep -qi "🔧 fix"; then
|
|
PATCH=true
|
|
fi
|
|
|
|
NEW_VERSION=$BASE_VERSION
|
|
|
|
if [ "$MAJOR" = true ]; then
|
|
NEW_VERSION=$(semver -i major $BASE_VERSION)
|
|
elif [ "$MINOR" = true ]; then
|
|
NEW_VERSION=$(semver -i minor $BASE_VERSION)
|
|
elif [ "$PATCH" = true ]; then
|
|
NEW_VERSION=$(semver -i patch $BASE_VERSION)
|
|
fi
|
|
|
|
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
|
|
echo "Next version: $NEW_VERSION"
|
|
|
|
- name: Update package.json version
|
|
run: |
|
|
jq --arg version "$NEW_VERSION" '.version = $version' package.json > temp.json && mv temp.json package.json
|
|
|
|
- name: Install dependencies and update package-lock.json
|
|
run: |
|
|
npm install
|
|
npm ci
|
|
|
|
- name: Create New Pull Request
|
|
uses: peter-evans/create-pull-request@v7
|
|
with:
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
sign-commits: true
|
|
commit-message: "chore(version): bump version to ${{ env.NEW_VERSION }}"
|
|
base: main
|
|
branch: version-bump/${{ env.NEW_VERSION }}
|
|
reviewers: danny-avila
|
|
title: "chore(version): Bump version to ${{ env.NEW_VERSION }}"
|
|
body: |
|
|
**Description**:
|
|
- 🎯 **Objective**: Update `package.json` and `package-lock.json` with the latest version bump.
|
|
- 🔍 **Details**: This PR is automatically generated upon merging PRs with the correct versioning labels.
|
|
- ✅ **Status**: Ready for review.
|
|
labels: "📦 version update" |