Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
phm07 committed Jun 6, 2024
2 parents bf5e964 + fa9b366 commit 77aa0d4
Show file tree
Hide file tree
Showing 17 changed files with 67 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
uses: golangci/golangci-lint-action@v6
with:
# Required: the version of golangci-lint is required and must be specified with patch version
version: v1.58.2 # renovate: datasource=github-releases depName=golangci/golangci-lint
version: v1.59.0 # renovate: datasource=github-releases depName=golangci/golangci-lint
# In general linting is quite fast with warm caches, but a fresh run might take some time.
args: --timeout 5m

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v4
- uses: googleapis/release-please-action@v4
with:
token: ${{ secrets.HCLOUD_BOT_TOKEN }}
config-file: .github/release-please-config.json
Expand Down
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ workflow:

test:golangci-lint:
stage: test
image: golangci/golangci-lint:v1.58.2
image: golangci/golangci-lint:v1.59.0
script:
- golangci-lint run -v

Expand Down
56 changes: 21 additions & 35 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,28 @@ before:
- go mod tidy

builds:
- id: hcloud-build
main: ./cmd/hcloud/main.go
binary: hcloud
ldflags:
- -w
- -X {{ .ModulePath }}/internal/version.version={{ .Version }}
- -X {{ .ModulePath }}/internal/version.versionPrerelease={{- if .IsSnapshot -}}dev+{{ .ShortCommit }}{{- end -}}
env:
- CGO_ENABLED=0
goos:
- freebsd
- windows
- linux
goarch:
- amd64
- arm
- arm64
- "386"
goarm:
- "6"
- "7"
- <<: &build_defaults
main: ./cmd/hcloud/main.go
binary: hcloud
flags:
- -trimpath
ldflags:
- -s
- -w
- -X {{ .ModulePath }}/internal/version.version={{ .Version }}
- -X {{ .ModulePath }}/internal/version.versionPrerelease={{- if .IsSnapshot -}}dev+{{ .ShortCommit }}{{- end -}}
env:
- CGO_ENABLED=0

- id: hcloud-build-darwin
main: ./cmd/hcloud/main.go
binary: hcloud
ldflags:
- -w
- -X {{ .ModulePath }}/internal/version.version={{ .Version }}
- -X {{ .ModulePath }}/internal/version.versionPrerelease={{- if .IsSnapshot -}}dev+{{ .ShortCommit }}{{- end -}}
env:
- CGO_ENABLED=0
goos:
- darwin
goarch:
- amd64
- arm64
id: hcloud-build
goos: [freebsd, windows, linux]
goarch: [amd64, arm, arm64, "386"]
goarm: ["6", "7"]

- <<: *build_defaults
id: hcloud-build-darwin
goos: [darwin]
goarch: [amd64, arm64]
hooks:
post:
- cmd: >
Expand Down
2 changes: 2 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore:
- "**/zz_*.go"
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/goccy/go-yaml v1.11.3
github.com/golang/mock v1.6.0
github.com/guptarohit/asciigraph v0.7.1
github.com/hetznercloud/hcloud-go/v2 v2.8.0
github.com/hetznercloud/hcloud-go/v2 v2.9.0
github.com/jedib0t/go-pretty/v6 v6.5.9
github.com/pelletier/go-toml/v2 v2.2.2
github.com/spf13/cobra v1.8.0
Expand All @@ -36,7 +36,7 @@ require (
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.19.0 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
Expand All @@ -51,12 +51,12 @@ require (
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/tools v0.17.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/protobuf v1.32.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ github.com/guptarohit/asciigraph v0.7.1 h1:K+JWbRc04XEfv8BSZgNuvhCmpbvX4+9NYd/Ux
github.com/guptarohit/asciigraph v0.7.1/go.mod h1:dYl5wwK4gNsnFf9Zp+l06rFiDZ5YtXM6x7SRWZ3KGag=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hetznercloud/hcloud-go/v2 v2.8.0 h1:vfbfL/JfV8dIZUX7ANHWEbKNqgFWsETqvt/EctvoFJ0=
github.com/hetznercloud/hcloud-go/v2 v2.8.0/go.mod h1:jvpP3qAWMIZ3WQwQLYa97ia6t98iPCgsJNwRts+Jnrk=
github.com/hetznercloud/hcloud-go/v2 v2.9.0 h1:s0N6R7Zoi2DPfMtUF5o9VeUBzTtHVY6MIkHOQnfu/AY=
github.com/hetznercloud/hcloud-go/v2 v2.9.0/go.mod h1:qtW/TuU7Bs16ibXl/ktJarWqU2LwHr7eGlwoilHxtgg=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jedib0t/go-pretty/v6 v6.5.9 h1:ACteMBRrrmm1gMsXe9PSTOClQ63IXDUt03H5U+UV8OU=
Expand All @@ -67,8 +67,8 @@ github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU=
github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k=
github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE=
github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho=
github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=
github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI=
github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE=
Expand Down Expand Up @@ -129,8 +129,8 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -164,8 +164,8 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU=
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/server/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (

"github.com/hetznercloud/cli/internal/cmd/base"
"github.com/hetznercloud/cli/internal/cmd/cmpl"
"github.com/hetznercloud/cli/internal/cmd/util"
"github.com/hetznercloud/cli/internal/hcapi2"
"github.com/hetznercloud/cli/internal/state"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud/exp/actionutils"
"github.com/hetznercloud/hcloud-go/v2/hcloud/schema"
)

Expand Down Expand Up @@ -108,7 +108,7 @@ var CreateCmd = base.CreateCmd{
return nil, nil, err
}

if err := s.WaitForActions(cmd, s, util.MergeNextActions(result.Action, result.NextActions)...); err != nil {
if err := s.WaitForActions(cmd, s, actionutils.AppendNextActions(result.Action, result.NextActions)...); err != nil {
return nil, nil, err
}

Expand Down
10 changes: 0 additions & 10 deletions internal/cmd/util/action.go

This file was deleted.

18 changes: 0 additions & 18 deletions internal/cmd/util/action_test.go

This file was deleted.

3 changes: 2 additions & 1 deletion internal/cmd/volume/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hetznercloud/cli/internal/hcapi2"
"github.com/hetznercloud/cli/internal/state"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud/exp/actionutils"
)

var CreateCmd = base.CreateCmd{
Expand Down Expand Up @@ -97,7 +98,7 @@ var CreateCmd = base.CreateCmd{
return nil, nil, err
}

if err := s.WaitForActions(cmd, s, util.MergeNextActions(result.Action, result.NextActions)...); err != nil {
if err := s.WaitForActions(cmd, s, actionutils.AppendNextActions(result.Action, result.NextActions)...); err != nil {
return nil, nil, err
}
cmd.Printf("Volume %d created\n", result.Volume.ID)
Expand Down
8 changes: 4 additions & 4 deletions internal/state/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func TestWaitForActionsSuccess(t *testing.T) {

assert.Equal(t,
strings.Join([]string{
"Waiting for attach_volume to complete (server: 46830545, volume: 46830546) ...\n",
"Waiting for attach_volume to complete (server: 46830545, volume: 46830546) ... done\n",
"Waiting for attach_volume (server: 46830545, volume: 46830546) ...\n",
"Waiting for attach_volume (server: 46830545, volume: 46830546) ... done\n",
}, ""),
stderr,
)
Expand Down Expand Up @@ -92,8 +92,8 @@ func TestWaitForActionsError(t *testing.T) {

assert.Equal(t,
strings.Join([]string{
"Waiting for attach_volume to complete (server: 46830545, volume: 46830546) ...\n",
"Waiting for attach_volume to complete (server: 46830545, volume: 46830546) ... failed\n",
"Waiting for attach_volume (server: 46830545, volume: 46830546) ...\n",
"Waiting for attach_volume (server: 46830545, volume: 46830546) ... failed\n",
}, ""),
stderr,
)
Expand Down
2 changes: 1 addition & 1 deletion internal/ui/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func ActionMessage(action *hcloud.Action) string {
return fmt.Sprintf("Waiting for %s to complete", color.New(color.Bold).Sprint(action.Command))
return fmt.Sprintf("Waiting for %s", color.New(color.Bold).Sprint(action.Command))
}

// FakeActionMessage returns the initial value with a unused color to grow the string
Expand Down
14 changes: 7 additions & 7 deletions internal/ui/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestMessages(t *testing.T) {
{ID: 46830545, Type: hcloud.ActionResourceTypeServer},
},
},
wantAction: "Waiting for create_server to complete",
wantAction: "Waiting for create_server",
wantResources: "(server: 46830545)",
},
{
Expand All @@ -42,7 +42,7 @@ func TestMessages(t *testing.T) {
{ID: 46830546, Type: hcloud.ActionResourceTypeVolume},
},
},
wantAction: "Waiting for attach_volume to complete",
wantAction: "Waiting for attach_volume",
wantResources: "(server: 46830545, volume: 46830546)",
},
{
Expand All @@ -53,7 +53,7 @@ func TestMessages(t *testing.T) {
Status: hcloud.ActionStatusRunning,
Progress: 0,
},
wantAction: "Waiting for create_server to complete",
wantAction: "Waiting for create_server",
wantResources: "",
},
}
Expand All @@ -73,9 +73,9 @@ func TestFakeActionMessages(t *testing.T) {
fakeMessage := FakeActionMessage("Some random message")

// The padding is important
actionMessage = fmt.Sprintf("%-60s", actionMessage)
fakeMessage = fmt.Sprintf("%-60s", fakeMessage)
actionMessage = fmt.Sprintf("%-40s", actionMessage)
fakeMessage = fmt.Sprintf("%-40s", fakeMessage)

assert.Equal(t, actionMessage, "Waiting for create_server to complete ")
assert.Equal(t, fakeMessage, "Some random message ")
assert.Equal(t, "Waiting for create_server ", actionMessage)
assert.Equal(t, "Some random message ", fakeMessage)
}
10 changes: 10 additions & 0 deletions internal/ui/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,13 @@ import (
func StdoutIsTerminal() bool {
return term.IsTerminal(int(os.Stdout.Fd()))
}

// TerminalWidth returns the width of the terminal.
func TerminalWidth() int {
width, _, err := term.GetSize(int(os.Stdout.Fd()))
if err != nil {
return 0
}

return width
}
4 changes: 2 additions & 2 deletions internal/ui/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type ProgressGroup interface {
}

func NewProgressGroup(output io.Writer) ProgressGroup {
if StdoutIsTerminal() {
if StdoutIsTerminal() && TerminalWidth() > 80 {
return newTerminalProgressGroup(output)
} else {
return newScriptProgressGroup(output)
Expand All @@ -26,7 +26,7 @@ type Progress interface {
}

func NewProgress(output io.Writer, message string, resources string) Progress {
if StdoutIsTerminal() {
if StdoutIsTerminal() && TerminalWidth() > 80 {
return newTerminalProgress(output, message, resources)
} else {
return newScriptProgress(output, message, resources)
Expand Down
2 changes: 1 addition & 1 deletion internal/ui/progress_terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func newTerminalProgress(output io.Writer, message string, resources string) *te
p := &terminalProgress{pb.New(100)}
p.el.SetWriter(output)
p.el.SetTemplateString(termProgressRunning)
p.el.Set("message", fmt.Sprintf("%-60s", message))
p.el.Set("message", fmt.Sprintf("%-40s", message))
p.el.Set("resources", resources)
return p
}
Expand Down

0 comments on commit 77aa0d4

Please sign in to comment.