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