Skip to content

Commit cc464d1

Browse files
committed
gen: parse env and gha-event
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
1 parent 75887cd commit cc464d1

177 files changed

Lines changed: 63697 additions & 0 deletions

File tree

Some content is hidden

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

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ RUN --mount=type=bind,target=. <<EOT
7070
if [ -f /tests-results/testconfig.yml ]; then
7171
args="$args --config /tests-results/testconfig.yml"
7272
fi
73+
if [ -f /tests-results/gha-event.json ]; then
74+
args="$args --gha-event /tests-results/gha-event.json"
75+
fi
76+
if [ -f /tests-results/env.txt ]; then
77+
args="$args --envs /tests-results/env.txt"
78+
fi
7379
if [ -n "$GEN_VALIDATION_MODE" ]; then
7480
args="$args --validation-mode $GEN_VALIDATION_MODE"
7581
fi

cmd/gotestmetrics/gen.go

Lines changed: 23 additions & 0 deletions
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"
@@ -28,6 +30,8 @@ type genCmd struct {
2830
Config string `kong:"name='config',required,default='testconfig.yml',help='Test config file.'"`
2931
Output string `kong:"name='output',default='./bin/gen/benchmarks.html',help='File to write the HTML report to.'"`
3032
Candidates string `kong:"name='candidates',help='Candidates file.'"`
33+
GHAEvent string `kong:"name='gha-event',help='GitHub Actions payload JSON file.'"`
34+
Envs string `kong:"name='envs',help='Environment variables file.'"`
3135
ValidationMode string `kong:"name='validation-mode',enum='sloppy,strict',default='sloppy',help='Validation mode.'"`
3236
}
3337

@@ -101,6 +105,25 @@ func (c *genCmd) writeHTML(benchmarks map[string]gotest.Benchmark) error {
101105
return err
102106
}
103107

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

go.mod

Lines changed: 3 additions & 0 deletions
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

go.sum

Lines changed: 7 additions & 0 deletions
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=

util/github/gha/event.go

Lines changed: 23 additions & 0 deletions
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)