make use of go embed

This commit is contained in:
Daylin Morgan 2024-08-10 18:48:41 -05:00
parent 8f8c551503
commit a03cbee7ac
Signed by: daylin
GPG key ID: 950D13E9719334AD
3 changed files with 45 additions and 33 deletions

View file

@ -0,0 +1,21 @@
ld-library-path
builder.pl
profile
system-path
nixos-help
nixos-install
nixos-version
nixos-manual-html
nixos-rebuild
nixos-configuration-reference-manpage
nixos-generate-config
nixos-enter
nixos-container
nixos-build-vms
nixos-wsl-version
nixos-wsl-welcome-message
nixos-wsl-welcome
restic-gdrive
gitea
lock
code

View file

@ -255,6 +255,12 @@ func splitDrv(drv string) (string, string) {
return drvName, hash
}
const tableTmpl = `# Building Derivations
| derivation | hash |
|---|---|
%s
`
func writeDervationsToStepSummary(drvs []string) {
tableRows := make([]string, len(drvs))
for i, drv := range drvs {
@ -264,16 +270,7 @@ func writeDervationsToStepSummary(drvs []string) {
name, hash,
)
}
o.writeToGithubStepSummary(
fmt.Sprintf(`# Building Derivations
| derivation | hash |
|---|---|
%s
`,
strings.Join(tableRows, "\n"),
),
)
o.writeToGithubStepSummary(fmt.Sprintf(tableTmpl, strings.Join(tableRows, "\n")))
}
func NixBuild(minimal bool, rest ...string) {

View file

@ -1,6 +1,7 @@
package oizys
import (
_ "embed"
"encoding/json"
"errors"
"fmt"
@ -12,22 +13,21 @@ import (
"github.com/charmbracelet/log"
)
var ignoredMap = stringSliceToMap(
[]string{
// nix
"ld-library-path", "builder.pl", "profile", "system-path",
// nixos
"nixos-help",
"nixos-install", "nixos-version",
"nixos-manual-html", "nixos-rebuild",
"nixos-configuration-reference-manpage",
"nixos-generate-config", "nixos-enter",
"nixos-container", "nixos-build-vms",
"nixos-wsl-version", "nixos-wsl-welcome-message", "nixos-wsl-welcome",
// trivial packages
"restic-gdrive", "gitea", "lock", "code",
},
)
//go:embed ignored.txt
var ignoredList string
var ignoredMap = stringToMap(ignoredList)
func stringToMap(s string) map[string]struct{} {
return stringSliceToMap(strings.Split(s, "\n"))
}
func stringSliceToMap(slice []string) map[string]struct{} {
hashMap := make(map[string]struct{}, len(slice))
for _, s := range slice {
hashMap[s] = struct{}{}
}
return hashMap
}
type Derivation struct {
InputDrvs map[string]interface{}
@ -72,13 +72,7 @@ func drvNotIgnored(drv string) bool {
return !ok
}
func stringSliceToMap(slice []string) map[string]struct{} {
hashMap := make(map[string]struct{}, len(slice))
for _, s := range slice {
hashMap[s] = struct{}{}
}
return hashMap
}
func drvsToInputs(derivation map[string]Derivation) []string {
var drvs []string