Fix pytest.yml GH workflow (#786) #1309
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: pytest | |
on: | |
pull_request_target: | |
branches: | |
- "**" | |
push: | |
branches: | |
- master | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- uses: actions/checkout@v4 | |
name: Check out repository | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Create dirs and files | |
run: | | |
mkdir -p /home/runner/work/albs-web-server/alts | |
mkdir -p /home/runner/work/albs-web-server/albs-frontend | |
mkdir -p /home/runner/work/albs-web-server/albs-node | |
mkdir -p /home/runner/work/albs-web-server/albs-sign-file | |
mkdir -p /home/runner/work/albs-web-server/albs-sign-node | |
mkdir -p /home/runner/work/albs-web-server/alma-tests-cacher | |
touch /home/runner/work/albs-web-server/alma-tests-cacher/vars.env | |
touch /home/runner/work/albs-web-server/albs-sign-file/.env | |
- name: Add env file | |
run: | | |
touch ./vars.env | |
echo ALTS_TOKEN="secret" >> ./vars.env | |
echo ALMALINUX_CLIENT="secret" >> ./vars.env | |
echo ALMALINUX_CLIENT_SECRET="secret" >> ./vars.env | |
echo GITHUB_CLIENT="secret" >> ./vars.env | |
echo GITHUB_CLIENT_SECRET="secret" >> ./vars.env | |
echo POSTGRES_PASSWORD="password" >> ./vars.env | |
echo JWT_SECRET="secret" >> ./vars.env | |
echo POSTGRES_DB="test-almalinux-bs" >> ./vars.env | |
echo PACKAGE_BEHOLDER_ENABLED="False" >> ./vars.env | |
echo DATABASE_URL="postgresql+asyncpg://postgres:password@db/test-almalinux-bs" >> ./vars.env | |
echo SYNC_DATABASE_URL="postgresql+psycopg2://postgres:password@db/test-almalinux-bs" >> ./vars.env | |
echo PULP_DATABASE_URL="postgresql+psycopg2://postgres:password@db/test-almalinux-bs" >> ./vars.env | |
echo FASTAPI_SQLA__PULP__SQLALCHEMY_URL="postgresql+psycopg2://postgres:password@db/test-almalinux-bs" >> ./vars.env | |
echo FASTAPI_SQLA__PULP__SQLALCHEMY_POOL_PRE_PING=True >> ./vars.env | |
echo FASTAPI_SQLA__PULP__SQLALCHEMY_POOL_RECYCLE=3600 >> ./vars.env | |
echo FASTAPI_SQLA__ASYNC__SQLALCHEMY_URL="postgresql+asyncpg://postgres:password@db/test-almalinux-bs" >> ./vars.env | |
echo FASTAPI_SQLA__ASYNC__SQLALCHEMY_ECHO_POOL=True >> ./vars.env | |
echo FASTAPI_SQLA__TEST__SQLALCHEMY_URL="postgresql+asyncpg://postgres:password@db/test-almalinux-bs" >> ./vars.env | |
echo SQLALCHEMY_URL="postgresql+psycopg2://postgres:password@db/test-almalinux-bs" >> ./vars.env | |
echo SQLALCHEMY_POOL_PRE_PING=True >> ./vars.env | |
echo SQLALCHEMY_POOL_RECYCLE=3600 >> ./vars.env | |
cat alws/alembic.ini | sed 's/almalinux-bs/test-almalinux-bs/' | tee alws/alembic.ini | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
load: true | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Start services | |
run: docker compose up -d --no-deps web_server db | |
- name: Run unit tests (pytest) | |
run: docker compose run -v /tmp:/tmp --no-deps web_server bash -o pipefail -c ' | |
pytest -vv --ignore alws/ --cov-report term-missing:skip-covered | |
--cov-report xml:/tmp/coverage.xml --junitxml=/tmp/pytest.xml --cov=alws | |
tests/ | tee /tmp/pytest-coverage.txt' | |
- name: Stop services | |
run: docker compose down --volumes | |
- name: Pytest coverage comment | |
uses: MishaKav/pytest-coverage-comment@main | |
id: coverageComment | |
with: | |
pytest-coverage-path: /tmp/pytest-coverage.txt | |
pytest-xml-coverage-path: /tmp/coverage.xml | |
title: Coverage report for changed files | |
badge-title: Total coverage | |
hide-badge: false | |
hide-report: false | |
report-only-changed-files: true | |
hide-comment: false | |
remove-link-from-badge: false | |
junitxml-path: /tmp/pytest.xml | |
- name: Create the Badge | |
if: ${{ github.ref == 'refs/heads/master' && steps.coverageComment.outputs.coverage }} | |
uses: schneegans/dynamic-badges-action@v1.7.0 | |
with: | |
auth: ${{ secrets.GIST_SECRET }} | |
gistID: 7894f3c3bd830eb5456d45c9dacc0f93 | |
filename: pytest-coverage-comment__web-server__main.json | |
label: Test Coverage | |
message: ${{ steps.coverageComment.outputs.coverage }} | |
color: ${{ steps.coverageComment.outputs.color }} | |
namedLogo: pytest |