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:
- name: Checkout
uses: actions/checkout@v4
- run: git checkout -B flake-lock
with:
ref: flake-lock
- name: Setup Git Bot
run: |
@ -39,9 +40,7 @@ jobs:
- name: Update nix flake
run: |
printf '# Flake Lock\n\n```txt\n' >> $GITHUB_STEP_SUMMARY
nix flake update --commit-lock-file 2>> $GITHUB_STEP_SUMMARY
printf '```\n' >> $GITHUB_STEP_SUMMARY
- name: Build
run: |
@ -64,7 +63,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- run: git checkout -B flake-lock
with:
ref: flake-lock
# - name: Setup Git Bot
# 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"
)
func LogCmd(cmd *exec.Cmd) {
func logCmd(cmd *exec.Cmd) {
log.Debugf("CMD: %s", strings.Join(cmd.Args, " "))
}
func CmdOutputWithSpinner(cmd *exec.Cmd, msg string, stderr bool) (output []byte, err error) {
LogCmd(cmd)
func cmdOutputWithSpinner(cmd *exec.Cmd, msg string, stderr bool) (output []byte, err error) {
logCmd(cmd)
s := startSpinner(msg)
if stderr {
output, err = cmd.CombinedOutput()
@ -38,8 +38,8 @@ func startSpinner(msg string) *spinner.Spinner {
return s
}
func ExitWithCommand(cmd *exec.Cmd) {
LogCmd(cmd)
func exitWithCommand(cmd *exec.Cmd) {
logCmd(cmd)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {

View file

@ -1,4 +1,4 @@
package ui
package oizys
import (
"fmt"
@ -11,17 +11,6 @@ import (
"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
func terminalSize() (int, int) {
fd := os.Stdout.Fd()
@ -36,13 +25,13 @@ func terminalSize() (int, int) {
return w, h
}
type Packages struct {
type packages struct {
desc string
names []string
pad int
}
func ParsePackages(lines []string, desc string) *Packages {
func parsePackages(lines []string, desc string) *packages {
w, _ := terminalSize()
maxAcceptable := (w / 4) - 1
maxLen := 0
@ -59,7 +48,7 @@ func ParsePackages(lines []string, desc string) *Packages {
names[i] = name
}
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 {
@ -73,7 +62,7 @@ func ellipsis(s string, maxLen int) string {
return string(runes[0:maxLen-3]) + "..."
}
func (p *Packages) Show(verbose bool) {
func (p *packages) show(verbose bool) {
p.summary()
if !verbose || (len(p.names) == 0) {
return
@ -92,7 +81,7 @@ func (p *Packages) Show(verbose bool) {
fmt.Println()
}
func (p *Packages) summary() {
func (p *packages) summary() {
fmt.Printf("%s: %s\n",
p.desc,
lipgloss.NewStyle().
@ -101,3 +90,14 @@ func (p *Packages) summary() {
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"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/log"
e "oizys/internal/exec"
"oizys/internal/ui"
"github.com/charmbracelet/log"
)
var o *Oizys
@ -131,7 +129,7 @@ func git(rest ...string) *exec.Cmd {
args := []string{"-C", o.flake}
args = append(args, rest...)
cmd := exec.Command("git", args...)
e.LogCmd(cmd)
logCmd(cmd)
return cmd
}
@ -143,18 +141,18 @@ func GitPull() {
if len(cmdOutput) > 0 {
fmt.Println("unstaged commits, cowardly exiting...")
ui.ShowFailedOutput(cmdOutput)
showFailedOutput(cmdOutput)
os.Exit(1)
}
cmdOutput, err = git("pull").CombinedOutput()
if err != nil {
ui.ShowFailedOutput(cmdOutput)
showFailedOutput(cmdOutput)
log.Fatal(err)
}
}
func parseDryRun(buf string) (*ui.Packages, *ui.Packages) {
func parseDryRun(buf string) (*packages, *packages) {
lines := strings.Split(strings.TrimSpace(buf), "\n")
var parts [2][]string
i := 0
@ -175,8 +173,8 @@ func parseDryRun(buf string) (*ui.Packages, *ui.Packages) {
os.Exit(0)
}
return ui.ParsePackages(parts[0], "packages to build"),
ui.ParsePackages(parts[1], "packages to fetch")
return parsePackages(parts[0], "packages to build"),
parsePackages(parts[1], "packages to fetch")
}
// TODO: Refactor this and above
@ -205,8 +203,8 @@ func parseDryRun2(buf string) ([]string, []string) {
// TODO: refactor to account for --debug and not --verbose?
func showDryRunResult(nixOutput string, verbose bool) {
toBuild, toFetch := parseDryRun(nixOutput)
toFetch.Show(o.debug)
toBuild.Show(true)
toFetch.show(o.debug)
toBuild.show(true)
}
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),
)
}
result, err := e.CmdOutputWithSpinner(cmd, spinnerMsg, true)
result, err := cmdOutputWithSpinner(cmd, spinnerMsg, true)
if err != nil {
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, rest...)
e.ExitWithCommand(cmd)
exitWithCommand(cmd)
}
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, rest...)
e.ExitWithCommand(cmd)
exitWithCommand(cmd)
}
func (o *Oizys) writeToGithubStepSummary(txt string) {
@ -334,12 +332,12 @@ func CacheBuild(rest ...string) {
args = append(args, NixosConfigAttrs()...)
args = append(args, rest...)
cmd := exec.Command("cachix", args...)
e.ExitWithCommand(cmd)
exitWithCommand(cmd)
}
func CI(rest ...string) {
args := []string{"workflow", "run", "build.yml", "-F", fmt.Sprintf("hosts=%s", o.host)}
args = append(args, rest...)
cmd := exec.Command("gh", args...)
e.ExitWithCommand(cmd)
exitWithCommand(cmd)
}

View file

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