forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
85 lines (75 loc) · 3.2 KB
/
Copy pathadapter-code-coverage.yml
File metadata and controls
85 lines (75 loc) · 3.2 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
name: Adapter Code Coverage
on:
pull_request:
paths: ["adapters/*/*.go"]
permissions:
contents: read
pull-requests: read
jobs:
run-coverage:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Discover Adapter Directories
id: get_directories
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const utils = require('./.github/workflows/helpers/pull-request-utils.js')
function directoryExtractor(filepath, status) {
// extract directory name only if file is not removed and file is in adapters directory
if (status != "removed" && filepath.startsWith("adapters/") && filepath.split("/").length > 2) {
return filepath.split("/")[1]
}
return ""
}
const helper = utils.diffHelper({github, context})
const directories = await helper.getDirectories(directoryExtractor)
// run coverage for maximum of 2 directories
return (directories.length == 0 || directories.length > 2) ? "" : JSON.stringify(directories)
- name: Run Coverage Tests
id: run_coverage
if: steps.get_directories.outputs.result != ''
env:
GOTOOLCHAIN: local
run: |
directories=$(echo '${{ steps.get_directories.outputs.result }}' | jq -r '.[]')
go mod download
# create a temporary directory to store the coverage output
temp_dir=$(mktemp -d)
touch ${temp_dir}/coverage_output.txt
# generate coverage for adapter
cd ./adapters
for directory in $directories; do
cd $directory
coverage_profile_path="${PWD}/${directory}.out"
go test -coverprofile="${coverage_profile_path}"
go tool cover -html="${coverage_profile_path}" -o "${temp_dir}/${directory}.html"
go tool cover -func="${coverage_profile_path}" -o "${temp_dir}/${directory}.txt"
cd ..
done
echo "coverage_dir=${temp_dir}" >> $GITHUB_OUTPUT
- name: Prepare Artifacts
if: steps.get_directories.outputs.result != ''
run: |
mkdir -p ./coverage-artifacts/pr-metadata
cp ${{ steps.run_coverage.outputs.coverage_dir }}/*.html ./coverage-artifacts/ 2>/dev/null || true
cp ${{ steps.run_coverage.outputs.coverage_dir }}/*.txt ./coverage-artifacts/ 2>/dev/null || true
echo '${{ steps.get_directories.outputs.result }}' > ./coverage-artifacts/pr-metadata/directories.json
echo '${{ github.event.pull_request.number }}' > ./coverage-artifacts/pr-metadata/pr_number
echo '${{ github.event.pull_request.head.sha }}' > ./coverage-artifacts/pr-metadata/head_sha
- name: Upload Coverage Artifacts
if: steps.run_coverage.outputs.coverage_dir != ''
uses: actions/upload-artifact@v4
with:
name: coverage-results
path: ./coverage-artifacts
retention-days: 1