70 lines
2.1 KiB
YAML
70 lines
2.1 KiB
YAML
|
|
name: bump-version
|
||
|
|
|
||
|
|
on:
|
||
|
|
push:
|
||
|
|
branches: [main]
|
||
|
|
workflow_dispatch:
|
||
|
|
|
||
|
|
concurrency:
|
||
|
|
group: bump-version
|
||
|
|
cancel-in-progress: false
|
||
|
|
|
||
|
|
jobs:
|
||
|
|
bump:
|
||
|
|
runs-on: ubuntu-latest
|
||
|
|
steps:
|
||
|
|
- name: Checkout
|
||
|
|
uses: actions/checkout@v4
|
||
|
|
with:
|
||
|
|
fetch-depth: 0
|
||
|
|
token: ${{ secrets.FORGEJO_TOKEN }}
|
||
|
|
|
||
|
|
- name: Skip if latest commit is already a release commit
|
||
|
|
run: |
|
||
|
|
SUBJECT=$(git log -1 --pretty=%s)
|
||
|
|
if [[ "$SUBJECT" == chore(release):* ]]; then
|
||
|
|
echo "Latest commit is a release commit ('$SUBJECT'). Skipping bump to avoid loop."
|
||
|
|
exit 0
|
||
|
|
fi
|
||
|
|
echo "Latest commit subject: $SUBJECT — proceeding with bump."
|
||
|
|
|
||
|
|
- name: Read current version
|
||
|
|
id: current
|
||
|
|
run: |
|
||
|
|
if [[ ! -f VERSION ]]; then
|
||
|
|
echo "VERSION file missing"
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
VERSION=$(tr -d '[:space:]' < VERSION)
|
||
|
|
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
|
||
|
|
|
||
|
|
- name: Compute next patch version
|
||
|
|
id: next
|
||
|
|
run: |
|
||
|
|
CURRENT="${{ steps.current.outputs.version }}"
|
||
|
|
STRIP_LEADING_V='s/^v//'
|
||
|
|
CORE=$(echo "$CURRENT" | sed -E "$STRIP_LEADING_V")
|
||
|
|
BASE="${CORE%%-*}"
|
||
|
|
SUFFIX=""
|
||
|
|
if [[ "$CORE" == *-* ]]; then
|
||
|
|
SUFFIX="-${CORE#*-}"
|
||
|
|
fi
|
||
|
|
IFS='.' read -r MAJOR MINOR PATCH <<< "$BASE"
|
||
|
|
if [[ -z "$MAJOR" || -z "$MINOR" || -z "$PATCH" ]]; then
|
||
|
|
echo "Cannot parse version: $CURRENT"
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
NEXT="v${MAJOR}.${MINOR}.$((PATCH + 1))${SUFFIX}"
|
||
|
|
echo "next=$NEXT" >> "$GITHUB_OUTPUT"
|
||
|
|
echo "Bumping $CURRENT → $NEXT"
|
||
|
|
|
||
|
|
- name: Update VERSION and push bump commit
|
||
|
|
run: |
|
||
|
|
NEXT="${{ steps.next.outputs.next }}"
|
||
|
|
printf '%s\n' "$NEXT" > VERSION
|
||
|
|
git config user.name "forgejo-actions[bot]"
|
||
|
|
git config user.email "forgejo-actions[bot]@noreply.${FORGEJO_DOMAIN:-src.sersofts.org}"
|
||
|
|
git add VERSION
|
||
|
|
git commit -m "chore(release): bump version to $NEXT"
|
||
|
|
git push origin HEAD:main
|