Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZO-4513: Run tests (with batou) via GHA #605

Merged
merged 9 commits into from
Feb 6, 2024
31 changes: 31 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: pre-commit

on:
push:
branches:
- main
pull_request:

env:
PROJECT: vivi
BUILD_URL: "${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}"

concurrency: precommit_branch_${{github.ref_name}}

jobs:
pre-commit:
runs-on: zon-ubuntu-general-dind
permissions:
contents: read

steps:
- uses: actions/[email protected]
- uses: pre-commit/[email protected]

- uses: slackapi/[email protected]
if: failure() && github.ref_name == 'main'
with:
channel-id: "${{secrets.SLACK_TEAM_CONTENT_CHANNEL_ID}}"
slack-message: ":small_red_triangle_down: <${{env.BUILD_URL}}|${{env.PROJECT}}> tests failed"
env:
SLACK_BOT_TOKEN: ${{secrets.SLACK_BOT_TOKEN}}
178 changes: 178 additions & 0 deletions .github/workflows/testrunner.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
name: Testrunner

on:
push:
branches:
- main
pull_request:
schedule:
# XXX GHA unfortunately does not support randomize, so https://xkcd.com/221/
- cron: "22 4 * * *"
repository_dispatch: # triggered by ZeitOnline/zeit.newsimport
types: [test-app]

env:
project: vivi
build_url: "${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}"

concurrency: test_branch_${{github.ref_name}}

jobs:
test:
runs-on: zon-ubuntu-general-dind
permissions:
contents: read
checks: write
id-token: write

steps:
- uses: actions/[email protected]
- name: determine deployment branch
run: |
if [[ "${{github.ref_name}}" = "main" ]]; then
branch="main"
else
branch=$(echo -e "${{github.event.pull_request.body}}" | \
sed -ne '/JENKINS_BATOU_BRANCH=/s/JENKINS_BATOU_BRANCH=//p' | \
tr --delete ' \r\n')
if [[ -z "$branch" ]]; then
branch=main
fi
fi
echo "DEPLOYMENT_BRANCH=$branch" >> $GITHUB_ENV
- name: checkout deployment
uses: actions/[email protected]
with:
repository: ZeitOnline/vivi-deployment
ref: ${{env.DEPLOYMENT_BRANCH}}
path: deployment
# Has been added manually (both the key in vivi-deployment and
# the GHA secret in vivi)
ssh-key: ${{secrets.DEPLOY_KEY_DEPLOYMENT}}
- uses: ZeitOnline/[email protected]
with:
project_name: ${{env.project}}
environment: staging
gar_docker_auth: true # for docker pull dav-server
vault_export_token: true

- name: checkout vivi
run: |
mkdir -p deployment/work/source
ln -s $PWD deployment/work/source/vivi
# Keys have been added manually (both the key in the target repo and
# the GHA+Dependabot secret in vivi and vivi-deployment)
- name: checkout zeit.jabber
uses: actions/[email protected]
with:
repository: ZeitOnline/zeit.jabber
path: deployment/work/source/zeit.jabber
ssh-key: ${{secrets.DEPLOY_KEY_JABBER}}
- name: checkout zeit.ldap
uses: actions/[email protected]
with:
repository: ZeitOnline/zeit.ldap
path: deployment/work/source/zeit.ldap
ssh-key: ${{secrets.DEPLOY_KEY_LDAP}}
- name: checkout zeit.newsimport
uses: actions/[email protected]
with:
repository: ZeitOnline/zeit.newsimport
path: deployment/work/source/zeit.newsimport
ssh-key: ${{secrets.DEPLOY_KEY_NEWSIMPORT}}

- uses: actions/[email protected]
with:
python-version: "3.10"
cache: "pip"
cache-dependency-path: |
deployment/components/source/*.txt
- uses: actions/[email protected] # for jshint
with:
node-version: "20"
- name: setup apt
# firefox dependencies see https://github.com/microsoft/playwright/blob/main/packages/playwright-core/src/server/registry/nativeDeps.ts
# gcc for e.g. `pygraphviz`
# libxml/xslt will be superfluous after ZO-859
run: |
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update
sudo apt-get -y install --no-install-recommends \
libasound2 libatk1.0-0 libcairo-gobject2 libcairo2 libdbus-1-3 libdbus-glib-1-2 libfontconfig1 libfreetype6 libgdk-pixbuf-2.0-0 libglib2.0-0 libgtk-3-0 libpango-1.0-0 libpangocairo-1.0-0 libx11-6 libx11-xcb1 libxcb-shm0 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxtst6 \
build-essential graphviz-dev \
libxml2 libxslt1.1 \
pandoc
- uses: browser-actions/[email protected]
- name: setup geckodriver
run: |
curl -fsSL https://github.com/mozilla/geckodriver/releases/download/v0.34.0/geckodriver-v0.34.0-linux64.tar.gz \
| tar -xzv geckodriver && sudo mv geckodriver /usr/local/bin/geckodriver

- name: ./batou deploy local
run: |
cd deployment
./batou deploy gha
- name: display log output
if: failure()
run: |
for i in deployment/work/supervisor/var/log/*.log; do
echo $i
cat $i
done

- name: bin/test
run: |
# `pendulum` requires local timezone configuration
export TZ="Europe/Berlin"

if [[ "${{github.event_name}}" = "schedule" ]]; then
not_selenium='not selenium'
else
not_selenium='not selenium and not integration'
fi

set +e
deployment/bin/test -v -n 6 -m "$not_selenium" -r a \
--junitxml=report.xml --cov=. --cov-report=
result=$?

deployment/bin/test -v -n 4 -m 'selenium' --reruns=3 -r aR \
--junitxml=report_selenium.xml --cov=. \
--cov-append --cov-report=html
selenium=$?

if [[ "$result" = "0" ]]; then
result=$selenium
fi
exit $result

- name: Publish test result
uses: enricomi/[email protected]
if: always()
with:
comment_mode: "off"
files: "deployment/work/source/report*.xml"

- name: Publish coverage
uses: actions/[email protected]
id: coverage
with:
name: coverage-${{env.project}}
path: deployment/work/source/coverage-report
if-no-files-found: ignore
- name: Annotate coverage
uses: louisbrunner/[email protected]
with:
token: ${{secrets.GITHUB_TOKEN}} # unfortunately required
name: Coverage Report
conclusion: success
output: |
{"summary": "[Download](${{env.build_url}}/artifacts/${{steps.coverage.outputs.artifact-id}})"}

- uses: slackapi/[email protected]
if: failure() && github.ref_name == 'main' && github.event_name != 'schedule'
with:
channel-id: "${{secrets.SLACK_TEAM_CONTENT_CHANNEL_ID}}"
slack-message: ":small_red_triangle_down: <${{env.build_url}}|${{env.project}}> tests failed"
env:
SLACK_BOT_TOKEN: ${{secrets.SLACK_BOT_TOKEN}}
Loading