diff --git a/.github/workflows/build-war-and-container.yml b/.github/workflows/build-and-publish-image.yml similarity index 51% rename from .github/workflows/build-war-and-container.yml rename to .github/workflows/build-and-publish-image.yml index 2b80b89d7..8f0f24e3e 100644 --- a/.github/workflows/build-war-and-container.yml +++ b/.github/workflows/build-and-publish-image.yml @@ -1,16 +1,19 @@ -name: Build .war and Docker container +name: Build JAR and Docker image and publish to GHCR on: push: branches: [ main ] + tags: [ v* ] pull_request: types: - opened - reopened - synchronize - assigned + env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} + jobs: build: runs-on: ubuntu-latest @@ -18,26 +21,23 @@ jobs: contents: read packages: write steps: - - uses: actions/checkout@v2 - - name: Set up JDK 21 - uses: actions/setup-java@v1 - with: - java-version: 21 - name: Build with Maven - run: ./mvnw -B package - - name: Publish to Github - run: ./mvnw -B -Dmaven.test.skip=true deploy - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: + - actions/checkout@v4 + - actions/setup-java@v4 + with: + distribution: 'temurin' # See 'Supported distributions' for available options + java-version: '21' + run: ./mvnw spring-boot:build-image --batch-mode --no-transfer-progress - name: Log in to the Container registry - uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Extract metadata (tags, labels) for Docker + - name: Extract metadata (tags, labels) to use for Docker (incl. image tags) id: meta - uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | @@ -45,14 +45,10 @@ jobs: type=ref,event=tag type=ref,event=pr type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }} - - name: Build Docker image - run: ./mvnw -B -Dmaven.test.skip=true -Dspring-boot.build-image.imageName=ghcr.io/hbtgmbh/salat:ci spring-boot:build-image - - name: Push Docker image with ci tag (required by tag-push-action) - run: docker push ghcr.io/hbtgmbh/salat:ci - name: Push Docker image - uses: akhilerm/tag-push-action@v2.0.0 + uses: akhilerm/tag-push-action@v2.0.1 with: - src: ghcr.io/hbtgmbh/salat:ci + src: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest dst: | ${{ steps.meta.outputs.tags }}