ci: Add job 'build-jar' (with maven) #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build & Publish Docker Image to GHCR | |
on: | |
push: | |
branches: | |
- main # Change if needed | |
workflow_dispatch: # Allow manual trigger | |
permissions: | |
contents: read | |
packages: write # Allows pushing to GHCR | |
jobs: | |
build-jar: | |
name: Build JAR with Maven | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'temurin' | |
java-version: '17' | |
cache: 'maven' | |
- name: Build with Maven | |
run: mvn clean package -DskipTests | |
- name: Upload JAR as Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: java-artifacts | |
path: | | |
target/*.jar | |
target/lib/*.jar | |
build-and-push: | |
name: Build & Push Docker Image | |
runs-on: ubuntu-latest | |
needs: build-jar | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Log in to GHCR | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin | |
- name: Build Docker Image | |
run: | | |
docker build -t ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:latest . | |
- name: Push Docker Image to GHCR | |
run: | | |
docker push ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:latest |