aboutsummaryrefslogtreecommitdiffstats
path: root/.github/workflows/test.yaml
blob: 30e6ba338f8e05d2b8c01e64ff32d14d3e931776 (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
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-20.04, self-hosted]

    steps:
      - name: Download image artifact
        uses: actions/download-artifact@v2
        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@v2

      # 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@v2
        with:
          name: coverage
          path: .coverage.*
          retention-days: 1

      # Self-hosted runner needs containers, images, networks, volumes, etc.
      # removed because they persist across runs and may interfere.
      - name: Docker cleanup
        if: matrix.os == 'self-hosted' && always()
        run: |
          export IMAGE_SUFFIX='-venv:${{ inputs.version }}'
          docker-compose down --rmi all --remove-orphans -v -t 0

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

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

      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: "3.10"
          cache: pip
          cache-dependency-path: requirements/coveralls.pip

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

      - name: Download coverage data
        uses: actions/download-artifact@v2
        with:
          name: coverage

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

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

      # 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
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: coveralls --service=github