91 lines
3.4 KiB
YAML
91 lines
3.4 KiB
YAML
name: Main CI-Backend
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
push:
|
|
branches:
|
|
- main
|
|
paths:
|
|
- 'server/**/*.java'
|
|
- 'server/**/*.xml'
|
|
- 'server/pom.xml'
|
|
- '.github/workflows/ci-main-backend.yml'
|
|
|
|
jobs:
|
|
build-and-push:
|
|
name: Build & Push
|
|
runs-on: graalvm-25
|
|
permissions:
|
|
contents: write
|
|
packages: write
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
token: ${{ secrets.REGISTRY_TOKEN }}
|
|
|
|
- name: Cache Maven dependencies
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: ~/.m2/repository
|
|
key: ${{ runner.os }}-maven-${{ hashFiles('**/server/pom.xml') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-maven-
|
|
|
|
- name: Increment version in pom.xml
|
|
id: version
|
|
working-directory: ./server
|
|
run: |
|
|
CURRENT_VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout)
|
|
echo "Current version: ${CURRENT_VERSION}"
|
|
NEW_VERSION=$((CURRENT_VERSION + 1))
|
|
echo "New version: ${NEW_VERSION}"
|
|
./mvnw versions:set -DnewVersion=${NEW_VERSION} -DgenerateBackupFiles=false -q
|
|
echo "version=${NEW_VERSION}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Commit version bump
|
|
run: |
|
|
git config user.name "gitea-actions[bot]"
|
|
git config user.email "gitea-actions[bot]@noreply.lightroasted.vps-kinghost.net"
|
|
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 Docker Hub
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- name: Find PR number
|
|
id: find_pr
|
|
run: |
|
|
PR_NUMBER=$(curl -s \
|
|
-H "Authorization: token ${{ secrets.REGISTRY_TOKEN }}" \
|
|
"https://lightroasted.vps-kinghost.net/api/v1/repos/${{ github.repository }}/commits/${{ github.sha }}/pull" \
|
|
| jq -r 'if type == "object" and .number != null then .number | tostring else empty end')
|
|
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 pull docker.io/rmcampos/tasknote-api:${{ steps.find_pr.outputs.tag }}
|
|
docker tag docker.io/rmcampos/tasknote-api:${{ steps.find_pr.outputs.tag }} docker.io/rmcampos/tasknote-api:latest
|
|
docker tag docker.io/rmcampos/tasknote-api:${{ steps.find_pr.outputs.tag }} docker.io/rmcampos/tasknote-api:${{ steps.version.outputs.version }}
|
|
docker push docker.io/rmcampos/tasknote-api:latest
|
|
docker push docker.io/rmcampos/tasknote-api:${{ steps.version.outputs.version }}
|
|
|
|
- name: Create and push Git tag
|
|
run: |
|
|
git config user.name "gitea-actions[bot]"
|
|
git config user.email "gitea-actions[bot]@noreply.lightroasted.vps-kinghost.net"
|
|
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 }}
|