Skip to content

Commit 30dccad

Browse files
committed
gen: parse env and gha-event
Signed-off-by: CrazyMax <[email protected]>
1 parent 75887cd commit 30dccad

File tree

178 files changed

+63716
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

178 files changed

+63716
-10
lines changed

Diff for: .github/workflows/ci.yml

+15-10
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,15 @@ jobs:
253253
name: Download results
254254
uses: actions/download-artifact@v4
255255
with:
256-
path: /tmp/buildkit-bench
256+
path: /tmp/buildkit-bench-result
257257
pattern: bench-results-*
258258
merge-multiple: true
259259
-
260260
name: Download candidates
261261
uses: actions/download-artifact@v4
262262
with:
263263
name: candidates
264-
path: /tmp/buildkit-bench
264+
path: /tmp/buildkit-bench-result
265265
-
266266
name: Set up Docker Buildx
267267
uses: docker/setup-buildx-action@v3
@@ -272,6 +272,15 @@ jobs:
272272
-
273273
name: Checkout
274274
uses: actions/checkout@v4
275+
-
276+
name: Create metadata files
277+
run: |
278+
cp ./testconfig.yml /tmp/buildkit-bench-result/
279+
echo "$(date +'%Y%m%d-%H%M%S')" > /tmp/buildkit-bench-result/name.txt
280+
env|sort > /tmp/buildkit-bench-result/env.txt
281+
if [ -f "$GITHUB_EVENT_PATH" ]; then
282+
cp $GITHUB_EVENT_PATH /tmp/buildkit-bench-result/gha-event.json
283+
fi
275284
-
276285
name: Generate HTML report
277286
uses: docker/bake-action@v5
@@ -281,18 +290,14 @@ jobs:
281290
provenance: false
282291
set: |
283292
*.cache-from=type=registry,ref=${{ env.BUILDKIT_CACHE_REPO }}:tests-base
284-
*.contexts.tests-results=cwd:///tmp/buildkit-bench
293+
*.contexts.tests-results=cwd:///tmp/buildkit-bench-result
285294
*.output=./bin/report
286295
env:
287296
BAKE_ALLOW_REMOTE_FS_ACCESS: 1
288297
-
289-
name: Include additional files to report directory
298+
name: Include results to report
290299
run: |
291-
cp -r /tmp/buildkit-bench/* ./testconfig.yml ./bin/report/
292-
env|sort > ./bin/report/env.txt
293-
if [ -f "$GITHUB_EVENT_PATH" ]; then
294-
cp $GITHUB_EVENT_PATH ./bin/report/gha-event.json
295-
fi
300+
cp -r /tmp/buildkit-bench-result/* ./bin/report/
296301
-
297302
name: Upload report
298303
uses: actions/upload-artifact@v4
@@ -324,7 +329,7 @@ jobs:
324329
-
325330
name: Move reports
326331
run: |
327-
reportDir=$(date +'%Y%m%d-%H%M%S')
332+
reportDir=$(cat /tmp/buildkit-bench-report/name.txt)
328333
mkdir -p ./website/public/result/$reportDir
329334
mv /tmp/buildkit-bench-report/* ./website/public/result/$reportDir/
330335
if [ -d ./bin/gh-pages/result ]; then

Diff for: Dockerfile

+9
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,21 @@ ARG GEN_VALIDATION_MODE
6464
RUN --mount=type=bind,target=. <<EOT
6565
set -e
6666
args="gen --output /tmp/benchmarks.html"
67+
if [ -f /tests-results/name.txt ]; then
68+
args="$args --name $(cat /tests-results/name.txt)"
69+
fi
6770
if [ -f /tests-results/candidates.json ]; then
6871
args="$args --candidates /tests-results/candidates.json"
6972
fi
7073
if [ -f /tests-results/testconfig.yml ]; then
7174
args="$args --config /tests-results/testconfig.yml"
7275
fi
76+
if [ -f /tests-results/gha-event.json ]; then
77+
args="$args --gha-event /tests-results/gha-event.json"
78+
fi
79+
if [ -f /tests-results/env.txt ]; then
80+
args="$args --envs /tests-results/env.txt"
81+
fi
7382
if [ -n "$GEN_VALIDATION_MODE" ]; then
7483
args="$args --validation-mode $GEN_VALIDATION_MODE"
7584
fi

Diff for: cmd/gotestmetrics/gen.go

+24
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import (
1414
"github.com/go-echarts/go-echarts/v2/components"
1515
"github.com/go-echarts/go-echarts/v2/opts"
1616
"github.com/go-echarts/go-echarts/v2/types"
17+
"github.com/joho/godotenv"
1718
"github.com/moby/buildkit-bench/util/candidates"
19+
"github.com/moby/buildkit-bench/util/github/gha"
1820
"github.com/moby/buildkit-bench/util/gotest"
1921
"github.com/moby/buildkit-bench/util/testutil"
2022
"github.com/montanaflynn/stats"
@@ -25,9 +27,12 @@ import (
2527
type genCmd struct {
2628
Files []string `kong:"arg='',name='files',required,help='Benchmark results files generated by parse command.'"`
2729

30+
Name string `kong:"name='name',help='Name of the report.'"`
2831
Config string `kong:"name='config',required,default='testconfig.yml',help='Test config file.'"`
2932
Output string `kong:"name='output',default='./bin/gen/benchmarks.html',help='File to write the HTML report to.'"`
3033
Candidates string `kong:"name='candidates',help='Candidates file.'"`
34+
GHAEvent string `kong:"name='gha-event',help='GitHub Actions payload JSON file.'"`
35+
Envs string `kong:"name='envs',help='Environment variables file.'"`
3136
ValidationMode string `kong:"name='validation-mode',enum='sloppy,strict',default='sloppy',help='Validation mode.'"`
3237
}
3338

@@ -101,6 +106,25 @@ func (c *genCmd) writeHTML(benchmarks map[string]gotest.Benchmark) error {
101106
return err
102107
}
103108

109+
var envs map[string]string
110+
if c.Envs != "" {
111+
envs, err = godotenv.Read(c.Envs)
112+
if err != nil {
113+
return err
114+
}
115+
}
116+
117+
if c.GHAEvent != "" {
118+
ghaEventName, ok := envs["GITHUB_EVENT_NAME"]
119+
if !ok {
120+
return errors.New("missing GITHUB_EVENT_NAME in envs")
121+
}
122+
_, err = gha.ParseEventFile(ghaEventName, c.GHAEvent)
123+
if err != nil {
124+
return err
125+
}
126+
}
127+
104128
var sortedRefs []candidates.Ref
105129
if c.Candidates != "" {
106130
cds, err := candidates.Load(c.Candidates)

Diff for: go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ require (
88
github.com/containerd/continuity v0.4.3
99
github.com/go-echarts/go-echarts/v2 v2.4.1
1010
github.com/gofrs/flock v0.12.1
11+
github.com/google/go-github/v65 v65.0.0
1112
github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6
13+
github.com/joho/godotenv v1.5.1
1214
github.com/moby/buildkit v0.15.2
1315
github.com/montanaflynn/stats v0.7.1
1416
github.com/opencontainers/image-spec v1.1.0
@@ -38,6 +40,7 @@ require (
3840
github.com/gogo/googleapis v1.4.1 // indirect
3941
github.com/gogo/protobuf v1.3.2 // indirect
4042
github.com/golang/protobuf v1.5.4 // indirect
43+
github.com/google/go-querystring v1.1.0 // indirect
4144
github.com/hashicorp/errwrap v1.1.0 // indirect
4245
github.com/hashicorp/go-multierror v1.1.1 // indirect
4346
github.com/in-toto/in-toto-golang v0.5.0 // indirect

Diff for: go.sum

+7
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,15 @@ github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4er
6767
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
6868
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
6969
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
70+
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
7071
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
7172
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
7273
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
7374
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
75+
github.com/google/go-github/v65 v65.0.0 h1:pQ7BmO3DZivvFk92geC0jB0q2m3gyn8vnYPgV7GSLhQ=
76+
github.com/google/go-github/v65 v65.0.0/go.mod h1:DvrqWo5hvsdhJvHd4WyVF9ttANN3BniqjP8uTFMNb60=
77+
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
78+
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
7479
github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6 h1:k7nVchz72niMH6YLQNvHSdIE7iqsQxK1P41mySCvssg=
7580
github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw=
7681
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
@@ -83,6 +88,8 @@ github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUq
8388
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
8489
github.com/in-toto/in-toto-golang v0.5.0 h1:hb8bgwr0M2hGdDsLjkJ3ZqJ8JFLL/tgYdAxF/XEFBbY=
8590
github.com/in-toto/in-toto-golang v0.5.0/go.mod h1:/Rq0IZHLV7Ku5gielPT4wPHJfH1GdHMCq8+WPxw8/BE=
91+
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
92+
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
8693
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
8794
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
8895
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=

Diff for: util/github/gha/event.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package gha
2+
3+
import (
4+
"os"
5+
6+
"github.com/google/go-github/v65/github"
7+
)
8+
9+
func ParseEventFile(name string, fp string) (interface{}, error) {
10+
dt, err := os.ReadFile(fp)
11+
if err != nil {
12+
return nil, err
13+
}
14+
return ParseEvent(name, dt)
15+
}
16+
17+
func ParseEvent(name string, dt []byte) (interface{}, error) {
18+
event, err := github.ParseWebHook(name, dt)
19+
if err != nil {
20+
return nil, err
21+
}
22+
return event, nil
23+
}

0 commit comments

Comments
 (0)