Merge pull request #2 from bifrurcated/jpa-hibernate #35
This file contains 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: Java CI with Maven | |
on: | |
push: | |
branches: ["main"] | |
pull_request: | |
branches: ["main"] | |
permissions: | |
checks: write | |
jobs: | |
test: | |
name: Build and Run Tests | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
name: Check out code | |
- name: Setup Maven Action | |
uses: s4u/setup-maven-action@v1.11.0 | |
with: | |
java-version: 17 | |
- name: Run tests | |
run: mvn test --batch-mode --fail-at-end | |
- name: JUnit Report Action | |
uses: mikepenz/action-junit-report@v4.0.4 | |
if: success() || failure() | |
with: | |
report_paths: '**/build/test-results/test/TEST-*.xml' | |
build-and-push-docker-image: | |
needs: test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Setup Maven Action | |
uses: s4u/setup-maven-action@v1.11.0 | |
with: | |
java-version: 17 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build image | |
run: mvn spring-boot:build-image -Ddockerfile=Dockerfile.layers -DskipTests | |
- name: Get project artifactId and version | |
run: | | |
artifactId=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.artifactId}' exec:exec) | |
version=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' exec:exec) | |
image_name="${artifactId}:${version}" | |
echo "IMAGE_NAME=${image_name}" >> $GITHUB_ENV | |
- name: print IMAGE_NAME | |
run: echo ${IMAGE_NAME} | |
- name: Push image | |
run: docker push ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }} |