Skip to content

Enable JUnit tests in cicd again #228

Enable JUnit tests in cicd again

Enable JUnit tests in cicd again #228

Workflow file for this run

# This workflow runs the tests, builds the image and starts the deploy-script for olahd-backend on the devserver
name: olahd CI/CD
on:
push:
branches:
- 'main'
- 'develop'
tags:
#- 'refs/tags/v*'
- 'v[0-9]+.[0-9]+.[0-9]+'
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
junit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'temurin'
- name: run JUnit tests
run: mvn test
# builds docker image to test if dockerfiles are working
build:
#needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build the Docker image with version
run: docker build . --file Dockerfile --tag my-image-name:$(date +%s)
deploy-develop:
name: Deploy to develop
environment:
name: Develop
if: github.event.ref == 'refs/heads/develop'
#needs: [test, build]
needs: [build, build-and-push-dev-image]
runs-on: ubuntu-latest
steps:
- name: copy key
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/key
chmod 600 ~/.ssh/key
env:
SSH_KEY: ${{ secrets.OLAHD_SSH_KEY }}
- name: deploy to server
run: ssh $SSH_USER@$SSH_HOST -o StrictHostKeyChecking=no -i ~/.ssh/key /home/$SSH_USER/start-olahd-docker.sh
env:
SSH_USER: ${{ secrets.OLAHD_SSH_USER }}
SSH_HOST: ${{ secrets.OLAHD_SSH_HOST_DEV }}
deploy-staging:
name: Deploy to staging
environment:
name: Staging
if: github.event.ref == 'refs/heads/main'
#needs: [test, build]
needs: build
runs-on: ubuntu-latest
steps:
- name: copy key
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/key
chmod 600 ~/.ssh/key
env:
SSH_KEY: ${{ secrets.OLAHD_SSH_KEY }}
- name: deploy to server
run: ssh $SSH_USER@$SSH_HOST -o StrictHostKeyChecking=no -i ~/.ssh/key /home/$SSH_USER/start-olahd-docker.sh
env:
SSH_USER: ${{ secrets.OLAHD_SSH_USER }}
SSH_HOST: ${{ secrets.OLAHD_SSH_HOST_STAGE }}
deploy-production:
name: Deploy to production
environment:
name: Production
#if: startsWith(github.event.ref, 'refs/tags/v')
if: startsWith(github.ref, 'refs/tags/')
#needs: [test, build]
needs: build
runs-on: ubuntu-latest
steps:
- name: copy key
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/key
chmod 600 ~/.ssh/key
env:
SSH_KEY: ${{ secrets.OLAHD_SSH_KEY }}
- name: deploy to server
run: ssh $SSH_USER@$SSH_HOST -o StrictHostKeyChecking=no -i ~/.ssh/key /home/$SSH_USER/start-olahd-docker.sh
env:
SSH_USER: ${{ secrets.OLAHD_SSH_USER }}
SSH_HOST: ${{ secrets.OLAHD_SSH_HOST_PROD }}
build-and-push-dev-image:
name: Push dev images to registry
environment:
name: Develop
if: github.event.ref == 'refs/heads/develop'
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: develop
- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-and-push-main-image-staging:
name: Push main images to registry (staging)
environment:
name: Staging
if: github.event.ref == 'refs/heads/main'
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: main
- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-and-push-main-image-production:
name: Push main images to registry (production)
environment:
name: Production
if: startsWith(github.ref, 'refs/tags/')
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: main
- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}