mirror of
https://github.com/UniversityOfHelsinkiCS/oodikone.git
synced 2026-10-12 19:03:39 +03:00
439 lines
14 KiB
YAML
439 lines
14 KiB
YAML
name: 'Lint and test'
|
|
|
|
on:
|
|
workflow_call:
|
|
secrets:
|
|
username:
|
|
required: true
|
|
description: 'Toska registry username'
|
|
password:
|
|
required: true
|
|
description: 'Toska registry password'
|
|
|
|
jobs:
|
|
# === Static tests / linting ===
|
|
lint_packages:
|
|
name: 'Lint packages'
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
- name: Lint backend, frontend and shared
|
|
uses: ./.github/actions/lint
|
|
|
|
# === Build database images ===
|
|
build_backend:
|
|
name: 'Build backend'
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
- uses: docker/setup-buildx-action@v4
|
|
- name: 'Build image and export it'
|
|
uses: docker/build-push-action@v7
|
|
with:
|
|
build-args: |
|
|
SENTRY_RELEASE=${{ github.sha }}
|
|
SENTRY_ENVIRONMENT=staging
|
|
context: services
|
|
file: services/backend/Dockerfile
|
|
push: false
|
|
tags: oodikone-backend:staging
|
|
outputs: type=docker,dest=/tmp/backend.tar
|
|
env:
|
|
DOCKER_BUILD_SUMMARY: false
|
|
|
|
- name: 'Upload image for other jobs'
|
|
uses: actions/upload-artifact@v7
|
|
with:
|
|
if-no-files-found: error
|
|
name: backend-image
|
|
path: /tmp/backend.tar
|
|
|
|
build_frontend:
|
|
name: 'Build frontend'
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
- uses: docker/setup-buildx-action@v4
|
|
|
|
- name: Get current time
|
|
id: get_current_time
|
|
run: echo "NOW=$(date --iso-8601=seconds)" >> $GITHUB_OUTPUT
|
|
|
|
- name: Build frontend image
|
|
uses: docker/build-push-action@v7
|
|
with:
|
|
build-args: |
|
|
BUILT_AT=${{ steps.get_current_time.outputs.NOW }}
|
|
BASE_PATH=/oodikone
|
|
STAGING=true
|
|
context: services
|
|
file: services/frontend/Dockerfile
|
|
push: false
|
|
tags: oodikone-frontend:staging
|
|
outputs: type=docker,dest=/tmp/frontend.tar
|
|
env:
|
|
DOCKER_BUILD_SUMMARY: false
|
|
|
|
# - name: 'Upload image for other jobs'
|
|
# uses: actions/upload-artifact@v7
|
|
# with:
|
|
# if-no-files-found: error
|
|
# name: frontend-image
|
|
# path: /tmp/frontend.tar
|
|
|
|
pull_docker_images:
|
|
name: 'Pull all needed docker images and cache them'
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
- name: 'Login to toska docker registry'
|
|
uses: docker/login-action@v4
|
|
with:
|
|
registry: registry-toska.ext.ocp-prod-0.k8s.it.helsinki.fi
|
|
username: ${{ secrets.username }}
|
|
password: ${{ secrets.password }}
|
|
|
|
- name: 'Pull required images'
|
|
run: docker compose --file docker-compose.ci.yml --profile oodikone --profile updater pull --ignore-buildable --quiet
|
|
|
|
- name: 'Save Docker images for downstream jobs'
|
|
run: |
|
|
docker save \
|
|
registry-toska.ext.ocp-prod-0.k8s.it.helsinki.fi/kone-db \
|
|
registry-toska.ext.ocp-prod-0.k8s.it.helsinki.fi/sis-db \
|
|
registry-toska.ext.ocp-prod-0.k8s.it.helsinki.fi/user-db \
|
|
redis:7.2.6 \
|
|
postgres:15.10 \
|
|
"quay.io/toska/jami:production" \
|
|
nginx:latest \
|
|
| zstd -T0 -3 -o /tmp/docker-images.tar.zst
|
|
|
|
- name: 'Upload Docker images artifact'
|
|
uses: actions/upload-artifact@v7
|
|
with:
|
|
name: docker-images
|
|
path: /tmp/docker-images.tar.zst
|
|
retention-days: 1
|
|
|
|
# === Update databases ===
|
|
check_migration_files:
|
|
name: Check if new migrations have been added
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
kone_db_migrations: ${{ steps.check_migrations.outputs.kone_db_migrations }}
|
|
user_db_migrations: ${{ steps.check_migrations.outputs.user_db_migrations }}
|
|
sis_db_migrations: ${{ steps.check_migrations.outputs.sis_db_migrations }}
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
- name: Check if new migrations have been added
|
|
id: check_migrations
|
|
uses: dorny/paths-filter@v3
|
|
with:
|
|
filters: |
|
|
kone_db_migrations:
|
|
- 'services/backend/src/database/migrations_kone/**'
|
|
- '.github/workflows/test.yaml'
|
|
user_db_migrations:
|
|
- 'services/backend/src/database/migrations_user/**'
|
|
- '.github/workflows/test.yaml'
|
|
sis_db_migrations:
|
|
- 'updater/sis-updater-worker/src/db/migrations/**'
|
|
- '.github/workflows/test.yaml'
|
|
|
|
build_and_push_anon_sis_db:
|
|
name: 'Build anon sis-db and push to toska hub if new migrations have been added'
|
|
needs:
|
|
- pull_docker_images
|
|
- check_migration_files
|
|
runs-on: ubuntu-latest
|
|
if: needs.check_migration_files.outputs.sis_db_migrations == 'true'
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
- name: 'Login to toska docker registry'
|
|
uses: docker/login-action@v4
|
|
with:
|
|
registry: registry-toska.ext.ocp-prod-0.k8s.it.helsinki.fi
|
|
username: ${{ secrets.username }}
|
|
password: ${{ secrets.password }}
|
|
|
|
- name: 'Download Docker images'
|
|
uses: actions/download-artifact@v8
|
|
with:
|
|
name: docker-images
|
|
path: /tmp
|
|
|
|
- name: 'Load Docker images'
|
|
run: zstd -d /tmp/docker-images.tar.zst --stdout | docker load
|
|
|
|
- name: 'Let sis-updater-worker run migrations, then push new version of image to toska hub'
|
|
run: |
|
|
docker compose --file docker-compose.ci.yml up --detach --quiet-pull sis-updater-worker
|
|
sleep 30 # wait for sis-updater-worker to start and run migrations
|
|
./anonyymioodi/commit_and_push_to_toska_hub.sh sis-db
|
|
|
|
build_and_push_anon_kone_db:
|
|
name: 'Build anon kone-db and push to toska hub if new migrations have been added'
|
|
needs:
|
|
- pull_docker_images
|
|
- build_backend
|
|
- build_frontend
|
|
- check_migration_files
|
|
runs-on: ubuntu-latest
|
|
if: needs.check_migration_files.outputs.kone_db_migrations == 'true'
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
|
|
- name: 'Download Docker images'
|
|
uses: actions/download-artifact@v8
|
|
with:
|
|
name: docker-images
|
|
path: /tmp
|
|
- name: 'Download backend image'
|
|
uses: actions/download-artifact@v8
|
|
with:
|
|
name: backend-image
|
|
|
|
- name: 'Load Docker images'
|
|
run: zstd -d /tmp/docker-images.tar.zst --stdout | docker load
|
|
- name: 'Load built backend image'
|
|
run: docker load --input backend.tar
|
|
|
|
- name: 'Login to toska docker registry'
|
|
uses: docker/login-action@v4
|
|
with:
|
|
registry: registry-toska.ext.ocp-prod-0.k8s.it.helsinki.fi
|
|
username: ${{ secrets.username }}
|
|
password: ${{ secrets.password }}
|
|
|
|
- name: 'Let backend run migrations, then push new version of image to toska hub'
|
|
run: |
|
|
docker compose --file docker-compose.ci.yml up --detach backend
|
|
sleep 30 # wait for backend to start and run migrations
|
|
./anonyymioodi/commit_and_push_to_toska_hub.sh kone-db
|
|
|
|
build_and_push_anon_user_db:
|
|
name: 'Build anon user-db and push to toska hub if new migrations have been added'
|
|
needs:
|
|
- pull_docker_images
|
|
- build_backend
|
|
- build_frontend
|
|
- check_migration_files
|
|
runs-on: ubuntu-latest
|
|
if: needs.check_migration_files.outputs.user_db_migrations == 'true'
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
- uses: dorny/paths-filter@v3
|
|
id: check_migrations
|
|
with:
|
|
filters: |
|
|
migrations:
|
|
- 'services/backend/src/database/migrations_user/**'
|
|
- '.github/workflows/test.yaml'
|
|
|
|
- name: 'Download Docker images'
|
|
uses: actions/download-artifact@v8
|
|
with:
|
|
name: docker-images
|
|
path: /tmp
|
|
- name: 'Download backend image'
|
|
uses: actions/download-artifact@v8
|
|
with:
|
|
name: backend-image
|
|
|
|
- name: 'Load Docker images'
|
|
run: zstd -d /tmp/docker-images.tar.zst --stdout | docker load
|
|
- name: 'Load built backend image'
|
|
run: docker load --input backend.tar
|
|
|
|
- name: 'Login to toska docker registry'
|
|
uses: docker/login-action@v4
|
|
with:
|
|
registry: registry-toska.ext.ocp-prod-0.k8s.it.helsinki.fi
|
|
username: ${{ secrets.username }}
|
|
password: ${{ secrets.password }}
|
|
|
|
- name: 'Let backend run migrations, then push new version of image to toska hub'
|
|
run: |
|
|
docker compose --file docker-compose.ci.yml up --detach backend
|
|
sleep 30 # wait for backend to start and run migrations
|
|
./anonyymioodi/commit_and_push_to_toska_hub.sh user-db
|
|
|
|
# === Backend api-tests ===
|
|
test_api:
|
|
needs:
|
|
- pull_docker_images
|
|
- build_and_push_anon_sis_db
|
|
- build_and_push_anon_kone_db
|
|
- build_and_push_anon_user_db
|
|
- lint_packages
|
|
if: always() && !cancelled() && needs.lint_packages.result == 'success'
|
|
strategy:
|
|
fail-fast: false
|
|
runs-on: ubuntu-24.04
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v6
|
|
|
|
- name: Install node-24
|
|
uses: actions/setup-node@v6
|
|
with:
|
|
node-version: 24
|
|
|
|
- name: 'Download Docker images'
|
|
uses: actions/download-artifact@v8
|
|
with:
|
|
name: docker-images
|
|
path: /tmp
|
|
|
|
- name: 'Load Docker images'
|
|
run: zstd -d /tmp/docker-images.tar.zst --stdout | docker load
|
|
|
|
- name: 'Login to toska docker registry'
|
|
uses: docker/login-action@v4
|
|
with:
|
|
registry: registry-toska.ext.ocp-prod-0.k8s.it.helsinki.fi
|
|
username: ${{ secrets.username }}
|
|
password: ${{ secrets.password }}
|
|
|
|
- name: Start oodikone (without frontend and backend)
|
|
run: npm run oodikone:ci:setup -- --quiet-pull
|
|
|
|
- name: Run api-tests
|
|
run: npm run oodikone:ci:api
|
|
|
|
# === End-to-end tests ===
|
|
test_end_to_end:
|
|
needs:
|
|
- pull_docker_images
|
|
- build_and_push_anon_sis_db
|
|
- build_and_push_anon_kone_db
|
|
- build_and_push_anon_user_db
|
|
- lint_packages
|
|
if: always() && !cancelled() && needs.lint_packages.result == 'success'
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- name: 'Test course statistics'
|
|
spec: cypress/e2e/Course_statistics.js
|
|
- name: 'Test custom population'
|
|
spec: cypress/e2e/Custom_population.js
|
|
- name: 'Test population statistics'
|
|
spec: cypress/e2e/Population_statistics.js
|
|
- name: 'Test filters'
|
|
spec: cypress/e2e/Filters.js
|
|
- name: 'Test students'
|
|
spec: cypress/e2e/Students.js
|
|
- name: 'Test completed courses'
|
|
spec: cypress/e2e/Completed_courses.js
|
|
- name: 'Test degree programme overview'
|
|
spec: cypress/e2e/Degree_programme_overview.js
|
|
- name: 'Test teachers and users'
|
|
spec: |
|
|
cypress/e2e/Teachers.js
|
|
cypress/e2e/Users.js
|
|
- name: 'Test faculty statistics'
|
|
spec: cypress/e2e/Faculty_statistics.js
|
|
- name: 'Test language center view'
|
|
spec: cypress/e2e/Language_center.js
|
|
- name: 'Test study guidance groups'
|
|
spec: cypress/e2e/Study_guidance_groups.js
|
|
- name: 'Test university'
|
|
spec: cypress/e2e/University.js
|
|
|
|
name: ${{ matrix.name }}
|
|
runs-on: ubuntu-24.04
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v6
|
|
|
|
- name: Install node-24 for cypress
|
|
uses: actions/setup-node@v6
|
|
with:
|
|
node-version: 24
|
|
|
|
- name: 'Download Docker images'
|
|
uses: actions/download-artifact@v8
|
|
with:
|
|
name: docker-images
|
|
path: /tmp
|
|
- name: 'Download backend image'
|
|
uses: actions/download-artifact@v8
|
|
with:
|
|
name: backend-image
|
|
# - name: 'Download frontend image'
|
|
# uses: actions/download-artifact@v8
|
|
# with:
|
|
# name: frontend-image
|
|
|
|
- name: 'Load Docker images'
|
|
run: zstd -d /tmp/docker-images.tar.zst --stdout | docker load
|
|
- name: 'Load built backend image'
|
|
run: docker load --input backend.tar
|
|
# - name: 'Load built frontend image'
|
|
# run: docker load --input frontend.tar
|
|
|
|
- name: 'Run tests'
|
|
uses: ./.github/actions/run-tests
|
|
with:
|
|
username: ${{ secrets.username }}
|
|
password: ${{ secrets.password }}
|
|
spec: ${{ matrix.spec }}
|
|
test_name: ${{ matrix.name }}
|
|
|
|
# === Other tests ===
|
|
test_service_exit_statuses:
|
|
name: 'Check services run correctly'
|
|
needs:
|
|
- pull_docker_images
|
|
- build_and_push_anon_sis_db
|
|
- build_and_push_anon_kone_db
|
|
- build_and_push_anon_user_db
|
|
- lint_packages
|
|
if: always() && !cancelled() && needs.lint_packages.result == 'success'
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
- name: 'Login to toska docker registry'
|
|
uses: docker/login-action@v4
|
|
with:
|
|
registry: registry-toska.ext.ocp-prod-0.k8s.it.helsinki.fi
|
|
username: ${{ secrets.username }}
|
|
password: ${{ secrets.password }}
|
|
|
|
- name: 'Download Docker images'
|
|
uses: actions/download-artifact@v8
|
|
with:
|
|
name: docker-images
|
|
path: /tmp
|
|
- name: 'Download backend image'
|
|
uses: actions/download-artifact@v8
|
|
with:
|
|
name: backend-image
|
|
# - name: 'Download frontend image'
|
|
# uses: actions/download-artifact@v8
|
|
# with:
|
|
# name: frontend-image
|
|
|
|
- name: 'Load Docker images'
|
|
run: zstd -d /tmp/docker-images.tar.zst --stdout | docker load
|
|
- name: 'Load built backend image'
|
|
run: docker load --input backend.tar
|
|
# - name: 'Load built frontend image'
|
|
# run: docker load --input frontend.tar
|
|
|
|
- name: 'Run services, build rest of the needed images'
|
|
run: docker compose --file docker-compose.ci.yml --profile oodikone up --detach --quiet-pull
|
|
|
|
- name: 'Check that exit statuses are not errors'
|
|
run: |
|
|
docker ps -a
|
|
if [[ $(docker ps --all | grep -Eo '(Exited|Restarting) \([0-9]+\)' | grep -Eo '[0-9]+' | awk 'BEGIN {sum=0} { sum += $1 } END { print sum }') != '0' ]]; then
|
|
echo 'Some process had nonzero exit code';
|
|
exit 1;
|
|
fi
|
|
|
|
- name: 'Print logs on failure'
|
|
if: failure()
|
|
run: docker compose --file docker-compose.ci.yml --profile oodikone logs && sleep 15
|