Files
tasknote/.github/workflows/ci-main-backend.yml
T
rmcampos fc3d871c8b
Pull Request CI-Backend / Checks (pull_request) Successful in 6m48s
Pull Request CI-Frontend / Checks (pull_request) Successful in 6m59s
Pull Request CI-Backend / Build & Push (pull_request) Failing after 7m10s
Pull Request CI-Frontend / Build & Push (pull_request) Failing after 15m2s
feat: add caching to workflows
2026-06-15 13:20:44 -03:00

97 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
- 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: Set lowercase repo name
id: repo
run: echo "name=${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT
- 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 Gitea Container Registry
uses: docker/login-action@v3
with:
registry: lightroasted.vps-kinghost.net
username: ${{ github.actor }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- 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" 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 buildx imagetools create \
--tag lightroasted.vps-kinghost.net/${{ steps.repo.outputs.name }}/api:latest \
--tag lightroasted.vps-kinghost.net/${{ steps.repo.outputs.name }}/api:${{ steps.version.outputs.version }} \
lightroasted.vps-kinghost.net/${{ steps.repo.outputs.name }}/api:${{ steps.find_pr.outputs.tag }}
- 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 }}