[WIP] Try to speed up the CI for testing by building and caching in ghcr #5043
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: Test | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
on: | |
push: | |
branches: | |
- master | |
- release | |
pull_request: | |
permissions: | |
contents: read | |
packages: write | |
jobs: | |
lint: | |
if: '! github.event.pull_request.draft' | |
name: Lint code base | |
runs-on: ubuntu-24.04 | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Setup Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.12' | |
- name: Pre-commit | |
uses: pre-commit/action@v3.0.0 | |
build: | |
name: Build image | |
runs-on: ubuntu-24.04 | |
strategy: | |
fail-fast: true | |
matrix: | |
service_name: | |
- app | |
- nginx | |
- qgis | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Set up Docker BuildKit | |
run: echo "DOCKER_BUILDKIT=1" >> $GITHUB_ENV | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Login to Dockerhub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
- name: Build and push `qfieldcloud-${{ matrix.service_name }}` | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./docker-${{ matrix.service_name }} | |
file: ./docker-${{ matrix.service_name }}/Dockerfile | |
push: true | |
tags: ghcr.io/opengisch/qfieldcloud-${{ matrix.service_name }}:${{ github.sha }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push `qfieldcloud-worker_wrapper` (if needed) | |
if: ${{ matrix.service_name == 'app' }} | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./docker-app | |
file: ./docker-app/Dockerfile | |
target: 'worker_wrapper_runtime' | |
push: true | |
tags: ghcr.io/opengisch/qfieldcloud-worker_wrapper:${{ github.sha }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push `qfieldcloud-app-testing` (if needed) | |
if: ${{ matrix.service_name == 'app' }} | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./docker-app | |
file: ./docker-app/Dockerfile | |
target: 'webserver_test' | |
push: true | |
tags: ghcr.io/opengisch/qfieldcloud-app-testing:${{ github.sha }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
test: | |
name: Run tests | |
runs-on: ubuntu-24.04 | |
needs: | |
- build | |
strategy: | |
fail-fast: false | |
matrix: | |
django_app: | |
- authentication | |
# - notifs | |
# - subscription | |
# - core | |
# - __flaky__ | |
continue-on-error: true | |
env: | |
QFIELDCLOUD_IMAGE_NAME_FOR_APP: "ghcr.io/opengisch/qfieldcloud-app-testing:${{ github.sha }}" | |
QFIELDCLOUD_IMAGE_NAME_FOR_WORKER_WRAPPER: "ghcr.io/opengisch/qfieldcloud-worker_wrapper:${{ github.sha }}" | |
QFIELDCLOUD_IMAGE_NAME_FOR_QGIS: "ghcr.io/opengisch/qfieldcloud-qgis:${{ github.sha }}" | |
# TODO remove me | |
QFIELDCLOUD_QGIS_IMAGE_NAME: "ghcr.io/opengisch/qfieldcloud-qgis:${{ github.sha }}" | |
QFIELDCLOUD_IMAGE_NAME_FOR_NGINX: "ghcr.io/opengisch/qfieldcloud-nginx:${{ github.sha }}" | |
COMPOSE_FILE: docker-compose.yml:docker-compose.override.services.yml:docker-compose.override.test.yml | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Prepare the `.env` file | |
run: | | |
cp .env.example .env | |
- name: Check env vars configuration | |
run: | | |
scripts/check_envvars.sh | |
# - name: Pull docker containers | |
# run: docker compose pull | |
- name: Build and run docker containers | |
run: | | |
docker compose up -d | |
- name: Initial manage.py commands | |
run: | | |
docker compose run app python manage.py makemigrations --no-input --check | |
docker compose run app python manage.py migrate | |
docker compose run app python manage.py collectstatic | |
- name: Run mandatory unit and integration tests | |
if: matrix.django_app != '__flaky__' | |
run: | | |
docker compose run app python manage.py test --keepdb -v2 --exclude-tag="flaky" qfieldcloud.${{ matrix.django_app }} | |
- name: Run flaky unit and integration tests | |
if: matrix.django_app == '__flaky__' | |
run: | | |
docker compose run app python manage.py test --keepdb -v2 --tag="flaky" qfieldcloud | |
- name: Print failure logs | |
if: failure() | |
run: | | |
docker compose logs | |
- name: Post Google Chat message on failure | |
if: failure() && matrix.django_app != '__flaky__' | |
uses: julb/action-post-googlechat-message@v1 | |
with: | |
message: | | |
Failed job run for branch `${{ github.head_ref || github.ref_name }}`, check ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} . | |
gchat_webhook_url: ${{ secrets.GOOGLE_CHAT_WEBHOOK_URL }} | |
- name: Setup tmate session | |
if: ${{ failure() }} | |
uses: mxschmitt/action-tmate@v3 | |
timeout-minutes: 30 | |
with: | |
limit-access-to-actor: true |