mirror of
https://github.com/booklore-app/booklore.git
synced 2025-12-23 14:20:48 -05:00
Try fixing versioning #2
This commit is contained in:
85
.github/workflows/docker-build-publish.yml
vendored
85
.github/workflows/docker-build-publish.yml
vendored
@@ -33,7 +33,7 @@ jobs:
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
password: ${{ github.token }}
|
||||
|
||||
- name: Set up QEMU for multi-arch builds
|
||||
uses: docker/setup-qemu-action@v3
|
||||
@@ -41,18 +41,18 @@ jobs:
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
# Set up Java for backend tests
|
||||
- name: Set up JDK 21
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: '21'
|
||||
distribution: 'temurin'
|
||||
|
||||
# Run backend tests
|
||||
- name: Run Backend Tests
|
||||
id: backend_tests
|
||||
working-directory: ./booklore-api
|
||||
run: ./gradlew test
|
||||
run: |
|
||||
echo "Running backend tests with testcontainers..."
|
||||
./gradlew test
|
||||
continue-on-error: true
|
||||
|
||||
- name: Publish Test Results
|
||||
@@ -78,19 +78,26 @@ jobs:
|
||||
- name: Check Test Results
|
||||
if: steps.backend_tests.outcome == 'failure'
|
||||
run: |
|
||||
echo "Backend tests failed!"
|
||||
echo "❌ Backend tests failed! Check the test results above."
|
||||
exit 1
|
||||
|
||||
# ----------------------------
|
||||
# Versioning Logic
|
||||
# ----------------------------
|
||||
- name: Get Latest Master Version
|
||||
id: get_version
|
||||
run: |
|
||||
latest_tag=$(git tag --list "v*" --sort=-v:refname | head -n 1)
|
||||
latest_tag=${latest_tag:-"v0.0.0"}
|
||||
echo "latest_tag=$latest_tag" >> $GITHUB_ENV
|
||||
echo "Latest master tag: $latest_tag"
|
||||
|
||||
- name: Determine Version Bump (Only for Master)
|
||||
if: github.ref == 'refs/heads/master'
|
||||
id: determine_bump
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
run: |
|
||||
echo "Determining version bump from PR labels..."
|
||||
|
||||
# Get PR number from merge commit
|
||||
# Extract PR number from merge commit
|
||||
pr_number=$(git log -1 --pretty=%B | grep -oE 'Merge pull request #[0-9]+' | grep -oE '[0-9]+') || true
|
||||
if [ -z "$pr_number" ]; then
|
||||
pr_number=$(gh pr list --state merged --base master --limit 1 --json number --jq '.[0].number')
|
||||
@@ -100,7 +107,6 @@ jobs:
|
||||
labels=$(gh pr view "$pr_number" --json labels --jq '.labels[].name' || echo "")
|
||||
echo "PR labels: $labels"
|
||||
|
||||
# Determine bump type
|
||||
if echo "$labels" | grep -q 'major'; then
|
||||
bump="major"
|
||||
elif echo "$labels" | grep -q 'minor'; then
|
||||
@@ -108,7 +114,6 @@ jobs:
|
||||
elif echo "$labels" | grep -q 'patch'; then
|
||||
bump="patch"
|
||||
else
|
||||
# fallback: check commit message
|
||||
last_commit_msg=$(git log -1 --pretty=%B)
|
||||
if echo "$last_commit_msg" | grep -iq '#major'; then
|
||||
bump="major"
|
||||
@@ -120,46 +125,25 @@ jobs:
|
||||
bump="patch"
|
||||
fi
|
||||
fi
|
||||
echo "Version bump type: $bump"
|
||||
|
||||
# Get latest tag
|
||||
latest_tag=$(git tag --list "v*" --sort=-v:refname | head -n 1)
|
||||
latest_tag=${latest_tag:-"v0.0.0"}
|
||||
echo "Latest tag: $latest_tag"
|
||||
|
||||
# Split version
|
||||
IFS='.' read -r major minor patch <<< "${latest_tag#v}"
|
||||
# Calculate next version
|
||||
semver=$(echo ${{ env.latest_tag }} | sed 's/^v//')
|
||||
major=$(echo $semver | cut -d. -f1)
|
||||
minor=$(echo $semver | cut -d. -f2)
|
||||
patch=$(echo $semver | cut -d. -f3)
|
||||
|
||||
case "$bump" in
|
||||
major)
|
||||
major=$((major + 1))
|
||||
minor=0
|
||||
patch=0
|
||||
;;
|
||||
minor)
|
||||
minor=$((minor + 1))
|
||||
patch=0
|
||||
;;
|
||||
patch)
|
||||
patch=$((patch + 1))
|
||||
;;
|
||||
major) major=$((major+1)); minor=0; patch=0 ;;
|
||||
minor) minor=$((minor+1)); patch=0 ;;
|
||||
patch) patch=$((patch+1)) ;;
|
||||
esac
|
||||
|
||||
new_tag="v${major}.${minor}.${patch}"
|
||||
echo "new_tag=$new_tag" >> $GITHUB_ENV
|
||||
echo "Next version: $new_tag"
|
||||
next_version="v${major}.${minor}.${patch}"
|
||||
echo "Version bump type: $bump"
|
||||
echo "Next version: $next_version"
|
||||
|
||||
# ----------------------------
|
||||
# Draft release with correct version
|
||||
# ----------------------------
|
||||
- name: Update Release Draft (Only for Master)
|
||||
if: github.ref == 'refs/heads/master'
|
||||
uses: release-drafter/release-drafter@v6
|
||||
with:
|
||||
name-template: 'Release ${{ env.new_tag }}'
|
||||
tag-template: '${{ env.new_tag }}'
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
echo "bump=$bump" >> $GITHUB_ENV
|
||||
echo "new_tag=$next_version" >> $GITHUB_ENV
|
||||
|
||||
- name: Generate Image Tag
|
||||
id: set_image_tag
|
||||
@@ -177,7 +161,7 @@ jobs:
|
||||
echo "image_tag=$image_tag" >> $GITHUB_ENV
|
||||
echo "Image tag: $image_tag"
|
||||
|
||||
- name: Build and Push Docker Image (Docker Hub & GHCR)
|
||||
- name: Build and Push Docker Image
|
||||
run: |
|
||||
docker buildx create --use
|
||||
docker buildx build \
|
||||
@@ -208,17 +192,18 @@ jobs:
|
||||
- name: Publish Draft Release (Only for Master)
|
||||
if: github.ref == 'refs/heads/master'
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: gh release edit ${{ env.new_tag }} --draft=false
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
run: |
|
||||
gh release edit ${{ env.new_tag }} --draft=false
|
||||
|
||||
- name: Notify Discord of New Release
|
||||
if: github.ref == 'refs/heads/master'
|
||||
continue-on-error: true
|
||||
shell: bash
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
|
||||
NEW_TAG: ${{ env.new_tag }}
|
||||
NEW_TAG: ${{ env.new_tag }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if [ -z "${DISCORD_WEBHOOK_URL:-}" ]; then
|
||||
|
||||
Reference in New Issue
Block a user