102 lines
3.2 KiB
YAML
102 lines
3.2 KiB
YAML
name: Main CI-Backend
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
push:
|
|
branches:
|
|
- main
|
|
paths:
|
|
- 'server/**/*.java'
|
|
- 'server/**/*.xml'
|
|
- 'server/pom.xml'
|
|
- '.github/workflows/main-server.yml'
|
|
|
|
jobs:
|
|
build-and-push:
|
|
name: Build & Push
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: write
|
|
packages: write
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v6
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Set lowercase repo name
|
|
id: repo
|
|
run: echo "name=${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Set up Java
|
|
uses: actions/setup-java@v4
|
|
with:
|
|
distribution: 'temurin'
|
|
java-version: '25'
|
|
cache: 'maven'
|
|
|
|
- name: Increment version in pom.xml
|
|
id: version
|
|
working-directory: ./server
|
|
run: |
|
|
# Extract current version from pom.xml
|
|
CURRENT_VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout)
|
|
echo "Current version: ${CURRENT_VERSION}"
|
|
|
|
# Increment version
|
|
NEW_VERSION=$((CURRENT_VERSION + 1))
|
|
echo "New version: ${NEW_VERSION}"
|
|
|
|
# Update pom.xml with new version
|
|
./mvnw versions:set -DnewVersion=${NEW_VERSION} -DgenerateBackupFiles=false -q
|
|
|
|
# Output for later steps
|
|
echo "version=${NEW_VERSION}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Commit version bump
|
|
run: |
|
|
git config user.name "github-actions[bot]"
|
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
git add server/pom.xml
|
|
git commit -m "chore: bump api version to ${{ steps.version.outputs.version }} [skip ci]"
|
|
git push
|
|
|
|
- name: Log in to GitHub Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Find PR number
|
|
id: find_pr
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
PR_NUMBER=$(gh pr list --search "${{ github.sha }}" --state merged --json number --jq '.[0].number')
|
|
if [ -z "$PR_NUMBER" ]; then
|
|
echo "No merged PR found for this commit. Falling back to 'candidate' tag."
|
|
PR_NUMBER="candidate"
|
|
else
|
|
PR_NUMBER="pr-${PR_NUMBER}"
|
|
fi
|
|
echo "tag=${PR_NUMBER}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Promote Docker image
|
|
run: |
|
|
docker buildx imagetools create \
|
|
--tag ghcr.io/${{ steps.repo.outputs.name }}/api:latest \
|
|
--tag ghcr.io/${{ steps.repo.outputs.name }}/api:${{ steps.version.outputs.version }} \
|
|
ghcr.io/${{ steps.repo.outputs.name }}/api:${{ steps.find_pr.outputs.tag }}
|
|
|
|
- name: Create and push Git tag
|
|
run: |
|
|
git config user.name "github-actions[bot]"
|
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
git tag -a api-v${{ steps.version.outputs.version }} -m "Release API v${{ steps.version.outputs.version }}"
|
|
git push origin api-v${{ steps.version.outputs.version }}
|