46 lines
1.8 KiB
YAML
46 lines
1.8 KiB
YAML
name: Version
|
|
on:
|
|
push:
|
|
branches: [development, main]
|
|
permissions:
|
|
contents: write
|
|
jobs:
|
|
bump:
|
|
if: github.actor != 'github-actions[bot]' && !contains(github.event.head_commit.message, '[skip ci]')
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
- name: Bump version
|
|
run: |
|
|
set -e
|
|
git config user.name "github-actions[bot]"
|
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
[ -f VERSION ] || echo "0.1.0" > VERSION
|
|
IFS=. read -r MA MI PA < VERSION
|
|
BRANCH="${GITHUB_REF_NAME}"
|
|
BUMP=patch
|
|
if [ "$BRANCH" = "main" ]; then
|
|
# MINOR bump when every new commit already exists on development (PR from development)
|
|
git fetch origin development || true
|
|
RANGE="${{ github.event.before }}..${{ github.sha }}"
|
|
if git rev-parse -q --verify origin/development >/dev/null \
|
|
&& [ -n "$(git rev-list $RANGE 2>/dev/null)" ] \
|
|
&& [ -z "$(git rev-list $RANGE --not origin/development 2>/dev/null | grep -v "^$(git rev-parse HEAD)$" || true)" ]; then
|
|
BUMP=minor
|
|
fi
|
|
fi
|
|
if [ "$BUMP" = minor ]; then MI=$((MI+1)); PA=0; else PA=$((PA+1)); fi
|
|
NEW="$MA.$MI.$PA"
|
|
echo "$NEW" > VERSION
|
|
git add VERSION
|
|
git commit -m "chore(release): v$NEW [skip ci]"
|
|
git push origin "HEAD:$BRANCH"
|
|
if [ "$BRANCH" = "main" ]; then
|
|
git fetch origin development || exit 0
|
|
git checkout -B development origin/development
|
|
git merge origin/main -m "chore(release): merge main v$NEW [skip ci]"
|
|
git push origin development
|
|
fi
|