Skip to content

Commit

Permalink
Merge branch 'digitalocean:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
titanventura authored Oct 28, 2023
2 parents 1915f37 + 0191117 commit 6173bbe
Show file tree
Hide file tree
Showing 27 changed files with 424 additions and 120 deletions.
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ updates:
schedule:
interval: weekly
open-pull-requests-limit: 10
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: weekly
13 changes: 3 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,12 @@ jobs:
os: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Restore cache
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Ensure code is formatted with gofmt
run: make gofmt_check
if: matrix.os == 'ubuntu-latest'
Expand Down
22 changes: 7 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,26 @@ jobs:
runs-on: 'ubuntu-latest'
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
# https://github.com/marketplace/actions/goreleaser-action#usage
# note the fetch-depth: 0 input in Checkout step. It is required for
# the changelog to work correctly
fetch-depth: 0

- name: Login to Docker Hub
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Install Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: 1.21.x

- name: Restore cache
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
Expand All @@ -51,18 +43,18 @@ jobs:
runs-on: 'ubuntu-latest'
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
# fetch-depth: 0 fetches all history for all branches and tags
fetch-depth: 0

- name: Login to Docker Hub
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Buld snap
- name: Build snap
id: build
run: |
make _build_snap && \
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/snapcraft-candidate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ jobs:
fetch-depth: 0

- name: Login to Docker Hub
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Buld snap
- name: Build snap
id: build
run: |
make _build_snap && \
Expand Down
17 changes: 7 additions & 10 deletions commands/activations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package commands
import (
"bytes"
"errors"
"sort"
"strconv"
"strings"
"testing"
Expand All @@ -37,9 +36,7 @@ func TestActivationsCommand(t *testing.T) {
names = append(names, c.Name())
}

sort.Strings(expected)
sort.Strings(names)
assert.Equal(t, expected, names)
assert.ElementsMatch(t, expected, names)
}

var hello1Result = whisk.Result(map[string]interface{}{
Expand Down Expand Up @@ -369,7 +366,7 @@ func TestActivationsList(t *testing.T) {
}

if k == "limit" {
limit, _ = strconv.ParseInt(v, 0, 64)
limit, _ = strconv.Atoi(v)
}

if k == "since" {
Expand All @@ -381,7 +378,7 @@ func TestActivationsList(t *testing.T) {
}

if k == "skip" {
skip, _ = strconv.ParseInt(v, 0, 64)
skip, _ = strconv.Atoi(v)
}

if v == "" {
Expand Down Expand Up @@ -417,11 +414,11 @@ func TestActivationsList(t *testing.T) {
expectedListOptions.Name = config.Args[0]
}
if limit != nil {
expectedListOptions.Limit = int(limit.(int64))
expectedListOptions.Limit = limit.(int)
}

if skip != nil {
expectedListOptions.Skip = int(skip.(int64))
expectedListOptions.Skip = skip.(int)
}
tm.serverless.EXPECT().ListActivations(expectedListOptions).Return(theActivations, nil)
}
Expand Down Expand Up @@ -475,7 +472,7 @@ func TestActivationsLogs(t *testing.T) {
if tt.doctlFlags != nil {
for k, v := range tt.doctlFlags {
if k == "limit" {
limit, _ = strconv.ParseInt(v, 0, 64)
limit, _ = strconv.Atoi(v)
}

if k == "follow" {
Expand Down Expand Up @@ -507,7 +504,7 @@ func TestActivationsLogs(t *testing.T) {
} else {
expectedListOptions := whisk.ActivationListOptions{Docs: true}
if limit != nil {
expectedListOptions.Limit = int(limit.(int64))
expectedListOptions.Limit = limit.(int)
}

if funcName != nil {
Expand Down
10 changes: 8 additions & 2 deletions commands/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,9 +704,9 @@ Optionally, pass a deployment ID to get the spec of that specific deployment.`,
AddStringFlag(getCmd, doctl.ArgAppDeployment, "", "", "optional: a deployment ID")
AddStringFlag(getCmd, doctl.ArgFormat, "", "yaml", `the format to output the spec in; either "yaml" or "json"`)

validateCmd := CmdBuilder(cmd, RunAppsSpecValidate, "validate <spec file>", "Validate an application spec", `Use this command to check whether a given app spec (YAML or JSON) is valid.
validateCmd := cmdBuilderWithInit(cmd, RunAppsSpecValidate, "validate <spec file>", "Validate an application spec", `Use this command to check whether a given app spec (YAML or JSON) is valid.
You may pass - as the filename to read from stdin.`, Writer)
You may pass - as the filename to read from stdin.`, Writer, false)
AddBoolFlag(validateCmd, doctl.ArgSchemaOnly, "", false, "Only validate the spec schema and not the correctness of the spec.")

return cmd
Expand Down Expand Up @@ -762,6 +762,7 @@ func RunAppsSpecGet(c *CmdConfig) error {
}

// RunAppsSpecValidate validates an app spec file
// doesn't require auth & connection to the API with doctl.ArgSchemaOnly flag
func RunAppsSpecValidate(c *CmdConfig) error {
if len(c.Args) < 1 {
return doctl.NewMissingArgsErr(c.NS)
Expand All @@ -778,6 +779,7 @@ func RunAppsSpecValidate(c *CmdConfig) error {
return err
}

// validate schema only (offline)
if schemaOnly {
ymlSpec, err := yaml.Marshal(appSpec)
if err != nil {
Expand All @@ -787,6 +789,10 @@ func RunAppsSpecValidate(c *CmdConfig) error {
return err
}

// validate the spec against the API
if err := c.initServices(c); err != nil {
return err
}
res, err := c.Apps().Propose(&godo.AppProposeRequest{
Spec: appSpec,
})
Expand Down
7 changes: 6 additions & 1 deletion commands/cdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ Currently, you can only update the custom domain and its certificate ID with thi
This is useful when you need to ensure that files which were recently changed on the origin server are immediately available via the CDN.
To purge specific files, you can use the `+"`"+`--files`+"`"+` flag and supply a path. The path may be for a single file or may contain a wildcard (`+"`"+`*`+"`"+`) to recursively purge all files under a directory. When only a wildcard is provided, or no path is provided, all cached files will be purged.`, Writer,
To purge specific files, you can use the `+"`"+`--files`+"`"+` flag and supply a path. The path may be for a single file or may contain a wildcard (`+"`"+`*`+"`"+`) to recursively purge all files under a directory. When only a wildcard is provided, or no path is provided, all cached files will be purged.
Examples:
doctl compute cdn flush <cdn-id> --files /path/to/assets/*
doctl compute cdn flush <cdn-id> --files "/path/to/file.one, /path/to/file.two"
doctl compute cdn flush <cdn-id> --files /path/to/file.one --files /path/to/file.two
doctl compute cdn flush <cdn-id> --files * `, Writer,
aliasOpt("fc"))
AddStringSliceFlag(cmdCDNFlushCache, doctl.ArgCDNFiles, "", []string{"*"}, "cdn files")

Expand Down
5 changes: 1 addition & 4 deletions commands/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package commands

import (
"io"
"sort"
"testing"

"github.com/digitalocean/doctl"
Expand Down Expand Up @@ -140,9 +139,7 @@ func assertCommandNames(t *testing.T, cmd *Command, expected ...string) {
}
}

sort.Strings(expected)
sort.Strings(names)
assert.Equal(t, expected, names)
assert.ElementsMatch(t, expected, names)
}

type testFn func(c *CmdConfig, tm *tcMocks)
Expand Down
21 changes: 19 additions & 2 deletions commands/displayers/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,39 @@ func (d *Domain) KV() []map[string]interface{} {

type DomainRecord struct {
DomainRecords do.DomainRecords
Short bool
}

func (dr *DomainRecord) JSON(out io.Writer) error {
return writeJSON(dr.DomainRecords, out)
}

func (dr *DomainRecord) Cols() []string {
return []string{
defaultCols := []string{
"ID", "Type", "Name", "Data", "Priority", "Port", "TTL", "Weight",
}

if dr.Short {
return defaultCols
}

return append(defaultCols, "Flags", "Tag")
}

func (dr *DomainRecord) ColMap() map[string]string {
return map[string]string{
defaultColMap := map[string]string{
"ID": "ID", "Type": "Type", "Name": "Name", "Data": "Data",
"Priority": "Priority", "Port": "Port", "TTL": "TTL", "Weight": "Weight",
}

if dr.Short {
return defaultColMap
}

defaultColMap["Flags"] = "Flags"
defaultColMap["Tag"] = "Tag"

return defaultColMap
}

func (dr *DomainRecord) KV() []map[string]interface{} {
Expand All @@ -81,6 +97,7 @@ func (dr *DomainRecord) KV() []map[string]interface{} {
"ID": d.ID, "Type": d.Type, "Name": d.Name,
"Data": d.Data, "Priority": d.Priority,
"Port": d.Port, "TTL": d.TTL, "Weight": d.Weight,
"Flags": d.Flags, "Tag": d.Tag,
}
out = append(out, o)
}
Expand Down
25 changes: 19 additions & 6 deletions commands/domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,7 @@ func RunRecordList(c *CmdConfig) error {
return err
}

items := &displayers.DomainRecord{DomainRecords: list}
return c.Display(items)

return displayDomainRecords(c, list...)
}

// RunRecordCreate creates a domain record.
Expand Down Expand Up @@ -284,8 +282,7 @@ func RunRecordCreate(c *CmdConfig) error {
return err
}

item := &displayers.DomainRecord{DomainRecords: do.DomainRecords{*r}}
return c.Display(item)
return displayDomainRecords(c, *r)

}

Expand Down Expand Up @@ -404,6 +401,22 @@ func RunRecordUpdate(c *CmdConfig) error {
return err
}

item := &displayers.DomainRecord{DomainRecords: do.DomainRecords{*r}}
return displayDomainRecords(c, *r)
}

func displayDomainRecords(c *CmdConfig, records ...do.DomainRecord) error {
// Check the format flag to determine if the displayer should use the short
// layout of the record display.The short version is used by default, but to format
// output that includes columns not in the short layout we need the full version.
var short = true
format, err := c.Doit.GetStringSlice(c.NS, doctl.ArgFormat)
if err != nil {
return err
}
if len(format) > 0 {
short = false
}

item := &displayers.DomainRecord{DomainRecords: do.DomainRecords(records), Short: short}
return c.Display(item)
}
5 changes: 1 addition & 4 deletions commands/functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package commands
import (
"bytes"
"os"
"sort"
"strings"
"testing"
"time"
Expand All @@ -37,9 +36,7 @@ func TestFunctionsCommand(t *testing.T) {
names = append(names, c.Name())
}

sort.Strings(expected)
sort.Strings(names)
assert.Equal(t, expected, names)
assert.ElementsMatch(t, expected, names)
}

func TestFunctionsGet(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions commands/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1778,11 +1778,11 @@ func parseNodePoolString(nodePool, defaultName, defaultSize string, defaultCount
case "size":
out.Size = value
case "count":
count, err := strconv.ParseInt(value, 10, 64)
count, err := strconv.Atoi(value)
if err != nil {
return nil, errors.New("Node pool count must be a valid integer.")
}
out.Count = int(count)
out.Count = count
case "tag":
out.Tags = append(out.Tags, value)
case "label":
Expand All @@ -1806,17 +1806,17 @@ func parseNodePoolString(nodePool, defaultName, defaultSize string, defaultCount
}
out.AutoScale = autoScale
case "min-nodes":
minNodes, err := strconv.ParseInt(value, 10, 64)
minNodes, err := strconv.Atoi(value)
if err != nil {
return nil, errors.New("Node pool min-nodes must be a valid integer.")
}
out.MinNodes = int(minNodes)
out.MinNodes = minNodes
case "max-nodes":
maxNodes, err := strconv.ParseInt(value, 10, 64)
maxNodes, err := strconv.Atoi(value)
if err != nil {
return nil, errors.New("Node pool max-nodes must be a valid integer.")
}
out.MaxNodes = int(maxNodes)
out.MaxNodes = maxNodes
default:
return nil, fmt.Errorf("Unsupported node pool argument %q", key)
}
Expand Down
Loading

0 comments on commit 6173bbe

Please sign in to comment.