add ci command to oizys-cli

This commit is contained in:
Daylin Morgan 2024-05-24 11:50:18 -05:00
parent 7ff50c1310
commit c58213dfb5
Signed by: daylin
GPG key ID: 950D13E9719334AD
4 changed files with 53 additions and 16 deletions

View file

@ -0,0 +1,20 @@
package cmd
import (
"github.com/spf13/cobra"
)
// gh workflow run build.yml -F lockFile=@flake.lock
var ciCmd= &cobra.Command{
Use: "ci",
Short: "offload build to GHA",
Run: func(cmd *cobra.Command, args []string) {
oizys.CI(args...)
},
}
func init() {
rootCmd.AddCommand(ciCmd)
}

View file

@ -3,9 +3,10 @@ package cmd
import (
"os"
o "oizys/pkg"
cc "github.com/ivanpirog/coloredcobra"
"github.com/spf13/cobra"
o "oizys/pkg"
)
func Execute() {

View file

@ -1,7 +1,9 @@
{
lib,
installShellFiles,
buildGoModule,
lib,
makeWrapper,
gh,
...
}:
buildGoModule {
@ -11,10 +13,18 @@ buildGoModule {
src = lib.cleanSource ./.;
vendorHash = "sha256-NCHU491j6fRfSk6LA9tS9yiuT/gZhPic46mNTVf1Jeg=";
nativeBuildInputs = [ installShellFiles ];
nativeBuildInputs = [
installShellFiles
makeWrapper
];
postInstall = ''
installShellCompletion --cmd oizys \
--zsh <($out/bin/oizys completion zsh)
--zsh <(OIZYS_SKIP_CHECK=true $out/bin/oizys completion zsh)
'';
postFixup = ''
wrapProgram $out/bin/oizys \
--prefix PATH ${lib.makeBinPath [ gh ]}
'';
}

View file

@ -8,12 +8,11 @@ import (
"os"
"os/exec"
"strings"
"time"
"github.com/muesli/termenv"
"golang.org/x/term"
"time"
"github.com/briandowns/spinner"
)
@ -52,7 +51,7 @@ func (o *Oizys) Output() string {
)
}
func (o *Oizys) Set (
func (o *Oizys) Set(
flake, host, cache string,
verbose bool,
) {
@ -118,7 +117,7 @@ func ellipsis(s string, maxLen int) string {
func (p *packages) show(verbose bool) {
p.summary()
if !verbose || (len(p.names) == 0) {
if !verbose || (len(p.names) == 0) {
return
}
@ -159,7 +158,6 @@ func showFailedOutput(buf []byte) {
}
func (o *Oizys) GitPull() {
cmdOutput, err := o.git("status", "--porcelain").Output()
if err != nil {
log.Fatal(err)
@ -171,14 +169,13 @@ func (o *Oizys) GitPull() {
os.Exit(1)
}
cmdOutput, err = o.git("pull").CombinedOutput()
cmdOutput, err = o.git("pull").CombinedOutput()
if err != nil {
showFailedOutput(cmdOutput)
log.Fatal(err)
}
}
func parseDryRun(buf string) (*packages, *packages) {
lines := strings.Split(strings.TrimSpace(buf), "\n")
var parts [2][]string
@ -232,10 +229,10 @@ func (o *Oizys) NixosRebuild(subcmd string, rest ...string) {
o.flake,
}
args = append(args, rest...)
if o.verbose {
args = append(args, "--print-build-logs")
if o.verbose {
args = append(args, "--print-build-logs")
fmt.Println("CMD:", "sudo", strings.Join(args, " "))
}
}
cmd := exec.Command("sudo", args...)
runCommand(cmd)
}
@ -267,11 +264,20 @@ func (o *Oizys) CacheBuild(rest ...string) {
}
func (o *Oizys) CheckFlake() {
if _, err := os.Stat(o.flake); errors.Is(err, fs.ErrNotExist) {
log.Fatalln("path to flake:", o.flake, "does not exist")
if _, ok := os.LookupEnv("OIZYS_SKIP_CHECK"); !ok {
if _, err := os.Stat(o.flake); errors.Is(err, fs.ErrNotExist) {
log.Fatalln("path to flake:", o.flake, "does not exist")
}
}
}
func (o *Oizys) CI(rest ...string) {
args := []string{"workflow", "run", "build.yml", "-F", fmt.Sprintf("host=%s", o.host)}
args = append(args, rest...)
cmd := exec.Command("gh", args...)
runCommand(cmd)
}
func Output(flake string, host string) string {
return fmt.Sprintf(
"%s#nixosConfigurations.%s.config.system.build.toplevel",