improve oizys ci output

This commit is contained in:
Daylin Morgan 2024-08-09 12:41:18 -05:00
parent 65664246a5
commit b8dc12e3ce
Signed by: daylin
GPG key ID: 950D13E9719334AD

View file

@ -56,7 +56,10 @@ func New() *Oizys {
o.flake = oizysDir o.flake = oizysDir
} }
o.githubSummary = os.Getenv("GITHUB_STEP_SUMMARY") o.githubSummary = os.Getenv("GITHUB_STEP_SUMMARY")
o.inCI = o.githubSummary != "" if o.githubSummary != "" {
o.inCI = true
log.Debug("running oizys in CI mode")
}
o.githubToken = os.Getenv("GITHUB_TOKEN") o.githubToken = os.Getenv("GITHUB_TOKEN")
o.repo = git.NewRepo(o.flake) o.repo = git.NewRepo(o.flake)
return o return o
@ -244,6 +247,35 @@ func NixosRebuild(subcmd string, rest ...string) {
e.ExitWithCommand(cmd) e.ExitWithCommand(cmd)
} }
func splitDrv(drv string) (string, string) {
s := strings.SplitN(drv, "-", 2)
ss := strings.Split(s[0], "/")
hash := ss[len(ss)-1]
drvName := strings.Replace(s[1], ".drv^*", "", 1)
return drvName, hash
}
func writeDervationsToStepSummary(drvs []string) {
tableRows := make([]string, len(drvs))
for i, drv := range drvs {
name, hash := splitDrv(drv)
tableRows[i] = fmt.Sprintf(
"| %s | %s |",
name, hash,
)
}
o.writeToGithubStepSummary(
fmt.Sprintf(`# Building Derivations:
| derivation | hash |
|---|---|
%s
`,
strings.Join(tableRows, "\n"),
),
)
}
func NixBuild(minimal bool, rest ...string) { func NixBuild(minimal bool, rest ...string) {
cmd := exec.Command("nix", "build") cmd := exec.Command("nix", "build")
if o.resetCache { if o.resetCache {
@ -257,9 +289,7 @@ func NixBuild(minimal bool, rest ...string) {
os.Exit(0) os.Exit(0)
} }
if o.inCI { if o.inCI {
o.writeToGithubStepSummary("# Building Derivations:\n") writeDervationsToStepSummary(drvs)
// TODO: write as a markdown table with hash + name (without .drv)
o.writeToGithubStepSummary(strings.Join(drvs, "\n"))
} }
cmd.Args = append(cmd.Args, append(drvs, "--no-link")...) cmd.Args = append(cmd.Args, append(drvs, "--no-link")...)
} }