Skip to content

CI

CI #789

Workflow file for this run

name: CI
on:
push:
branches:
- master
pull_request:
schedule:
# Schedule weekly builds on master, to ensure that the Docker image gets
# rebuilt regularly (in order to include security fixes in the base image).
- cron: '5 4 * * 5'
jobs:
test:
name: run tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Fix permissions of working directory
run: chmod 777 .
- name: Start containers with docker-compose
run: docker-compose up -d
env:
CONTAINER_COVERAGE_HOME_DIR: /srv/www/studentenportal
- name: Check running containers
run: docker ps
- name: Run tests
run: docker-compose run --rm studentenportal_dev ./deploy/dev/test.sh --coverage-xml
- name: Upload coverage to codecov.io
uses: codecov/codecov-action@v3
with:
token: ${{secrets.CODECOV_TOKEN}}
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: psf/black@stable
publish:
name: publish docker image
runs-on: ubuntu-latest
env:
DOCKER_USERNAME: "${{ secrets.DOCKER_USERNAME }}"
DOCKER_PASSWORD: "${{ secrets.DOCKER_PASSWORD }}"
if: github.ref == 'refs/heads/master'
needs:
- test
- lint
steps:
- uses: actions/checkout@v3
- name: Fetch repository tags (for git describe to work)
run: git fetch --prune --unshallow
# Build and push docker image
# Make sure that the DOCKER_USERNAME and DOCKER_PASSWORD secret variables are set
- name: Export env vars
run: |
export RELEASE=$(git describe --tags)
if [ -z "$RELEASE" ]; then echo "Could not determine release name"; exit 1; fi
echo "export DOCKER_TAGS='studentenportal/web:latest studentenportal/web:${RELEASE}'" >> .ci-env
echo "export DOCKER_TAGS_NGINX='studentenportal/nginx:latest studentenportal/nginx:${RELEASE}'" >> .ci-env
- name: Build Docker image
run: source .ci-env && bash deploy/production/ci-build.sh
- name: Publish Docker image
run: source .ci-env && bash deploy/production/ci-publish.sh