Skip to content

Upgrade CI actions #1792

Upgrade CI actions

Upgrade CI actions #1792

Workflow file for this run

name: "Hitas CI"
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches:
- master
pull_request:
branches:
- master
merge_group:
branches:
- master
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
frontend:
name: "Frontend checks"
runs-on: ubuntu-latest
steps:
- name: "Checkout code"
uses: actions/checkout@v3
- name: "Frontend - Set Node.js 18.x"
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: "Frontend - Install dependencies"
uses: borales/actions-yarn@v4
with:
dir: "frontend"
cmd: install
- name: "Frontend - Check for ESLint issues"
uses: borales/actions-yarn@v4
with:
dir: "frontend"
cmd: eslint-check
- name: "Frontend - Check for Prettier issues"
uses: borales/actions-yarn@v4
with:
dir: "frontend"
cmd: prettier-check
build-frontend:
name: "Test building frontend docker image"
runs-on: ubuntu-latest
steps:
- name: "Checkout code"
uses: actions/checkout@v3
- name: "Set up Docker Buildx"
uses: docker/setup-buildx-action@v3
- name: "Build frontend container"
uses: docker/build-push-action@v2
with:
context: frontend
push: false
tags: hitas-frontend
cache-from: type=gha,scope=frontend
cache-to: type=gha,scope=frontend
backend:
name: "Backend checks"
runs-on: ubuntu-latest
env:
POETRY_VERSION: 1.8.4
POETRY_VIRTUALENVS_CREATE: 0
POETRY_HOME: ~/.local
POETRY_CACHE_DIR: ~/.cache/pypoetry
PRE_COMMIT_HOME: ~/.cache/pre-commit
SECRET_KEY: xxx
DATABASE_URL: postgres://postgres:postgres@localhost:5432/github_actions
# Majority of the tests require database
services:
postgres:
image: postgres:13.7
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: github_actions
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: "Checkout code"
uses: actions/checkout@v3
with:
# Disable shallow cloning to improving relevancy of reporting for SonarCloud
fetch-depth: 0
- name: "Set up Python 3.13"
id: setup-python
uses: actions/setup-python@v4
with:
python-version: "3.13"
- name: "Load cached dependencies and pre-commit hooks"
id: cache
uses: actions/cache@v4
with:
path: |
${{ env.pythonLocation }}
${{ env.POETRY_HOME }}
${{ env.POETRY_CACHE_DIR }}
${{ env.PRE_COMMIT_HOME }}
# Invalidate cache when any of these changes:
# - python version
# - poetry version
# - dependencies
# - pre-commit config
# - manually changed "cache-v1" prefix
key: cache-v1-${{ hashFiles('**/poetry.lock', '**/.pre-commit-config.yaml') }}-poetry${{ env.POETRY_VERSION }}-python${{ steps.setup-python.outputs.python-version }}
- name: "Install Poetry"
if: steps.cache.outputs.cache-hit != 'true'
run: curl -sSL https://install.python-poetry.org | python -
- name: "Add poetry install directory to path"
run: echo "${{ env.POETRY_HOME }}" >> $GITHUB_PATH
- name: "Install dependencies"
if: steps.cache.outputs.cache-hit != 'true'
run: >
cd backend
&& poetry install --no-root
- name: "Install pre-commit hook environments"
if: steps.cache.outputs.cache-hit != 'true'
run: >
cd backend
&& pre-commit install-hooks
- name: "Run pre-commit hooks against all files"
run: >
cd backend
&& pre-commit run --all-files
- name: "Test for migration issues"
run: >
cd backend
&& ./manage.py makemigrations --check --no-color --no-input --dry-run
- name: "Run tests and create coverage report"
run: >
cd backend
&& pytest -s -vvv --cov=. --cov-report=xml --cov-branch .
# Without this workaround Sonar reports a warning about an incorrect source path
- name: "Override coverage report source path for Sonar"
run: sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' backend/coverage.xml
- name: "SonarCloud Scan"
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
build-backend:
name: "Test building backend docker image"
runs-on: ubuntu-latest
steps:
- name: "Checkout code"
uses: actions/checkout@v3
- name: "Set up Docker Buildx"
uses: docker/setup-buildx-action@v3
- name: "Build backend container"
uses: docker/build-push-action@v2
with:
context: backend
push: false
tags: hitas-backend
cache-from: type=gha,scope=backend
cache-to: type=gha,scope=backend