49 lines
1.7 KiB
Go
49 lines
1.7 KiB
Go
package main
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"encoding/json"
|
||
|
|
"flag"
|
||
|
|
"fmt"
|
||
|
|
"os"
|
||
|
|
"path/filepath"
|
||
|
|
"strings"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"data-terminal-cloud/internal/cisupplychainconformance"
|
||
|
|
)
|
||
|
|
|
||
|
|
func main() {
|
||
|
|
capturePath := flag.String("capture", "", "remote-ci-supply-chain-capture-v1 JSON")
|
||
|
|
candidateVersion := flag.String("candidate-version", "", "release candidate version")
|
||
|
|
buildDigest := flag.String("build-digest", "", "sha256 immutable build digest")
|
||
|
|
sourceCommit := flag.String("source-commit", "", "full source commit")
|
||
|
|
outputPath := flag.String("output", "", "absolute output report path")
|
||
|
|
flag.Parse()
|
||
|
|
if *capturePath == "" || strings.TrimSpace(*candidateVersion) == "" || strings.TrimSpace(*buildDigest) == "" || strings.TrimSpace(*sourceCommit) == "" || !filepath.IsAbs(*outputPath) {
|
||
|
|
fmt.Fprintln(os.Stderr, "usage: ci-supply-chain-conformance -capture capture.json -candidate-version VERSION -build-digest sha256:... -source-commit COMMIT -output ABSOLUTE.json")
|
||
|
|
os.Exit(2)
|
||
|
|
}
|
||
|
|
content, err := os.ReadFile(*capturePath)
|
||
|
|
if err != nil {
|
||
|
|
fmt.Fprintln(os.Stderr, "read remote CI capture:", err)
|
||
|
|
os.Exit(2)
|
||
|
|
}
|
||
|
|
capture, err := cisupplychainconformance.ParseCapture(content)
|
||
|
|
if err != nil {
|
||
|
|
fmt.Fprintln(os.Stderr, err)
|
||
|
|
os.Exit(2)
|
||
|
|
}
|
||
|
|
report := cisupplychainconformance.Evaluate(capture, *candidateVersion, *buildDigest, *sourceCommit, time.Now().UTC())
|
||
|
|
report.InputSHA256["ci_capture"] = cisupplychainconformance.SHA256(content)
|
||
|
|
encoded, _ := json.MarshalIndent(report, "", " ")
|
||
|
|
encoded = append(encoded, '\n')
|
||
|
|
if err = os.WriteFile(*outputPath, encoded, 0o600); err != nil {
|
||
|
|
fmt.Fprintln(os.Stderr, "write remote CI report:", err)
|
||
|
|
os.Exit(2)
|
||
|
|
}
|
||
|
|
fmt.Printf("Remote CI supply-chain conformance %s: %s\n", report.Result, *outputPath)
|
||
|
|
if report.Result != "PASS" {
|
||
|
|
os.Exit(1)
|
||
|
|
}
|
||
|
|
}
|