-
Notifications
You must be signed in to change notification settings - Fork 3
/
verify.go
65 lines (58 loc) · 1.65 KB
/
verify.go
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
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package commands
import (
_ "embed"
"flag"
"fmt"
"os"
"text/template"
"github.com/hashicorp/composite-action-framework-go/pkg/cli"
"github.com/hashicorp/composite-action-framework-go/pkg/fs"
"github.com/hashicorp/composite-action-framework-go/pkg/json"
)
//go:embed templates/stepsummary.md.tmpl
var stepSummaryTemplate string
type verifyOpts struct {
verifyish
outFile string
stepSummary string
}
func (opts *verifyOpts) Flags(fs *flag.FlagSet) {
opts.verifyish.Flags(fs)
fs.StringVar(&opts.outFile, "o", "", "write the result json to this file")
fs.StringVar(&opts.stepSummary, "github-step-summary", os.Getenv("GITHUB_STEP_SUMMARY"), "write a github step summary to this file")
}
var Verify = cli.LeafCommand("verify", "verify a build's reproducibility", func(opts *verifyOpts) error {
result, err := opts.runVerification()
if err != nil {
return err
}
if opts.outFile != "" {
if err := json.WriteFile(opts.outFile, result); err != nil {
return err
}
opts.log("Result written to %s", opts.outFile)
}
if opts.stepSummary != "" {
opts.log("Writing GitHub Step Summary to %s", opts.stepSummary)
f, err := fs.Append(opts.stepSummary)
if err != nil {
return err
}
defer f.Close()
funcs := template.FuncMap{
"json": func(a any) string {
s, err := json.String(a)
if err != nil {
return fmt.Sprintf("<error: %v>", err)
}
return s
},
}
if err := template.Must(template.New("").Funcs(funcs).Parse(stepSummaryTemplate)).Execute(f, result); err != nil {
return err
}
}
return opts.output.result("Reproducibility verification", result)
})