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,
) {
@ -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)
@ -178,7 +176,6 @@ func (o *Oizys) GitPull() {
}
}
func parseDryRun(buf string) (*packages, *packages) {
lines := strings.Split(strings.TrimSpace(buf), "\n")
var parts [2][]string
@ -267,9 +264,18 @@ func (o *Oizys) CacheBuild(rest ...string) {
}
func (o *Oizys) CheckFlake() {
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 {