aboutsummaryrefslogtreecommitdiffstats
path: root/.github/workflows/test.yaml
blob: 591ed51fd7ba6f28f6b655134ef7b7a1b5c08749 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
on:
  workflow_call:
    inputs:
      artifact:
        required: true
        type: string
      version:
        required: true
        type: string

jobs:
  test:
    name: Test with coverage
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-22.04, ubuntu-24.04]

    steps:
      - name: Download image artifact
        uses: actions/download-artifact@v4
        with:
          name: ${{ inputs.artifact }}

      - name: Load image from archive
        run: docker load -i ${{ inputs.artifact }}.tar

      # Needed for the Docker Compose file.
      - name: Checkout code
        uses: actions/checkout@v4

      # Memory limit tests would fail if this isn't disabled.
      - name: Disable swap memory
        run: sudo swapoff -a

      # Run tests with coverage within the container.
      # Suffix the generated coverage datafile with the name of the runner's OS.
      - name: Run tests
        id: run_tests
        run: |
          export IMAGE_SUFFIX='-venv:${{ inputs.version }}'
          docker compose run \
            --rm -T -e COVERAGE_DATAFILE=.coverage.${{ matrix.os }} \
            --entrypoint coverage \
            snekbox \
            run -m unittest

      # Upload it so the coverage from all matrix jobs can be combined later.
      - name: Upload coverage data
        uses: actions/upload-artifact@v4
        with:
          name: coverage-${{ matrix.os }}
          path: .coverage.*
          retention-days: 1
          include-hidden-files: true

  report:
    name: Report coverage
    runs-on: ubuntu-latest
    needs: test

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.11"
          cache: pip
          cache-dependency-path: requirements/coverage.pip

      - name: Install dependencies
        run: pip install -U -r requirements/coverage.pip

      - name: Download coverage data
        uses: actions/download-artifact@v4
        with:
          pattern: coverage-*
          merge-multiple: true

      - name: Combine coverage data
        run: coverage combine .coverage.*

      - name: Display coverage report
        run: coverage report -m

      - name: Generate lcov report
        run: coverage lcov

      # Comment on the PR with the coverage results and register a GitHub check
      # which links to the coveralls.io job.
      - name: Publish coverage report to coveralls.io
        uses: coverallsapp/[email protected]
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          format: lcov

  dry-run-deploy:
    name: Dry run deployment.yaml init container
    runs-on: ubuntu-latest
    needs: test
    steps:
      - name: Download image artifact
        uses: actions/download-artifact@v4
        with:
          name: ${{ inputs.artifact }}

      - name: Load image from archive
        run: docker load -i ${{ inputs.artifact }}.tar

      # Needed for the Docker Compose file.
      - name: Checkout code
        uses: actions/checkout@v4

      # Install eval deps the same way as init container from deployment.yaml
      # This is to ensure that deployment won't fail at that step
      - name: Install eval deps
        run: |
          export IMAGE_SUFFIX='-venv:${{ inputs.version }}'
          docker compose run --rm -T --entrypoint /bin/bash snekbox scripts/install_eval_deps.sh