more styxing

This commit is contained in:
Daylin Morgan 2024-01-26 15:42:48 -06:00
parent 2434a3b3bf
commit a64d438e4a
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F

View file

@ -4,7 +4,13 @@ from std/nativesockets import getHostname
var logger = newConsoleLogger() var logger = newConsoleLogger()
addHandler(logger) addHandler(logger)
let summaryFile = getEnv("GITHUB_STEP_SUMMARY")
let summaryFilePath = getEnv("GITHUB_STEP_SUMMARY")
proc writeToSummary(msg: string) =
let f = open(summaryFilePath, mode = fmAppend)
write(f,msg)
close(f)
type type
StyxContext = object StyxContext = object
@ -34,8 +40,8 @@ proc dry(c: StyxContext) =
execQuit "nix build " & c.systemFlakePath & " --dry-run" execQuit "nix build " & c.systemFlakePath & " --dry-run"
proc cache(c: StyxContext) = proc cache(c: StyxContext) =
# Simple benchmarking ## build and upload to binary cache
let start = cpuTime() let start = getTime()
let code = execCmd """ let code = execCmd """
cachix watch-exec """ & c.cache & """ \ cachix watch-exec """ & c.cache & """ \
-- \ -- \
@ -43,17 +49,26 @@ proc cache(c: StyxContext) =
--print-build-logs \ --print-build-logs \
--accept-flake-config --accept-flake-config
""" """
let duration = (cpuTime() - start) let duration = (getTime() - start)
if code != 0: if code != 0:
error "faile to build configuration for: ", c.host error "failed to build configuration for: ", c.host
if summaryFile != "": if summaryFilePath != "":
writeFile( writeToSummary(
summaryFile,
"Built host: " & c.host & " in " & $duration & " seconds" "Built host: " & c.host & " in " & $duration & " seconds"
) )
info "Built host: " & c.host & " in " & $duration & " seconds" info "Built host: " & c.host & " in " & $duration & " seconds"
proc touchPr(c: StyxContext) =
const cmds = ["git branch -D update_flake_lock_action",
"git fetch origin",
"git checkout update_flake_lock_action",
"git commit --amend --no-edit",
"git push origin update_flake_lock_action --force"]
for cmd in cmds:
let code = execCmd cmd
if code != 0:
error "command: ",cmd,"exited with code: ",$code
proc nixosRebuild(c: StyxContext, cmd: string) = proc nixosRebuild(c: StyxContext, cmd: string) =
execQuit "sudo nixos-rebuild " & cmd & " " & " --flake " & c.flake execQuit "sudo nixos-rebuild " & cmd & " " & " --flake " & c.flake
@ -64,20 +79,7 @@ proc boot(c: StyxContext) =
proc switch(c: StyxContext) = proc switch(c: StyxContext) =
## nixos rebuild switch ## nixos rebuild switch
nixosRebuild c, "swith" nixosRebuild c, "switch"
# proc matchCmd(cmd: string): proc =
# case cmd:
# of "dry": dry
# of "switch": switch
# of "boot": boot
# of "cache": cache
# of "build": build
# else:
# error "unknown command", cmd
# quit 1
#
proc runCmd(c: StyxContext, cmd: string) = proc runCmd(c: StyxContext, cmd: string) =
case cmd: case cmd:
@ -86,6 +88,7 @@ proc runCmd(c: StyxContext, cmd: string) =
of "boot": boot c of "boot": boot c
of "cache": cache c of "cache": cache c
of "build": build c of "build": build c
of "touch-pr": touchPr c
else: else:
error "unknown command: ", cmd error "unknown command: ", cmd
quit 1 quit 1
@ -99,9 +102,10 @@ styx <cmd> [opts]
switch nixos-rebuild switch switch nixos-rebuild switch
cache build and push to cachix cache build and push to cachix
build build system flake build build system flake
touch-pr trigger Github Action Ci
options: options:
-?|--help > show this help --help > show this help
-h|--host > hostname (current host) -h|--host > hostname (current host)
-f|--flake > path to flake ($FLAKE_PATH or $HOME/styx) -f|--flake > path to flake ($FLAKE_PATH or $HOME/styx)
-c|--cache > name of cachix binary cache (daylin) -c|--cache > name of cachix binary cache (daylin)
@ -131,6 +135,8 @@ when isMainModule:
parseFlag c, key, val parseFlag c, key, val
of cmdEnd: of cmdEnd:
discard discard
if cmd == "":
echo "please specify a command, see below"
echo usage; quit 1
info $c info $c
runCmd c, cmd runCmd c, cmd