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 ( import (
"os" "os"
o "oizys/pkg"
cc "github.com/ivanpirog/coloredcobra" cc "github.com/ivanpirog/coloredcobra"
"github.com/spf13/cobra" "github.com/spf13/cobra"
o "oizys/pkg"
) )
func Execute() { func Execute() {

View file

@ -1,7 +1,9 @@
{ {
lib,
installShellFiles, installShellFiles,
buildGoModule, buildGoModule,
lib, makeWrapper,
gh,
... ...
}: }:
buildGoModule { buildGoModule {
@ -11,10 +13,18 @@ buildGoModule {
src = lib.cleanSource ./.; src = lib.cleanSource ./.;
vendorHash = "sha256-NCHU491j6fRfSk6LA9tS9yiuT/gZhPic46mNTVf1Jeg="; vendorHash = "sha256-NCHU491j6fRfSk6LA9tS9yiuT/gZhPic46mNTVf1Jeg=";
nativeBuildInputs = [ installShellFiles ]; nativeBuildInputs = [
installShellFiles
makeWrapper
];
postInstall = '' postInstall = ''
installShellCompletion --cmd oizys \ 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"
"os/exec" "os/exec"
"strings" "strings"
"time"
"github.com/muesli/termenv" "github.com/muesli/termenv"
"golang.org/x/term" "golang.org/x/term"
"time"
"github.com/briandowns/spinner" "github.com/briandowns/spinner"
) )
@ -159,7 +158,6 @@ func showFailedOutput(buf []byte) {
} }
func (o *Oizys) GitPull() { func (o *Oizys) GitPull() {
cmdOutput, err := o.git("status", "--porcelain").Output() cmdOutput, err := o.git("status", "--porcelain").Output()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@ -178,7 +176,6 @@ func (o *Oizys) GitPull() {
} }
} }
func parseDryRun(buf string) (*packages, *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
@ -267,10 +264,19 @@ func (o *Oizys) CacheBuild(rest ...string) {
} }
func (o *Oizys) CheckFlake() { func (o *Oizys) CheckFlake() {
if _, ok := os.LookupEnv("OIZYS_SKIP_CHECK"); !ok {
if _, err := os.Stat(o.flake); errors.Is(err, fs.ErrNotExist) { if _, err := os.Stat(o.flake); errors.Is(err, fs.ErrNotExist) {
log.Fatalln("path to flake:", o.flake, "does not exist") 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 { func Output(flake string, host string) string {
return fmt.Sprintf( return fmt.Sprintf(