-
Notifications
You must be signed in to change notification settings - Fork 1
152 lines (130 loc) · 5.73 KB
/
_combine_coverage_data.yml
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# This workflow will download simplecov artifacts created by parallel_test and combine
# them into one set of test coverage data.
#
# This workflow is meant to be called by other workflows.
name: "♻️ SimpleCov Report"
on:
workflow_call:
jobs:
combine_runtime_logs:
name: "♻️ "
runs-on: ubuntu-latest
env:
RAILS_ENV: test
# Manually export your local RAILS_MASTER_KEY if using the credentials system.
# RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
BUNDLE_JOBS: 2
BUNDLE_RETRY: 3
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
path: tmp/starter
- name: Install Ruby and gems
uses: ruby/setup-ruby@v1
with:
working-directory: tmp/starter
bundler-cache: true
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: tmp/starter/coverage_artifacts
pattern: test_coverage_*.log
merge-multiple: false
- name: List downloaded artifacts
run: ls -alR tmp/starter/coverage_artifacts
shell: bash
- name: Cat an artifact
run: cat tmp/starter/coverage_artifacts/test_coverage_*.log/.resultset.json
shell: bash
- name: Combine Coverage Data With Groups
working-directory: tmp/starter
run: "bundle exec rake coverage:report_with_groups[coverage_artifacts/**/.resultset.json]"
shell: bash
- name: Copy coverage.json to coverage_with_groups.json
run: cp tmp/starter/coverage/coverage.json tmp/starter/coverage/coverage_with_groups.json
continue-on-error: true
shell: bash
- name: Combine Coverage Data
working-directory: tmp/starter
run: "bundle exec rake coverage:report[coverage_artifacts/**/.resultset.json]"
shell: bash
- name: List coverage dir
run: ls -alR tmp/starter/coverage
continue-on-error: true
shell: bash
- name: Upload Coverage Report
uses: actions/upload-artifact@v4
id: upload-coverage-report
with:
name: test_coverage_report
path: tmp/starter/coverage
include-hidden-files: true
retention-days: 1
- uses: actions/github-script@v7
id: create-summary
name: Summary
env:
COVERAGE_REPORT_LINK: ${{ steps.upload-coverage-report.outputs.artifact-url }}
with:
script: |
try {
const fs = require('fs')
const jsonString = fs.readFileSync('tmp/starter/coverage/coverage.json')
var coverageData = JSON.parse(jsonString)
const groupJsonString = fs.readFileSync('tmp/starter/coverage/coverage_with_groups.json')
var groupCoverageData = JSON.parse(groupJsonString)
var files = coverageData.files.sort((a, b) => a.covered_percent - b.covered_percent);
var numberOfFilesToShow = 10
files = files.slice(0,numberOfFilesToShow)
var fileDetails = []
fileDetails.push(`<details>`)
fileDetails.push(`<summary>File Coverage Details</summary>`)
fileDetails.push(` `)
fileDetails.push(`${numberOfFilesToShow} files with the least coverage`)
fileDetails.push(` `)
fileDetails.push(`| File | Coverage |`)
fileDetails.push(`| ---- | -------- |`)
for (const file of files) {
var filePath = file.filename.split("tmp/starter/")[1];
var fileCoverage = file.covered_percent.toFixed(1)
fileDetails.push(`| ${filePath} | ${fileCoverage}% |`)
}
fileDetails.push(` `)
fileDetails.push(`</details>`)
var groups = groupCoverageData.groups;
var groupNames = Object.keys(groups)
var groupDetails = []
groupDetails.push(`<details>`)
groupDetails.push(`<summary>Group Coverage Details</summary>`)
groupDetails.push(` `)
groupDetails.push(`| Group | Coverage |`)
groupDetails.push(`| ---- | -------- |`)
for (const groupName of groupNames) {
var groupCoverage = groups[groupName].lines.covered_percent.toFixed(1)
groupDetails.push(`| ${groupName} | ${groupCoverage}% |`)
}
groupDetails.push(` `)
groupDetails.push(`</details>`)
core.summary.addRaw(`${coverageData.metrics.covered_percent.toFixed(1)}% Covered`,true)
core.summary.addRaw(`${coverageData.files.length} Files`,true)
core.summary.addRaw(`${coverageData.metrics.covered_strength.toFixed(1)} Coverage Strength`,true)
core.summary.addRaw(`${coverageData.metrics.covered_lines} Lines Covered (of ${coverageData.metrics.total_lines})`,true)
core.summary.addRaw(` `,true)
core.summary.addRaw(fileDetails.join("\r\n"), true)
core.summary.addRaw(` `,true)
core.summary.addRaw(groupDetails.join("\r\n"), true)
core.summary.addRaw(` `,true)
core.summary.addLink('For the next 24 hours you can download a full coverage report.', process.env.COVERAGE_REPORT_LINK)
} catch(err) {
core.summary.addRaw("Error while reading or parsing the coverage JSON", true)
core.summary.addRaw(err.toString(), true)
core.error("Error while reading or parsing the coverage JSON")
core.setFailed(err)
}
core.summary.write()
- name: Delete artifacts
uses: geekyeggo/delete-artifact@v5
with:
name: test_coverage_*.log
failOnError: false