diff --git a/.github/workflows/test-base.yaml b/.github/workflows/test-base.yaml new file mode 100644 index 0000000..8fe40ca --- /dev/null +++ b/.github/workflows/test-base.yaml @@ -0,0 +1,46 @@ +name: Test + +on: + workflow_call: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ hashFiles('Pipfile.lock', 'compose/local/django/Dockerfile') }} + restore-keys: | + ${{ runner.os }}-buildx- + - name: Bake docker images + uses: docker/bake-action@v4 + with: + load: true + set: | + *.cache-from=type=local,src=/tmp/.buildx-cache + *.cache-to=type=local,dest=/tmp/.buildx-cache-new + files: docker-compose.local.yaml + + - name: Start services + run: docker compose -f docker-compose.local.yaml up -d --wait --no-build + + - name: Check migrations + run: make checkmigration + + # - name: Run tests + # run: make test-coverage + + # - name: Upload coverage report + # uses: codecov/codecov-action@v3 + + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..2ad1168 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,12 @@ +name: Test PR + +on: + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + test: + uses: ./.github/workflows/test-base.yaml diff --git a/Makefile b/Makefile index aa31b0a..209e88c 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,9 @@ logs: makemigrations: up docker exec django bash -c "python manage.py makemigrations" + +checkmigration: + docker compose -f $(docker_config_file) exec django bash -c "python manage.py makemigrations --check --dry-run" test: up docker exec django bash -c "python manage.py test --keepdb --parallel=$(nproc)" diff --git a/compose/local/django/Dockerfile b/compose/local/django/Dockerfile index a4d2882..432fd92 100644 --- a/compose/local/django/Dockerfile +++ b/compose/local/django/Dockerfile @@ -22,7 +22,7 @@ RUN pip install pipenv # Requirements are installed here to ensure they will be cached. COPY Pipfile Pipfile.lock ./ -RUN pipenv sync --system --categories "packages" +RUN pipenv sync --system --categories "packages dev-packages" # Python 'run' stage FROM python as python-run-stage