Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 39 additions & 45 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,9 @@ jobs:
run: chmod +x mvnw
- name: Compile project
run: ./mvnw clean compile
# test:
# runs-on: ubuntu-latest
# name: Test app
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# with:
# fetch-depth: 0
# - name: Setup JDK
# uses: actions/setup-java@v4
# with:
# java-version: '21'
# distribution: 'temurin'
# - name: Cache Maven packages
# uses: actions/cache@v4
# with:
# path: ~/.m2/repository
# key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
# restore-keys: |
# ${{ runner.os }}-maven-
# - name: Give execute permission to mvnw
# run: chmod +x mvnw
# - name: Run Tests
# run: ./mvnw clean test
# - name: Upload test report
# uses: actions/upload-artifact@v4
# with:
# name: test-results
# path: target/surefire-reports
build:
test:
runs-on: ubuntu-latest
name: Build app
needs: [compile] # add test after tests have been added
name: Test app
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -81,12 +51,17 @@ jobs:
${{ runner.os }}-maven-
- name: Give execute permission to mvnw
run: chmod +x mvnw
- name: Build project
run: ./mvnw clean package
build-docker-image:
- name: Run Tests
run: ./mvnw clean test
- name: Upload test report
uses: actions/upload-artifact@v4
with:
name: test-results
path: target/surefire-reports
build:
runs-on: ubuntu-latest
name: Build docker image
needs: [ build ]
name: Build app
needs: [compile, test]
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -106,24 +81,43 @@ jobs:
${{ runner.os }}-maven-
- name: Give execute permission to mvnw
run: chmod +x mvnw
- name: Extract project version
id: extract_version
run: echo "VERSION=$(./mvnw -q -Dexec.executable='echo' -Dexec.args='${project.version}' --non-recursive exec:exec)" >> $GITHUB_OUTPUT
- name: Build project
run: ./mvnw clean package
build-docker-image:
runs-on: ubuntu-latest
name: Docker Build
needs: [ build]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build Docker image (no push)
if: github.event_name == 'pull_request'
uses: docker/build-push-action@v6
with:
context: .
push: false
tags: query-service:pr-${{ github.sha }}

- name: Login to Docker Hub
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and Push to Docker Hub
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/query-service:${{steps.extract_version.outputs.VERSION}}
${{ secrets.DOCKERHUB_USERNAME }}/query-service:${{ github.sha }}
${{ secrets.DOCKERHUB_USERNAME }}/query-service:latest
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/query-service:buildcache
cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/query-service:buildcache,mode=max

cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/query-service:buildcache,mode=max
Loading