Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,53 @@ on:
- master

jobs:
gofmt:
name: Go Format Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Check Go formatting
run: |
if [ -n "$(gofmt -s -l .)" ]; then
echo "Go code is not formatted. Please run 'gofmt -s -w .'"
gofmt -s -d .
exit 1
fi

golangci-lint:
name: Go Linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
args: --timeout=5m

go-mod-tidy:
name: Go Modules Tidy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Check if go.mod is tidy
run: |
go mod tidy
if [ -n "$(git diff --name-only)" ]; then
echo "go.mod is not tidy. Please run 'go mod tidy'"
git diff
exit 1
fi

test:
runs-on: ubuntu-latest
steps:
Expand Down
6 changes: 3 additions & 3 deletions cli_config/cli_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ func (c *Config) LoadFile(path string) error {
return fmt.Errorf("%w: %s", InvalidConfigErr, err)
}

if c.Vm.Manager != "lima" && c.Vm.Manager != "auto" && c.Vm.Manager != "mock" {
if c.Vm.Manager != "" && c.Vm.Manager != "lima" && c.Vm.Manager != "auto" && c.Vm.Manager != "mock" {
return fmt.Errorf("%w: unsupported value for `vm.manager`. Must be one of: auto, lima", InvalidConfigErr)
}

if c.Vm.Ubuntu != "18.04" && c.Vm.Ubuntu != "20.04" && c.Vm.Ubuntu != "22.04" && c.Vm.Ubuntu != "24.04" {
if c.Vm.Ubuntu != "" && c.Vm.Ubuntu != "18.04" && c.Vm.Ubuntu != "20.04" && c.Vm.Ubuntu != "22.04" && c.Vm.Ubuntu != "24.04" {
return fmt.Errorf("%w: unsupported value for `vm.ubuntu`. Must be one of: 18.04, 20.04, 22.04, 24.04", InvalidConfigErr)
}

if c.Vm.HostsResolver != "hosts_file" {
if c.Vm.HostsResolver != "" && c.Vm.HostsResolver != "hosts_file" {
return fmt.Errorf("%w: unsupported value for `vm.hosts_resolver`. Must be one of: hosts_file", InvalidConfigErr)
}

Expand Down
8 changes: 6 additions & 2 deletions cli_config/cli_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ open:
t.Fatal(err)
}

conf.LoadFile(path)
if err := conf.LoadFile(path); err != nil {
t.Fatal(err)
}

if conf.LoadPlugins != true {
t.Errorf("expected LoadPlugins to be true (default value)")
Expand All @@ -53,7 +55,9 @@ func TestLoadEnv(t *testing.T) {
AskVaultPass: false,
}

conf.LoadEnv("TRELLIS_")
if err := conf.LoadEnv("TRELLIS_"); err != nil {
t.Fatal(err)
}

if conf.AskVaultPass != true {
t.Errorf("expected AskVaultPass to be true")
Expand Down
16 changes: 8 additions & 8 deletions cmd/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (c *AliasCommand) Run(args []string) int {
FailMessage: "Error generating config",
},
)
spinner.Start()
_ = spinner.Start()

environments := c.Trellis.EnvironmentNames()
var envsToAlias []string
Expand All @@ -102,7 +102,7 @@ func (c *AliasCommand) Run(args []string) int {

tempDir, tempDirErr := os.MkdirTemp("", "trellis-alias-")
if tempDirErr != nil {
spinner.StopFail()
_ = spinner.StopFail()
c.UI.Error(tempDirErr.Error())
return 1
}
Expand All @@ -127,7 +127,7 @@ func (c *AliasCommand) Run(args []string) int {
_, site, err := c.Trellis.MainSiteFromEnvironment(environment)

if err != nil {
spinner.StopFail()
_ = spinner.StopFail()
c.UI.Error(err.Error())
return 1
}
Expand All @@ -143,7 +143,7 @@ func (c *AliasCommand) Run(args []string) int {
).Cmd("ansible-playbook", playbook.CmdArgs())

if err := aliasPlaybook.Run(); err != nil {
spinner.StopFail()
_ = spinner.StopFail()
c.UI.Error("Error creating WP-CLI aliases. Temporary playbook failed to execute:")
c.UI.Error(mockUi.ErrorWriter.String())
return 1
Expand All @@ -154,7 +154,7 @@ func (c *AliasCommand) Run(args []string) int {
for _, environment := range envsToAlias {
part, err := os.ReadFile(filepath.Join(tempDir, environment+".yml.part"))
if err != nil {
spinner.StopFail()
_ = spinner.StopFail()
c.UI.Error(err.Error())
return 1
}
Expand All @@ -164,7 +164,7 @@ func (c *AliasCommand) Run(args []string) int {
combinedYmlPath := filepath.Join(tempDir, "/combined.yml")
writeFileErr := os.WriteFile(combinedYmlPath, []byte(combined), 0644)
if writeFileErr != nil {
spinner.StopFail()
_ = spinner.StopFail()
c.UI.Error(writeFileErr.Error())
return 1
}
Expand All @@ -185,13 +185,13 @@ func (c *AliasCommand) Run(args []string) int {
).Cmd("ansible-playbook", playbook.CmdArgs())

if err := aliasCopyPlaybook.Run(); err != nil {
spinner.StopFail()
_ = spinner.StopFail()
c.UI.Error("Error creating WP-CLI aliases. Temporary playbook failed to execute:")
c.UI.Error(mockUi.ErrorWriter.String())
return 1
}

spinner.Stop()
_ = spinner.Stop()
c.UI.Info("")
message := `
Action Required: use the generated config by adding these lines to site/wp-cli.yml or an alternative wp-cli.yml (or wp-cli.local.yml) config.
Expand Down
2 changes: 1 addition & 1 deletion cmd/alias_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestIntegrationAlias(t *testing.T) {
alias := exec.Command(bin, "alias")
alias.Dir = path.Join(dummy, "trellis")

alias.Run()
_ = alias.Run()

if _, err := os.Stat(actualPath); os.IsNotExist(err) {
t.Error("wp-cli.trellis-alias.yml file not generated")
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ func TestHelperProcess(t *testing.T) {
return
}

fmt.Fprintf(os.Stdout, strings.Join(os.Args[3:], " "))
fmt.Fprint(os.Stdout, strings.Join(os.Args[3:], " "))
os.Exit(0)
}
2 changes: 1 addition & 1 deletion cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (c *DeployCommand) Run(args []string) int {
}

if environment == "development" {
if c.Trellis.CliConfig.AllowDevelopmentDeploys == false {
if !c.Trellis.CliConfig.AllowDevelopmentDeploys {
c.UI.Error(`
Error: deploying to the development environment is not supported by default.

Expand Down
6 changes: 3 additions & 3 deletions cmd/dot_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (c *DotEnvCommand) Run(args []string) int {
FailMessage: "Error templating .env file",
},
)
spinner.Start()
_ = spinner.Start()

environment := "development"
if len(args) == 1 {
Expand Down Expand Up @@ -85,12 +85,12 @@ func (c *DotEnvCommand) Run(args []string) int {
).Cmd("ansible-playbook", playbook.CmdArgs())

if err := dotenv.Run(); err != nil {
spinner.StopFail()
_ = spinner.StopFail()
c.UI.Error(mockUi.ErrorWriter.String())
return 1
}

spinner.Stop()
_ = spinner.Stop()
return 0
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/dot_env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestIntegrationDotEnv(t *testing.T) {
dotEnv := exec.Command(bin, "dotenv")
dotEnv.Dir = filepath.Join(dummy, "trellis")

dotEnv.Run()
_ = dotEnv.Run()

if _, err := os.Stat(actualPath); os.IsNotExist(err) {
t.Error(".env file not generated")
Expand Down
14 changes: 7 additions & 7 deletions cmd/droplet_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/digitalocean/godo"
"github.com/digitalocean/godo/util"
"github.com/fatih/color"
"github.com/manifoldco/promptui"
"github.com/hashicorp/cli"
"github.com/manifoldco/promptui"
"github.com/posener/complete"
"github.com/roots/trellis-cli/digitalocean"
"github.com/roots/trellis-cli/trellis"
Expand Down Expand Up @@ -263,16 +263,16 @@ func (c *DropletCreateCommand) createDroplet(region string, size string, image s
},
)

s.Start()
_ = s.Start()
err = util.WaitForActive(context.TODO(), c.doClient.Client, monitorUri)

if err != nil {
s.StopFail()
_ = s.StopFail()
c.UI.Error(err.Error())
return nil, err
}

s.Stop()
_ = s.Stop()

return droplet, nil
}
Expand Down Expand Up @@ -382,13 +382,13 @@ func (c *DropletCreateCommand) waitForSSH(droplet *godo.Droplet) (*godo.Droplet,
FailMessage: "Timeout waiting for SSH",
},
)
s.Start()
_ = s.Start()
err = digitalocean.CheckSSH(ip, ctx)

if err != nil {
s.StopFail()
_ = s.StopFail()
}
s.Stop()
_ = s.Stop()

return droplet, nil
}
4 changes: 2 additions & 2 deletions cmd/droplet_dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

"github.com/digitalocean/godo"
"github.com/fatih/color"
"github.com/manifoldco/promptui"
"github.com/hashicorp/cli"
"github.com/manifoldco/promptui"
"github.com/posener/complete"
"github.com/roots/trellis-cli/digitalocean"
"github.com/roots/trellis-cli/trellis"
Expand Down Expand Up @@ -261,5 +261,5 @@ func (c *DropletDnsCommand) selectIP() (ip string, err error) {
}

ip, err = droplets[i].PublicIPv4()
return ip, nil
return ip, err
}
2 changes: 1 addition & 1 deletion cmd/galaxy_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestGalaxyInstallRun(t *testing.T) {
galaxyInstallCommand := GalaxyInstallCommand{ui, trellis}

for _, file := range tc.roleFiles {
os.Create(file)
_, _ = os.Create(file)
}

code := galaxyInstallCommand.Run(tc.args)
Expand Down
26 changes: 13 additions & 13 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,16 @@ func (c *InitCommand) deleteVirtualenv() error {
FailMessage: "Error deleting virtualenv",
},
)
spinner.Start()
_ = spinner.Start()
err := c.Trellis.Virtualenv.Delete()

if err != nil {
spinner.StopFail()
_ = spinner.StopFail()
c.UI.Error(err.Error())
return err
}

spinner.Stop()
_ = spinner.Stop()

return nil
}
Expand All @@ -191,10 +191,10 @@ func (c *InitCommand) createVirtualenv(virtualenvCmd *exec.Cmd) error {
},
)

spinner.Start()
_ = spinner.Start()
err := c.Trellis.Virtualenv.Create()
if err != nil {
spinner.StopFail()
_ = spinner.StopFail()
c.UI.Error(err.Error())
c.UI.Error("")
c.UI.Error("Project initialization failed due to the error above.")
Expand All @@ -207,7 +207,7 @@ func (c *InitCommand) createVirtualenv(virtualenvCmd *exec.Cmd) error {
}

c.Trellis.VenvInitialized = true
spinner.Stop()
_ = spinner.Stop()

return nil
}
Expand All @@ -219,16 +219,16 @@ func (c *InitCommand) upgradePip() error {
FailMessage: "Error upgrading pip",
},
)
spinner.Start()
_ = spinner.Start()
pipUpgradeOutput, err := command.Cmd("python3", []string{"-m", "pip", "install", "--upgrade", "pip"}).CombinedOutput()

if err != nil {
spinner.StopFail()
_ = spinner.StopFail()
c.UI.Error(string(pipUpgradeOutput))
return err
}

spinner.Stop()
_ = spinner.Stop()
return nil
}

Expand All @@ -240,7 +240,7 @@ func (c *InitCommand) pipInstall() error {
StopMessage: "Dependencies installed",
},
)
spinner.Start()
_ = spinner.Start()
pipCmd := command.Cmd("pip", []string{"install", "-r", "requirements.txt"})

// Wrap pipCmd's Stdout in a custom writer that only displays output once the timer has elapsed.
Expand All @@ -250,7 +250,7 @@ func (c *InitCommand) pipInstall() error {

go func() {
<-timer.C
spinner.Pause()
_ = spinner.Pause()
writer.writer = os.Stdout
c.UI.Warn("\n\npip install taking longer than expected. Switching to verbose output:\n")
}()
Expand All @@ -260,11 +260,11 @@ func (c *InitCommand) pipInstall() error {
err := pipCmd.Run()

if err != nil {
spinner.StopFail()
_ = spinner.StopFail()
c.UI.Error(errorOutput.String())
return err
}

spinner.Stop()
_ = spinner.Stop()
return nil
}
Loading
Loading