feat: improve logging/flow

This commit is contained in:
2024-12-23 20:32:06 +02:00
parent ae2c2dfbe2
commit ab85fe77be
5 changed files with 67 additions and 11 deletions

View File

@@ -13,7 +13,8 @@ type GroupInstaller struct {
}
type GroupOpts struct {
BinName *string
BinName *string
CheckHasUpdate *string
}
// Install implements IInstaller.
@@ -24,7 +25,11 @@ func (i *GroupInstaller) Install() error {
if err != nil {
return err
}
RunInstaller(i.Config, installer)
if installer == nil {
logger.Warn("Installer type %s is not supported, skipping", step.Type)
} else {
RunInstaller(i.Config, installer)
}
}
return nil
}
@@ -36,6 +41,14 @@ func (i *GroupInstaller) Update() error {
// CheckNeedsUpdate implements IInstaller.
func (i *GroupInstaller) CheckNeedsUpdate() (error, bool) {
if i.GetOpts().CheckHasUpdate != nil {
cmd := exec.Command("sh", "-c", *i.GetOpts().CheckHasUpdate)
err := cmd.Run()
if err != nil {
return err, true
}
return nil, false
}
return nil, false
}
@@ -61,6 +74,9 @@ func (i *GroupInstaller) GetOpts() *GroupOpts {
if binName, ok := (*info.Opts)["bin_name"].(string); ok {
opts.BinName = &binName
}
if command, ok := (*info.Opts)["check_has_update"].(string); ok {
opts.CheckHasUpdate = &command
}
}
return opts
}

View File

@@ -25,7 +25,7 @@ func GetInstaller(config *appconfig.AppConfig, installer *appconfig.Installer) (
case appconfig.InstallerTypeShell:
return nil, NewShellInstaller(config, installer)
}
return fmt.Errorf("Installer type %s is not supported", installer.Type), nil
return nil, nil
}
func GetCurrentPlatform() appconfig.Platform {

View File

@@ -15,9 +15,9 @@ type ShellInstaller struct {
}
type ShellOpts struct {
Command *string
BinName *string
UpdateCheckCommand *string
Command *string
BinName *string
CheckHasUpdate *string
}
// Install implements IInstaller.
@@ -47,7 +47,14 @@ func (i *ShellInstaller) Update() error {
// CheckNeedsUpdate implements IInstaller.
func (i *ShellInstaller) CheckNeedsUpdate() (error, bool) {
if i.GetOpts().CheckHasUpdate != nil {
cmd := exec.Command("sh", "-c", *i.GetOpts().CheckHasUpdate)
err := cmd.Run()
if err != nil {
return err, true
}
return nil, false
}
return nil, false
}
@@ -77,6 +84,9 @@ func (i *ShellInstaller) GetOpts() *ShellOpts {
if binName, ok := (*info.Opts)["bin_name"].(string); ok {
opts.BinName = &binName
}
if command, ok := (*info.Opts)["check_has_update"].(string); ok {
opts.CheckHasUpdate = &command
}
}
return opts
}

12
main.go
View File

@@ -24,10 +24,14 @@ func main() {
logger.Error("%s", err)
return
}
err = installer.RunInstaller(cfg, installerInstance)
if err != nil {
logger.Error("%s", err)
os.Exit(1)
if installerInstance == nil {
logger.Warn("Installer type %s is not supported, skipping", i.Type)
} else {
err = installer.RunInstaller(cfg, installerInstance)
if err != nil {
logger.Error("%s", err)
os.Exit(1)
}
}
}
}

View File

@@ -46,5 +46,31 @@ install:
only: ['linux']
opts:
command: 'curl https://pyenv.run | bash'
- name: pipx
type: group
steps:
- name: pipx
type: brew
platforms:
only: ['macos']
opts:
post_command: |
sudo pipx ensurepath --global
- name: pipx
type: apt
platforms:
only: ['linux']
opts:
post_command: |
sudo pipx ensurepath --global
- name: jq
type: brew
platforms:
only: ['macos']
- name: yq
type: shell
opts:
command: pipx install yq