From c4b13b89112dbce4fe0be71eab7c68ba03a86659 Mon Sep 17 00:00:00 2001 From: "Storm B. Heg" Date: Thu, 5 Oct 2023 18:00:57 +0200 Subject: [PATCH] Add nightly workflow Split test against wagtaimain into a postgres and a sqlite variant. --- .github/report_nightly_build_failure.py | 30 ++++++++++++++ .github/workflows/nightly-tests.yml | 54 +++++++++++++++++++++++++ .github/workflows/test.yml | 5 ++- tox.ini | 8 ++-- 4 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 .github/report_nightly_build_failure.py create mode 100644 .github/workflows/nightly-tests.yml diff --git a/.github/report_nightly_build_failure.py b/.github/report_nightly_build_failure.py new file mode 100644 index 0000000..5b73a40 --- /dev/null +++ b/.github/report_nightly_build_failure.py @@ -0,0 +1,30 @@ +""" +Called by GitHub Action when the nightly build fails. + +This reports an error to the #nightly-build-failures Slack channel. +""" +import os + +import requests + + +if "SLACK_WEBHOOK_URL" in os.environ: + # https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables#default-environment-variables + repository = os.environ["GITHUB_REPOSITORY"] + run_id = os.environ["GITHUB_RUN_ID"] + url = f"https://github.com/{repository}/actions/runs/{run_id}" + + print("Reporting to #nightly-build-failures slack channel") + response = requests.post( + os.environ["SLACK_WEBHOOK_URL"], + json={ + "text": f"A Nightly build failed. See {url}", + }, + ) + + print(f"Slack responded with: {response}") + +else: + print( + "Unable to report to #nightly-build-failures slack channel because SLACK_WEBHOOK_URL is not set" + ) \ No newline at end of file diff --git a/.github/workflows/nightly-tests.yml b/.github/workflows/nightly-tests.yml new file mode 100644 index 0000000..ba52be2 --- /dev/null +++ b/.github/workflows/nightly-tests.yml @@ -0,0 +1,54 @@ +name: Nightly Wagtail test +# Inspired by: https://github.com/torchbox/wagtailmedia/blob/main/.github/workflows/nightly-tests.yml + +on: + schedule: + # Run every Monday at midnight + - cron: "0 0 * * 1" + + workflow_dispatch: + +jobs: + nightly-test: + # Cannot check the existence of secrets, so limiting to repository name to prevent all forks to run nightly. + # See: https://github.com/actions/runner/issues/520 + if: ${{ github.repository == 'wagtail-nest/wagtail-ab-testing' }} + runs-on: ubuntu-latest + + services: + postgres: + image: postgres:16 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/setup-python@v4 + with: + python-version: "3.11" + - name: Install dependencies + run: | + python -m pip install tox requests + - name: Test + id: test + continue-on-error: true + env: + DATABASE_URL: postgres://postgres:postgres@localhost/wagtail_ab_testing + run: | + tox -e wagtailmain-postgres,wagtailmain-sqlite + + - name: Send Slack notification on failure + if: steps.test.outcome == 'failure' + run: | + python .github/report_nightly_build_failure.py + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1880985..88b5b6b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -59,7 +59,10 @@ jobs: experimental: false # Future Wagtail release from main branch (allowed to fail) - python: "3.11" - toxenv: wagtailmain + toxenv: wagtailmain-sqlite + experimental: true + - python: "3.11" + toxenv: wagtailmain-postgres experimental: true steps: - uses: actions/checkout@v4 diff --git a/tox.ini b/tox.ini index 70e35ca..e0ddda8 100644 --- a/tox.ini +++ b/tox.ini @@ -46,8 +46,10 @@ deps=flake8>=2.2.0 commands=flake8 wagtail_ab_testing [testenv:wagtailmain] -basepython=python3.11 -commands = coverage run -p testmanage.py test --deprecation all --noinput deps= coverage - wagtailmain: git+https://github.com/wagtail/wagtail.git \ No newline at end of file + git+https://github.com/wagtail/wagtail.git + postgres: psycopg2>=2.9 + +setenv = + postgres: DATABASE_URL={env:DATABASE_URL:postgres:///wagtail_ab_testing}