Repository: wagtail-nest/wagtail-hallo (language: python)

Issue:
Remove CircleCI - replace nightly with GitHub Actions
> ## CI setup
> 
> It feels overkill to me we’re using both CircleCI and GitHub Actions on this project. The main reason CircleCI is used for Wagtail core is because we have so many frequent builds on GitHub Actions – so it’s nice to have basic linting finishing sooner. For a brand new project that will get little activity, I’d prefer we use GitHub Actions only.
> 
> Further notes on the CI setup:
> 
>     * The way the nightly jobs are defined in CircleCI is [deprecated](https://circleci.com/docs/2.0/workflows/#scheduling-a-workflow), and will stop working in June. We should either move this to GitHub Actions, or if we want to keep using CircleCI, use their new scheduling support.
>

_Originally posted by @lb- in https://github.com/wagtail/wagtail-hallo/issues/9#issuecomment-1056739234_


Discussion / hints:
As an example, @zerolab has done this in GitHub Actions for `wagtailmedia`:

- https://github.com/torchbox/wagtailmedia/blob/main/.github/workflows/nightly-tests.yml
- https://github.com/torchbox/wagtailmedia/blob/main/.github/report_nightly_build_failure.py
Also documented on https://github.com/wagtail/wagtail/wiki/Nightly-testing-of-official-plugins

Fix patch:
diff --git a/.circleci/config.yml b/.circleci/config.yml
deleted file mode 100644
index 2fb57c3..0000000
--- a/.circleci/config.yml
+++ /dev/null
@@ -1,94 +0,0 @@
-version: 2
-
-jobs:
-  black:
-    docker:
-      - image: circleci/python:3.9
-    steps:
-      - checkout
-      - run: pip install black
-      - run: black wagtail_hallo --check
-
-  flake8:
-    docker:
-      - image: circleci/python:3.9
-    steps:
-      - checkout
-      - run: pip install flake8
-      - run: flake8 wagtail_hallo
-
-  preflight:
-    docker:
-      - image: circleci/node:16
-    steps:
-      - checkout:
-
-      - type: cache-restore
-        keys:
-          - node-modules-{{ .Branch }}-{{ checksum "package-lock.json" }}
-          - node-modules-{{ .Branch }}-
-          - node-modules-master-
-
-      - run: npm ci
-      - run: npm run preflight
-
-      - type: cache-save
-        key: node-modules-{{ .Branch }}-{{ checksum "package-lock.json" }}
-        paths:
-          - 'node_modules'
-
-  test:
-    docker:
-      - image: circleci/python:3.9
-    steps:
-      - checkout
-
-      - type: cache-restore
-        keys:
-          - pip-{{ .Branch }}-
-          - pip-master-
-
-      - run: pip install -e .[testing]
-
-      - type: cache-save
-        key: pip-{{ .Branch }}-{{ epoch }}
-        paths:
-          - '~/.cache/pip'
-
-      - run: python testmanage.py test
-
-  nightly-wagtail-test:
-    docker:
-      - image: circleci/python:3.9
-    steps:
-      - checkout
-      - run: git clone git@github.com:wagtail/wagtail.git
-
-      - run: pip install -e .[testing]
-      - run: pip install ./wagtail
-
-      - run: python testmanage.py test
-
-      - run:
-          when: on_fail
-          command: python ./.circleci/report_nightly_build_failure.py
-
-workflows:
-  version: 2
-  test:
-    jobs:
-      - black
-      - flake8
-      - prettier
-      - test
-
-  nightly:
-    jobs:
-      - nightly-wagtail-test
-    triggers:
-      - schedule:
-          cron: '0 0 * * *'
-          filters:
-            branches:
-              only:
-                - master
diff --git a/.circleci/report_nightly_build_failure.py b/.circleci/report_nightly_build_failure.py
deleted file mode 100644
index eb1cba5..0000000
--- a/.circleci/report_nightly_build_failure.py
+++ /dev/null
@@ -1,23 +0,0 @@
-"""
-Called by CircleCI 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:
-    print("Reporting to #nightly-build-failures slack channel")
-    response = requests.post(
-        os.environ["SLACK_WEBHOOK_URL"],
-        json={
-            "text": "A Nightly build failed. See " + os.environ["CIRCLE_BUILD_URL"],
-        },
-    )
-
-    print("Slack responded with:", response)
-
-else:
-    print(
-        "Unable to report to #nightly-build-failures slack channel because SLACK_WEBHOOK_URL is not set"
-    )
diff --git a/.circleci/trigger-nightly-build.sh b/.circleci/trigger-nightly-build.sh
deleted file mode 100755
index 6cc6caf..0000000
--- a/.circleci/trigger-nightly-build.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/bash
-# Triggers a test run against the master version of Wagtail
-
-# This job will is scheduled in the config.yml, this script is here to help test the job
-
-curl -u ${CIRCLE_API_USER_TOKEN}: \
-     -d build_parameters[CIRCLE_JOB]=nightly-wagtail-test \
-     https://circleci.com/api/v1.1/project/github/wagtail/wagtail-hallo/tree/master
diff --git a/.github/report_nightly_build_failure.py b/.github/report_nightly_build_failure.py
new file mode 100644
index 0000000..29ceca9
--- /dev/null
+++ b/.github/report_nightly_build_failure.py
@@ -0,0 +1,27 @@
+"""
+Called by GitHub Actions 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"
+    )


Test patch:
diff --git a/.github/workflows/nightly-tests.yml b/.github/workflows/nightly-tests.yml
new file mode 100644
index 0000000..35f2abb
--- /dev/null
+++ b/.github/workflows/nightly-tests.yml
@@ -0,0 +1,51 @@
+name: Nightly Wagtail test
+
+on:
+  schedule:
+    - cron: '0 0 * * *'
+
+  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/wagtail-hallo' }}
+    runs-on: ubuntu-latest
+
+    services:
+      postgres:
+        image: postgres:10.8
+        ports:
+          - 5432:5432
+        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
+
+    steps:
+      - uses: actions/checkout@v2
+      - name: Set up Python 3.9
+        uses: actions/setup-python@v2
+        with:
+          python-version: 3.9
+      - name: Install dependencies
+        run: |
+          python -m pip install --upgrade pip
+          pip install "psycopg2>=2.6"
+          pip install "git+https://github.com/wagtail/wagtail.git@main#egg=wagtail"
+          pip install -e .[testing]
+      - name: Test
+        id: test
+        continue-on-error: true
+        run: |
+          ./runtests.py
+        env:
+          DATABASE_ENGINE: django.db.backends.postgresql
+          DATABASE_HOST: localhost
+          DATABASE_USER: postgres
+          DATABASE_PASS: postgres
+
+      - 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 }}