-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoverage-workflow.html
More file actions
248 lines (213 loc) · 8.32 KB
/
coverage-workflow.html
File metadata and controls
248 lines (213 loc) · 8.32 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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>workflow: Go Coverage Report</title>
<style>
body {
background: black;
color: rgb(80, 80, 80);
}
body, pre, #legend span {
font-family: Menlo, monospace;
font-weight: bold;
}
#topbar {
background: black;
position: fixed;
top: 0; left: 0; right: 0;
height: 42px;
border-bottom: 1px solid rgb(80, 80, 80);
}
#content {
margin-top: 50px;
}
#nav, #legend {
float: left;
margin-left: 10px;
}
#legend {
margin-top: 12px;
}
#nav {
margin-top: 10px;
}
#legend span {
margin: 0 5px;
}
.cov0 { color: rgb(192, 0, 0) }
.cov1 { color: rgb(128, 128, 128) }
.cov2 { color: rgb(116, 140, 131) }
.cov3 { color: rgb(104, 152, 134) }
.cov4 { color: rgb(92, 164, 137) }
.cov5 { color: rgb(80, 176, 140) }
.cov6 { color: rgb(68, 188, 143) }
.cov7 { color: rgb(56, 200, 146) }
.cov8 { color: rgb(44, 212, 149) }
.cov9 { color: rgb(32, 224, 152) }
.cov10 { color: rgb(20, 236, 155) }
</style>
</head>
<body>
<div id="topbar">
<div id="nav">
<select id="files">
<option value="file0">github.com/watany-dev/raptor/internal/workflow/load.go (90.3%)</option>
<option value="file1">github.com/watany-dev/raptor/internal/workflow/select.go (92.9%)</option>
</select>
</div>
<div id="legend">
<span>not tracked</span>
<span class="cov0">not covered</span>
<span class="cov8">covered</span>
</div>
</div>
<div id="content">
<pre class="file" id="file0" style="display: none">package workflow
import (
"fmt"
"os"
"gopkg.in/yaml.v3"
)
// LoadWorkflowFile loads and parses a GitHub Actions workflow file from the given path.
func LoadWorkflowFile(path string) (*WorkflowFile, error) <span class="cov8" title="1">{
data, err := os.ReadFile(path)
if err != nil </span><span class="cov8" title="1">{
return nil, fmt.Errorf("failed to read workflow file: %w", err)
}</span>
// Parse YAML into yaml.Node once (instead of parsing twice)
<span class="cov8" title="1">var root yaml.Node
if err := yaml.Unmarshal(data, &root); err != nil </span><span class="cov0" title="0">{
return nil, fmt.Errorf("failed to parse workflow YAML: %w", err)
}</span>
// Extract both WorkflowFile and JobOrder from the single parsed Node
<span class="cov8" title="1">wf, jobOrder, err := parseWorkflowFromNode(&root)
if err != nil </span><span class="cov8" title="1">{
return nil, fmt.Errorf("failed to parse workflow: %w", err)
}</span>
<span class="cov8" title="1">wf.JobOrder = jobOrder
return wf, nil</span>
}
// parseWorkflowFromNode extracts WorkflowFile and job order from a parsed yaml.Node.
// This avoids parsing the YAML twice by reusing the same Node for both operations.
func parseWorkflowFromNode(root *yaml.Node) (*WorkflowFile, []string, error) <span class="cov8" title="1">{
var wf WorkflowFile
// Decode the Node directly into the struct (no re-parsing needed)
if err := root.Decode(&wf); err != nil </span><span class="cov8" title="1">{
return nil, nil, fmt.Errorf("failed to decode workflow: %w", err)
}</span>
// Extract job order from the same Node
<span class="cov8" title="1">jobOrder := extractJobOrderFromNode(root)
return &wf, jobOrder, nil</span>
}
// extractJobOrderFromNode extracts job IDs in definition order from a parsed yaml.Node.
func extractJobOrderFromNode(root *yaml.Node) []string <span class="cov8" title="1">{
// root.Content[0] is the document node
if len(root.Content) == 0 </span><span class="cov0" title="0">{
return nil
}</span>
<span class="cov8" title="1">doc := root.Content[0]
if doc.Kind != yaml.MappingNode </span><span class="cov0" title="0">{
return nil
}</span>
// Find the "jobs" key in the mapping
<span class="cov8" title="1">for i := 0; i < len(doc.Content)-1; i += 2 </span><span class="cov8" title="1">{
keyNode := doc.Content[i]
valueNode := doc.Content[i+1]
if keyNode.Value == "jobs" && valueNode.Kind == yaml.MappingNode </span><span class="cov8" title="1">{
// Extract job IDs in order
var jobOrder []string
for j := 0; j < len(valueNode.Content)-1; j += 2 </span><span class="cov8" title="1">{
jobKeyNode := valueNode.Content[j]
jobOrder = append(jobOrder, jobKeyNode.Value)
}</span>
<span class="cov8" title="1">return jobOrder</span>
}
}
<span class="cov8" title="1">return nil</span>
}
</pre>
<pre class="file" id="file1" style="display: none">package workflow
import (
"fmt"
"os"
"path/filepath"
"strings"
)
// SelectJob selects a job from a workflow by its ID.
// It returns the job if found, or an error if the job ID doesn't exist.
func SelectJob(wf *WorkflowFile, jobID string) (*Job, error) <span class="cov8" title="1">{
if wf == nil </span><span class="cov8" title="1">{
return nil, fmt.Errorf("workflow is nil")
}</span>
<span class="cov8" title="1">if jobID == "" </span><span class="cov8" title="1">{
return nil, fmt.Errorf("job ID is empty")
}</span>
<span class="cov8" title="1">job, exists := wf.Jobs[jobID]
if !exists </span><span class="cov8" title="1">{
return nil, fmt.Errorf("job %q not found in workflow", jobID)
}</span>
<span class="cov8" title="1">return &job, nil</span>
}
// DiscoverWorkflows finds all workflow files in the .github/workflows directory.
// It returns a slice of absolute paths to workflow files (.yml or .yaml).
func DiscoverWorkflows(repoRoot string) ([]string, error) <span class="cov8" title="1">{
workflowsDir := filepath.Join(repoRoot, ".github", "workflows")
info, err := os.Stat(workflowsDir)
if err != nil </span><span class="cov8" title="1">{
if os.IsNotExist(err) </span><span class="cov8" title="1">{
return nil, fmt.Errorf("workflows directory does not exist: %s", workflowsDir)
}</span>
<span class="cov0" title="0">return nil, fmt.Errorf("failed to access workflows directory: %w", err)</span>
}
<span class="cov8" title="1">if !info.IsDir() </span><span class="cov8" title="1">{
return nil, fmt.Errorf("workflows path is not a directory: %s", workflowsDir)
}</span>
<span class="cov8" title="1">entries, err := os.ReadDir(workflowsDir)
if err != nil </span><span class="cov0" title="0">{
return nil, fmt.Errorf("failed to read workflows directory: %w", err)
}</span>
<span class="cov8" title="1">var workflows []string
for _, entry := range entries </span><span class="cov8" title="1">{
if entry.IsDir() </span><span class="cov8" title="1">{
continue</span>
}
<span class="cov8" title="1">name := entry.Name()
ext := strings.ToLower(filepath.Ext(name))
if ext == ".yml" || ext == ".yaml" </span><span class="cov8" title="1">{
workflows = append(workflows, filepath.Join(workflowsDir, name))
}</span>
}
<span class="cov8" title="1">return workflows, nil</span>
}
</pre>
</div>
</body>
<script>
(function() {
var files = document.getElementById('files');
var visible;
files.addEventListener('change', onChange, false);
function select(part) {
if (visible)
visible.style.display = 'none';
visible = document.getElementById(part);
if (!visible)
return;
files.value = part;
visible.style.display = 'block';
location.hash = part;
}
function onChange() {
select(files.value);
window.scrollTo(0, 0);
}
if (location.hash != "") {
select(location.hash.substr(1));
}
if (!visible) {
select("file0");
}
})();
</script>
</html>