fix: improve version bump logic and output handling in CI workflow
This commit is contained in:
@@ -11,10 +11,9 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
increment-version:
|
increment-version:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: github.ref == 'refs/heads/main' && !contains(github.event.head_commit.message, '[skip ci]')
|
|
||||||
outputs:
|
outputs:
|
||||||
version: ${{ steps.bump.outputs.VERSION }}
|
version: ${{ steps.finalize.outputs.VERSION }}
|
||||||
should_build: ${{ steps.bump.outputs.SHOULD_BUILD }}
|
should_build: ${{ steps.decide.outputs.SHOULD_BUILD }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
@@ -23,8 +22,34 @@ jobs:
|
|||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Decide version behavior
|
||||||
|
id: decide
|
||||||
|
run: |
|
||||||
|
CURRENT=$(grep -Po '"version":\s*"\K[^"]+' package.json | head -1)
|
||||||
|
COMMIT_MSG="${{ github.event.head_commit.message || '' }}"
|
||||||
|
|
||||||
|
SHOULD_BUMP=false
|
||||||
|
SHOULD_BUILD=true
|
||||||
|
|
||||||
|
if [ "${{ github.ref }}" = "refs/heads/main" ] && ! echo "$COMMIT_MSG" | grep -qi '\[skip ci\]'; then
|
||||||
|
SHOULD_BUMP=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
if echo "$COMMIT_MSG" | grep -qi '\[skip ci\]'; then
|
||||||
|
SHOULD_BUILD=false
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "CURRENT_VERSION=$CURRENT" >> $GITHUB_OUTPUT
|
||||||
|
echo "SHOULD_BUMP=$SHOULD_BUMP" >> $GITHUB_OUTPUT
|
||||||
|
echo "SHOULD_BUILD=$SHOULD_BUILD" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
echo "Current version: $CURRENT"
|
||||||
|
echo "Should bump: $SHOULD_BUMP"
|
||||||
|
echo "Should build: $SHOULD_BUILD"
|
||||||
|
|
||||||
- name: Bump patch version
|
- name: Bump patch version
|
||||||
id: bump
|
id: bump
|
||||||
|
if: ${{ steps.decide.outputs.SHOULD_BUMP == 'true' }}
|
||||||
run: |
|
run: |
|
||||||
# Get current version from package.json
|
# Get current version from package.json
|
||||||
CURRENT=$(grep -Po '"version":\s*"\K[^"]+' package.json | head -1)
|
CURRENT=$(grep -Po '"version":\s*"\K[^"]+' package.json | head -1)
|
||||||
@@ -45,9 +70,9 @@ jobs:
|
|||||||
grep '"version"' package.json | head -1
|
grep '"version"' package.json | head -1
|
||||||
|
|
||||||
echo "VERSION=$NEW_VERSION" >> $GITHUB_OUTPUT
|
echo "VERSION=$NEW_VERSION" >> $GITHUB_OUTPUT
|
||||||
echo "SHOULD_BUILD=true" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: Commit and push version bump
|
- name: Commit and push version bump
|
||||||
|
if: ${{ steps.decide.outputs.SHOULD_BUMP == 'true' }}
|
||||||
run: |
|
run: |
|
||||||
git config user.name "GitHub Actions"
|
git config user.name "GitHub Actions"
|
||||||
git config user.email "actions@github.com"
|
git config user.email "actions@github.com"
|
||||||
@@ -71,6 +96,15 @@ jobs:
|
|||||||
echo "Failed to push version bump after 3 attempts"
|
echo "Failed to push version bump after 3 attempts"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
|
- name: Finalize version output
|
||||||
|
id: finalize
|
||||||
|
run: |
|
||||||
|
if [ -n "${{ steps.bump.outputs.VERSION }}" ]; then
|
||||||
|
echo "VERSION=${{ steps.bump.outputs.VERSION }}" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "VERSION=${{ steps.decide.outputs.CURRENT_VERSION }}" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
|
||||||
build-windows:
|
build-windows:
|
||||||
runs-on: windows
|
runs-on: windows
|
||||||
needs: increment-version
|
needs: increment-version
|
||||||
|
|||||||
Reference in New Issue
Block a user