Compare commits

..

No commits in common. "13876be966361a2d63a021da71378779c56cd1a9" and "1cfef95fc4f3941a8990ff5f6eecc3424ada94a2" have entirely different histories.

6 changed files with 43 additions and 88 deletions

View file

@ -17,7 +17,8 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
- run: git checkout -B flake-lock with:
ref: flake-lock
- name: Setup Git Bot - name: Setup Git Bot
run: | run: |
@ -39,9 +40,7 @@ jobs:
- name: Update nix flake - name: Update nix flake
run: | run: |
printf '# Flake Lock\n\n```txt\n' >> $GITHUB_STEP_SUMMARY
nix flake update --commit-lock-file 2>> $GITHUB_STEP_SUMMARY nix flake update --commit-lock-file 2>> $GITHUB_STEP_SUMMARY
printf '```\n' >> $GITHUB_STEP_SUMMARY
- name: Build - name: Build
run: | run: |
@ -64,7 +63,8 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
- run: git checkout -B flake-lock with:
ref: flake-lock
# - name: Setup Git Bot # - name: Setup Git Bot
# run: | # run: |

View file

@ -1,42 +0,0 @@
package oizys
import (
"fmt"
"os"
"os/exec"
"github.com/charmbracelet/log"
"oizys/internal/ui"
)
type GitRepo struct {
path string
}
func (g *GitRepo) git(rest ...string) *exec.Cmd {
args := []string{"-C", g.path}
args = append(args, rest...)
cmd := exec.Command("git", args...)
// logCmd(cmd)
return cmd
}
func GitPull(workDir string) {
g := GitRepo{workDir}
cmdOutput, err := g.git("status", "--porcelain").Output()
if err != nil {
log.Fatal(err)
}
if len(cmdOutput) > 0 {
fmt.Println("unstaged commits, cowardly exiting...")
ui.ShowFailedOutput(cmdOutput)
os.Exit(1)
}
cmdOutput, err = g.git("pull").CombinedOutput()
if err != nil {
ui.ShowFailedOutput(cmdOutput)
log.Fatal(err)
}
}

View file

@ -11,12 +11,12 @@ import (
"github.com/charmbracelet/log" "github.com/charmbracelet/log"
) )
func LogCmd(cmd *exec.Cmd) { func logCmd(cmd *exec.Cmd) {
log.Debugf("CMD: %s", strings.Join(cmd.Args, " ")) log.Debugf("CMD: %s", strings.Join(cmd.Args, " "))
} }
func CmdOutputWithSpinner(cmd *exec.Cmd, msg string, stderr bool) (output []byte, err error) { func cmdOutputWithSpinner(cmd *exec.Cmd, msg string, stderr bool) (output []byte, err error) {
LogCmd(cmd) logCmd(cmd)
s := startSpinner(msg) s := startSpinner(msg)
if stderr { if stderr {
output, err = cmd.CombinedOutput() output, err = cmd.CombinedOutput()
@ -38,8 +38,8 @@ func startSpinner(msg string) *spinner.Spinner {
return s return s
} }
func ExitWithCommand(cmd *exec.Cmd) { func exitWithCommand(cmd *exec.Cmd) {
LogCmd(cmd) logCmd(cmd)
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {

View file

@ -1,4 +1,4 @@
package ui package oizys
import ( import (
"fmt" "fmt"
@ -11,17 +11,6 @@ import (
"golang.org/x/term" "golang.org/x/term"
) )
func ShowFailedOutput(buf []byte) {
arrow := lipgloss.
NewStyle().
Bold(true).
Foreground(lipgloss.Color("9")).
Render("->")
for _, line := range strings.Split(strings.TrimSpace(string(buf)), "\n") {
fmt.Println(arrow, line)
}
}
// TODO: seperate parsing and displaying of packages // TODO: seperate parsing and displaying of packages
func terminalSize() (int, int) { func terminalSize() (int, int) {
fd := os.Stdout.Fd() fd := os.Stdout.Fd()
@ -36,13 +25,13 @@ func terminalSize() (int, int) {
return w, h return w, h
} }
type Packages struct { type packages struct {
desc string desc string
names []string names []string
pad int pad int
} }
func ParsePackages(lines []string, desc string) *Packages { func parsePackages(lines []string, desc string) *packages {
w, _ := terminalSize() w, _ := terminalSize()
maxAcceptable := (w / 4) - 1 maxAcceptable := (w / 4) - 1
maxLen := 0 maxLen := 0
@ -59,7 +48,7 @@ func ParsePackages(lines []string, desc string) *Packages {
names[i] = name names[i] = name
} }
sort.Strings(names) sort.Strings(names)
return &Packages{names: names, pad: maxLen + 1, desc: desc} return &packages{names: names, pad: maxLen + 1, desc: desc}
} }
func ellipsis(s string, maxLen int) string { func ellipsis(s string, maxLen int) string {
@ -73,7 +62,7 @@ func ellipsis(s string, maxLen int) string {
return string(runes[0:maxLen-3]) + "..." return string(runes[0:maxLen-3]) + "..."
} }
func (p *Packages) Show(verbose bool) { func (p *packages) show(verbose bool) {
p.summary() p.summary()
if !verbose || (len(p.names) == 0) { if !verbose || (len(p.names) == 0) {
return return
@ -92,7 +81,7 @@ func (p *Packages) Show(verbose bool) {
fmt.Println() fmt.Println()
} }
func (p *Packages) summary() { func (p *packages) summary() {
fmt.Printf("%s: %s\n", fmt.Printf("%s: %s\n",
p.desc, p.desc,
lipgloss.NewStyle(). lipgloss.NewStyle().
@ -101,3 +90,14 @@ func (p *Packages) summary() {
Render(fmt.Sprint(len(p.names))), Render(fmt.Sprint(len(p.names))),
) )
} }
func showFailedOutput(buf []byte) {
arrow := lipgloss.
NewStyle().
Bold(true).
Foreground(lipgloss.Color("9")).
Render("->")
for _, line := range strings.Split(strings.TrimSpace(string(buf)), "\n") {
fmt.Println(arrow, line)
}
}

View file

@ -10,10 +10,8 @@ import (
"strings" "strings"
"github.com/charmbracelet/lipgloss" "github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/log"
e "oizys/internal/exec" "github.com/charmbracelet/log"
"oizys/internal/ui"
) )
var o *Oizys var o *Oizys
@ -131,7 +129,7 @@ func git(rest ...string) *exec.Cmd {
args := []string{"-C", o.flake} args := []string{"-C", o.flake}
args = append(args, rest...) args = append(args, rest...)
cmd := exec.Command("git", args...) cmd := exec.Command("git", args...)
e.LogCmd(cmd) logCmd(cmd)
return cmd return cmd
} }
@ -143,18 +141,18 @@ func GitPull() {
if len(cmdOutput) > 0 { if len(cmdOutput) > 0 {
fmt.Println("unstaged commits, cowardly exiting...") fmt.Println("unstaged commits, cowardly exiting...")
ui.ShowFailedOutput(cmdOutput) showFailedOutput(cmdOutput)
os.Exit(1) os.Exit(1)
} }
cmdOutput, err = git("pull").CombinedOutput() cmdOutput, err = git("pull").CombinedOutput()
if err != nil { if err != nil {
ui.ShowFailedOutput(cmdOutput) showFailedOutput(cmdOutput)
log.Fatal(err) log.Fatal(err)
} }
} }
func parseDryRun(buf string) (*ui.Packages, *ui.Packages) { func parseDryRun(buf string) (*packages, *packages) {
lines := strings.Split(strings.TrimSpace(buf), "\n") lines := strings.Split(strings.TrimSpace(buf), "\n")
var parts [2][]string var parts [2][]string
i := 0 i := 0
@ -175,8 +173,8 @@ func parseDryRun(buf string) (*ui.Packages, *ui.Packages) {
os.Exit(0) os.Exit(0)
} }
return ui.ParsePackages(parts[0], "packages to build"), return parsePackages(parts[0], "packages to build"),
ui.ParsePackages(parts[1], "packages to fetch") parsePackages(parts[1], "packages to fetch")
} }
// TODO: Refactor this and above // TODO: Refactor this and above
@ -205,8 +203,8 @@ func parseDryRun2(buf string) ([]string, []string) {
// TODO: refactor to account for --debug and not --verbose? // TODO: refactor to account for --debug and not --verbose?
func showDryRunResult(nixOutput string, verbose bool) { func showDryRunResult(nixOutput string, verbose bool) {
toBuild, toFetch := parseDryRun(nixOutput) toBuild, toFetch := parseDryRun(nixOutput)
toFetch.Show(o.debug) toFetch.show(o.debug)
toBuild.Show(true) toBuild.show(true)
} }
func Dry(verbose bool, minimal bool, rest ...string) { func Dry(verbose bool, minimal bool, rest ...string) {
@ -231,7 +229,7 @@ func Dry(verbose bool, minimal bool, rest ...string) {
lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("6")).Render(o.host), lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("6")).Render(o.host),
) )
} }
result, err := e.CmdOutputWithSpinner(cmd, spinnerMsg, true) result, err := cmdOutputWithSpinner(cmd, spinnerMsg, true)
if err != nil { if err != nil {
log.Fatal("failed to dry-run nix build", "err", err, "output", string(result)) log.Fatal("failed to dry-run nix build", "err", err, "output", string(result))
} }
@ -257,7 +255,7 @@ func NixosRebuild(subcmd string, rest ...string) {
cmd.Args = append(cmd.Args, "--print-build-logs") cmd.Args = append(cmd.Args, "--print-build-logs")
} }
cmd.Args = append(cmd.Args, rest...) cmd.Args = append(cmd.Args, rest...)
e.ExitWithCommand(cmd) exitWithCommand(cmd)
} }
func NixBuild(nom bool, minimal bool, rest ...string) { func NixBuild(nom bool, minimal bool, rest ...string) {
@ -284,7 +282,7 @@ func NixBuild(nom bool, minimal bool, rest ...string) {
cmd.Args = append(cmd.Args, "--log-format", "multiline") cmd.Args = append(cmd.Args, "--log-format", "multiline")
} }
cmd.Args = append(cmd.Args, rest...) cmd.Args = append(cmd.Args, rest...)
e.ExitWithCommand(cmd) exitWithCommand(cmd)
} }
func (o *Oizys) writeToGithubStepSummary(txt string) { func (o *Oizys) writeToGithubStepSummary(txt string) {
@ -334,12 +332,12 @@ func CacheBuild(rest ...string) {
args = append(args, NixosConfigAttrs()...) args = append(args, NixosConfigAttrs()...)
args = append(args, rest...) args = append(args, rest...)
cmd := exec.Command("cachix", args...) cmd := exec.Command("cachix", args...)
e.ExitWithCommand(cmd) exitWithCommand(cmd)
} }
func CI(rest ...string) { func CI(rest ...string) {
args := []string{"workflow", "run", "build.yml", "-F", fmt.Sprintf("hosts=%s", o.host)} args := []string{"workflow", "run", "build.yml", "-F", fmt.Sprintf("hosts=%s", o.host)}
args = append(args, rest...) args = append(args, rest...)
cmd := exec.Command("gh", args...) cmd := exec.Command("gh", args...)
e.ExitWithCommand(cmd) exitWithCommand(cmd)
} }

View file

@ -8,7 +8,6 @@ import (
"strings" "strings"
"github.com/charmbracelet/log" "github.com/charmbracelet/log"
e "oizys/internal/exec"
) )
var ignoredMap = stringSliceToMap( var ignoredMap = stringSliceToMap(
@ -129,7 +128,7 @@ func toBuildNixosConfiguration() []string {
if o.resetCache { if o.resetCache {
systemCmd.Args = append(systemCmd.Args, "--narinfo-cache-negative-ttl", "0") systemCmd.Args = append(systemCmd.Args, "--narinfo-cache-negative-ttl", "0")
} }
result, err := e.CmdOutputWithSpinner( result, err := cmdOutputWithSpinner(
systemCmd, systemCmd,
fmt.Sprintf("running dry build for: %s", strings.Join(NixosConfigAttrs(), " ")), fmt.Sprintf("running dry build for: %s", strings.Join(NixosConfigAttrs(), " ")),
true, true,
@ -144,7 +143,7 @@ func toBuildNixosConfiguration() []string {
func evaluateDerivations(drvs ...string) map[string]Derivation { func evaluateDerivations(drvs ...string) map[string]Derivation {
cmd := exec.Command("nix", "derivation", "show", "-r") cmd := exec.Command("nix", "derivation", "show", "-r")
cmd.Args = append(cmd.Args, drvs...) cmd.Args = append(cmd.Args, drvs...)
out, err := e.CmdOutputWithSpinner(cmd, out, err := cmdOutputWithSpinner(cmd,
fmt.Sprintf("evaluating derivations %s", strings.Join(drvs, " ")), fmt.Sprintf("evaluating derivations %s", strings.Join(drvs, " ")),
false) false)
if err != nil { if err != nil {