Feature/rest endpoints #82
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: Quotly Build Pipeline | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
permissions: read-all | |
jobs: | |
run_integration_tests: | |
runs-on: self-hosted | |
env: | |
RUNNER_TOOL_CACHE: /toolcache | |
services: | |
database: | |
image: mariadb:10.6.19-ubi | |
ports: | |
- 3306:3306 | |
env: | |
MYSQL_ROOT_PASSWORD: ${{ secrets.TEST_DATABASE_PASSWORD }} | |
MYSQL_DATABASE: ${{ vars.TEST_DATABASE_NAME }} | |
MYSQL_USER: ${{ vars.TEST_DATABASE_USERNAME }} | |
MYSQL_PASSWORD: ${{ secrets.TEST_DATABASE_PASSWORD }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Lint Dockerfile | |
uses: super-linter/[email protected] | |
env: | |
DEFAULT_BRANCH: origin/main | |
GITHUB_TOKEN: ${{ secrets.QUOTLY_TOKEN }} | |
FILTER_REGEX_INCLUDE: ^Dockerfile$ | |
FILTER_REGEX_EXCLUDE: .* | |
VALIDATE_DOCKERFILE: true | |
VALIDATE_JSCPD: false | |
- name: Lint Java | |
uses: super-linter/[email protected] | |
env: | |
DEFAULT_BRANCH: origin/main | |
GITHUB_TOKEN: ${{ secrets.QUOTLY_TOKEN }} | |
FILTER_REGEX_INCLUDE: src/.*\.java$ | |
VALIDATE_JAVA: true | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: 17 | |
cache: 'maven' | |
- name: Run backend tests | |
env: | |
DATABASE_URL: jdbc:mariadb://localhost:3306/${{ vars.TEST_DATABASE_NAME }} | |
DATABASE_USERNAME: ${{ vars.TEST_DATABASE_USERNAME }} | |
DATABASE_PASSWORD: ${{ secrets.TEST_DATABASE_PASSWORD }} | |
run: | | |
chmod +x mvnw | |
./mvnw test -Dquarkus.profile=test | |
build_and_push_docker_image: | |
runs-on: self-hosted | |
needs: run_integration_tests | |
env: | |
RUNNER_TOOL_CACHE: /toolcache | |
services: | |
docker: | |
image: docker:19.03.12 | |
options: --privileged | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: 17 | |
cache: 'maven' | |
- name: Generate docker image tag | |
id: tag | |
run: | | |
REPOSITORY_OWNER=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]') | |
BRANCH_NAME=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} | |
BRANCH_NAME=${BRANCH_NAME/'/#'/-} | |
BRANCH_NAME=${BRANCH_NAME//[^a-zA-Z0-9-]/} | |
if [ "$BRANCH_NAME" == "main" ]; then | |
DATE_TAG=$(date +'%Y.%m') | |
BUILD_NUMBER=$(echo $GITHUB_RUN_NUMBER) | |
DOCKER_IMAGE_TAG="${DATE_TAG}.${BUILD_NUMBER}" | |
DOCKER_IMAGE_NAME="ghcr.io/${REPOSITORY_OWNER}/quotly-release" | |
else | |
BUILD_NUMBER=$(echo $GITHUB_RUN_NUMBER) | |
DOCKER_IMAGE_TAG="${BRANCH_NAME}.${BUILD_NUMBER}" | |
DOCKER_IMAGE_NAME="ghcr.io/${REPOSITORY_OWNER}/quotly-staging" | |
fi | |
echo "DOCKER_IMAGE_TAG=$DOCKER_IMAGE_TAG" >> $GITHUB_ENV | |
echo "DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME" >> $GITHUB_ENV | |
- name: Build backend | |
run: | | |
chmod +x mvnw | |
./mvnw clean | |
./mvnw versions:set -DnewVersion=${{ env.DOCKER_IMAGE_TAG }} | |
./mvnw package -Dquarkus.package.jar.type=uber-jar -DskipTests | |
- name: Build Docker image | |
run: | | |
TAG=${{ env.DOCKER_IMAGE_TAG }} | |
docker build -t quotly:$TAG . | |
- name: Login to Github Packages | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ vars.DOCKER_USERNAME }} | |
password: ${{ secrets.QUOTLY_TOKEN }} | |
- name: Push Docker image | |
run: | | |
DOCKER_IMAGE_TAG=${{ env.DOCKER_IMAGE_TAG }} | |
DOCKER_IMAGE_NAME=${{ env.DOCKER_IMAGE_NAME }} | |
docker tag quotly:$DOCKER_IMAGE_TAG $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG | |
docker push $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG | |
- name: Clean up old staging images | |
if: endsWith(env.DOCKER_IMAGE_NAME, 'staging') | |
run: | | |
chmod +x cleanup_docker_images.sh | |
./cleanup_docker_images.sh ${{ github.repository_owner }} quotly-staging ${{ secrets.QUOTLY_TOKEN }} 5 |