ci: add docker publish #24
Workflow file for this run
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: build | |
on: | |
push: | |
branches: | |
- "**" | |
jobs: | |
build: | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Checkout github repo | |
uses: actions/checkout@v4 | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v1 | |
with: | |
java-version: 11 | |
- name: Build with maven | |
run: > | |
./mvnw clean install | |
- name: Upload the artifact | |
if: github.ref == 'refs/heads/add_docker_publish' | |
uses: actions/upload-artifact@v2 | |
with: | |
name: query-executor | |
path: target/cohort-requester*.jar | |
sonar: | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Checkout github repo | |
uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v1 | |
with: | |
java-version: 17 | |
- name: Run sonarcloud analysis | |
run: > | |
./mvnw verify sonar:sonar | |
-Dsonar.sources=src/main/scala | |
-Dsonar.tests=src/test/scala | |
-Dsonar.scala.coverage.reportPaths=target/scoverage.xml | |
-Dsonar.host.url=https://sonarcloud.io | |
-Dsonar.organization=aphp | |
-Dsonar.projectKey=aphp_Cohort360-QueryExecutor | |
env: | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
publish: | |
if: github.ref == 'refs/heads/add_docker_publish' | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'adopt' | |
java-version: '11' | |
- name: Extract version from pom.xml | |
id: extract_version | |
run: | | |
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
- name: Download artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: query-executor | |
path: target | |
- name: Fetch pg dependency | |
run: | | |
POSTGRES_VERSION=$(mvn help:evaluate -Dexpression=postgres.version -q -DforceStdout) | |
mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.1:get -Dartifact=org.postgresql:postgresql:$POSTGRES_VERSION | |
mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.1:copy -Dartifact=org.postgresql:postgresql:$POSTGRES_VERSION -DoutputDirectory=./ | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to DockerHub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v4 | |
with: | |
file: ./Dockerfile | |
push: true | |
tags: "aphpid/cohort360-queryexecutor:${{ env.VERSION }}" |