Repository navigation
86 lines (83 loc) · 3.33 KB
/
Copy pathmutation.yml
File metadata and controls
86 lines (83 loc) · 3.33 KB
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
name: Mutation Testing
on:
workflow_dispatch:
inputs:
packages:
description: >
Space-separated list of packages to mutate.
Default: all five core packages.
required: false
default: >-
./pkg/mapdoc
./pkg/treehash
./pkg/providerjoin
./pkg/sariflocate
./pkg/mapdiff
timeout_coefficient:
description: >
Gremlins timeout coefficient (multiples of baseline test time).
Increase if many mutants time out.
required: false
default: '20'
permissions:
contents: read
jobs:
mutate:
runs-on: ubuntu-latest
timeout-minutes: 60
env:
PACKAGES_INPUT: ${{ inputs.packages }}
TIMEOUT_INPUT: ${{ inputs.timeout_coefficient }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod
cache: true
cache-dependency-path: go.sum
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: '3.12'
- name: Install gremlins
run: |
GOBIN="$RUNNER_TEMP/gremlins" CGO_ENABLED=0 \
go install github.com/go-gremlins/gremlins/cmd/gremlins@v0.6.0
- name: Run mutation testing
run: |
set -eu
mkdir -p tests/mutation/run
python3 - <<'PY'
import os, re, subprocess
from pathlib import Path
packages = os.environ['PACKAGES_INPUT'].split()
coefficient = os.environ['TIMEOUT_INPUT']
if not packages or len(packages) > 50:
raise SystemExit('select between 1 and 50 local Go packages')
if not re.fullmatch(r'[1-9][0-9]{0,2}', coefficient):
raise SystemExit('timeout coefficient must be an integer from 1 through 999')
root = Path.cwd().resolve()
failed = []
for package in packages:
if (not re.fullmatch(r'\./pkg/[A-Za-z0-9_/-]+', package)
or not (root / package).is_dir()
or not (root / package).resolve().is_relative_to(root / 'pkg')):
raise SystemExit('packages must name existing local pkg/ directories')
for index, package in enumerate(packages):
output = root / 'tests/mutation/run' / f'{index:02d}-{package[6:].replace("/", "-")}.json'
command = [str(Path(os.environ['RUNNER_TEMP']) / 'gremlins/gremlins'),
'unleash', '--timeout-coefficient', coefficient,
'--threshold-efficacy', '0', '--threshold-mcover', '0',
'-o', str(output), package]
print(f'Mutating {package}', flush=True)
result = subprocess.run(command, check=False)
if result.returncode != 0 or not output.is_file():
failed.append(package)
if failed:
raise SystemExit('mutation execution failed or produced no receipt: ' + ', '.join(failed))
PY
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
if: always()
with:
name: mutation-results
path: tests/mutation/run/
retention-days: 30