diff --git a/.gitea/workflows/auto-tag.yml b/.gitea/workflows/auto-tag.yml deleted file mode 100644 index 3ffc041..0000000 --- a/.gitea/workflows/auto-tag.yml +++ /dev/null @@ -1,99 +0,0 @@ -name: Auto-Tag Release - -on: - push: - branches: - - main - -jobs: - tag-release: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Alle Tags holen - - - name: Determine version bump - id: bump_type - run: | - # Hole die letzten Commits seit dem letzten Tag - LATEST_TAG=$(git tag -l "v*" --sort=-v:refname | head -n 1) - - if [ -z "$LATEST_TAG" ]; then - echo "bump=minor" >> $GITHUB_OUTPUT - echo "Kein Tag vorhanden, starte mit minor" - exit 0 - fi - - # Analysiere Commits seit letztem Tag - COMMITS=$(git log ${LATEST_TAG}..HEAD --pretty=format:"%s") - - echo "=== Commits seit ${LATEST_TAG} ===" - echo "$COMMITS" - echo "==================================" - - # Prüfe auf Breaking Changes / Major Updates - if echo "$COMMITS" | grep -qiE "^BREAKING CHANGE:|^[^:]+!:|breaking:|major:"; then - echo "bump=major" >> $GITHUB_OUTPUT - echo "✓ Breaking Change gefunden → MAJOR" - # Prüfe auf Features / Minor Updates - elif echo "$COMMITS" | grep -qiE "^feat:|^feature:|minor:"; then - echo "bump=minor" >> $GITHUB_OUTPUT - echo "✓ Feature gefunden → MINOR" - # Prüfe auf Bugfixes - elif echo "$COMMITS" | grep -qiE "^fix:|bugfix:"; then - echo "bump=patch" >> $GITHUB_OUTPUT - echo "✓ Bugfix gefunden → PATCH" - # Prüfe auf Chores/Docs/etc - elif echo "$COMMITS" | grep -qiE "^chore:|^docs:|^style:|^refactor:|^test:|^build:|^ci:"; then - echo "bump=patch" >> $GITHUB_OUTPUT - echo "✓ Chore/Docs gefunden → PATCH" - # Fallback: Kein Pattern erkannt → PATCH - else - echo "bump=patch" >> $GITHUB_OUTPUT - echo "⚠ Kein Pattern erkannt → PATCH (Fallback)" - fi - - - name: Calculate new tag - id: get_tag - run: | - LATEST_TAG=$(git tag -l "v*" --sort=-v:refname | head -n 1) - - if [ -z "$LATEST_TAG" ]; then - NEW_TAG="v1.0.0" - else - VERSION=${LATEST_TAG#v} - MAJOR=$(echo $VERSION | cut -d. -f1) - MINOR=$(echo $VERSION | cut -d. -f2) - PATCH=$(echo $VERSION | cut -d. -f3) - - case ${{ steps.bump_type.outputs.bump }} in - 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}" - fi - - echo "new_tag=${NEW_TAG}" >> $GITHUB_OUTPUT - echo "Neues Tag: ${NEW_TAG}" - - - name: Create and push tag - run: | - git config user.name "Gitea Actions" - git config user.email "actions@gitea.local" - - git tag -a ${{ steps.get_tag.outputs.new_tag }} -m "Release ${{ steps.get_tag.outputs.new_tag }}" - git push origin ${{ steps.get_tag.outputs.new_tag }} \ No newline at end of file diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 65f49b5..56230ba 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -1,12 +1,10 @@ -name: Build and Push Docker Image +name: Build, Tag and Push Docker Image on: push: branches: - main - dev - tags: - - 'v*' pull_request: branches: - main @@ -18,6 +16,61 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Determine version and create tag (main only) + id: version + run: | + if [ "${{ gitea.ref_name }}" = "main" ]; then + # Hole letzten Tag + LATEST_TAG=$(git tag -l "v*" --sort=-v:refname | head -n 1) + + if [ -z "$LATEST_TAG" ]; then + NEW_TAG="v1.0.0" + BUMP="minor" + else + VERSION=${LATEST_TAG#v} + MAJOR=$(echo $VERSION | cut -d. -f1) + MINOR=$(echo $VERSION | cut -d. -f2) + PATCH=$(echo $VERSION | cut -d. -f3) + + COMMITS=$(git log ${LATEST_TAG}..HEAD --pretty=format:"%s" 2>/dev/null || echo "") + + if [ -z "$COMMITS" ]; then + echo "Keine neuen Commits seit ${LATEST_TAG}" + echo "skip=true" >> $GITHUB_OUTPUT + echo "version=${VERSION}" >> $GITHUB_OUTPUT + exit 0 + fi + + if echo "$COMMITS" | grep -qiE "^BREAKING CHANGE:|^[^:]+!:|breaking:|major:"; then + MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0; BUMP="major" + elif echo "$COMMITS" | grep -qiE "^feat:|^feature:|minor:"; then + MINOR=$((MINOR + 1)); PATCH=0; BUMP="minor" + else + PATCH=$((PATCH + 1)); BUMP="patch" + fi + + NEW_TAG="v${MAJOR}.${MINOR}.${PATCH}" + fi + + # Prüfe ob Tag bereits existiert + if git rev-parse "$NEW_TAG" >/dev/null 2>&1; then + echo "Tag ${NEW_TAG} existiert bereits" + echo "skip=true" >> $GITHUB_OUTPUT + echo "version=${NEW_TAG#v}" >> $GITHUB_OUTPUT + else + echo "Erstelle neues Tag: ${NEW_TAG} (${BUMP})" + echo "new_tag=${NEW_TAG}" >> $GITHUB_OUTPUT + echo "version=${NEW_TAG#v}" >> $GITHUB_OUTPUT + echo "skip=false" >> $GITHUB_OUTPUT + fi + else + # Dev branch: snapshot version + echo "version=dev-${{ gitea.sha }}" >> $GITHUB_OUTPUT + echo "skip=true" >> $GITHUB_OUTPUT + fi - name: Login to Gitea Container Registry run: | @@ -27,8 +80,8 @@ jobs: id: tags run: | IMAGE_BASE="git.avatic.de/lcc_public/lcc" - TAGS="" - + VERSION="${{ steps.version.outputs.version }}" + TAGS="-t ${IMAGE_BASE}:${VERSION}" TAGS="${TAGS} -t ${IMAGE_BASE}:${{ gitea.sha }}" if [ "${{ gitea.ref_name }}" = "main" ]; then @@ -38,11 +91,6 @@ jobs: TAGS="${TAGS} -t ${IMAGE_BASE}:dev" fi - if [[ "${{ gitea.ref }}" == refs/tags/* ]]; then - VERSION="${{ gitea.ref_name }}" - TAGS="${TAGS} -t ${IMAGE_BASE}:${VERSION}" - fi - echo "tags=${TAGS}" >> $GITHUB_OUTPUT echo "image_base=${IMAGE_BASE}" >> $GITHUB_OUTPUT @@ -50,13 +98,16 @@ jobs: run: | docker build \ --build-arg BUILDKIT_INLINE_CACHE=1 \ + --build-arg APP_VERSION=${{ steps.version.outputs.version }} \ ${{ steps.tags.outputs.tags }} \ . - name: Push Docker images run: | IMAGE_BASE="${{ steps.tags.outputs.image_base }}" + VERSION="${{ steps.version.outputs.version }}" + docker push ${IMAGE_BASE}:${VERSION} docker push ${IMAGE_BASE}:${{ gitea.sha }} if [ "${{ gitea.ref_name }}" = "main" ]; then @@ -65,13 +116,17 @@ jobs: elif [ "${{ gitea.ref_name }}" = "dev" ]; then docker push ${IMAGE_BASE}:dev fi - - if [[ "${{ gitea.ref }}" == refs/tags/* ]]; then - docker push ${IMAGE_BASE}:${{ gitea.ref_name }} - fi + + - name: Create and push git tag + if: gitea.ref_name == 'main' && steps.version.outputs.skip != 'true' && steps.version.outputs.new_tag != '' + run: | + git config user.name "Gitea Actions" + git config user.email "actions@gitea.local" + git tag -a ${{ steps.version.outputs.new_tag }} -m "Release ${{ steps.version.outputs.new_tag }}" + git push origin ${{ steps.version.outputs.new_tag }} - name: Deploy to Docker - if: github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'dev') + if: gitea.event_name == 'push' && (gitea.ref_name == 'main' || gitea.ref_name == 'dev') run: | mkdir -p ~/.ssh echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/deploy_key diff --git a/dockerfile b/dockerfile index d077963..cb88806 100644 --- a/dockerfile +++ b/dockerfile @@ -7,14 +7,22 @@ RUN npm run build FROM maven:3.9-eclipse-temurin-23 AS backend-build WORKDIR /app + +ARG APP_VERSION=0.0.1-SNAPSHOT + COPY pom.xml ./ COPY src ./src -# copy frontend COPY --from=frontend-build /app/frontend/dist ./src/main/resources/static -RUN mvn clean package -DskipTests +RUN mvn versions:set -DnewVersion=${APP_VERSION} -DgenerateBackupPoms=false && \ + mvn clean package -DskipTests FROM eclipse-temurin:23-jre-alpine WORKDIR /app + +ARG APP_VERSION=0.0.1-SNAPSHOT +ENV APP_VERSION=${APP_VERSION} +LABEL version="${APP_VERSION}" + COPY --from=backend-build /app/target/*.jar app.jar EXPOSE 8080 ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file diff --git a/pom.xml b/pom.xml index 5f7213a..ebf5633 100644 --- a/pom.xml +++ b/pom.xml @@ -209,6 +209,11 @@ + + org.codehaus.mojo + versions-maven-plugin + 2.18.0 + org.jvnet.jaxb jaxb-maven-plugin