Skip to content

Commit

Permalink
chore: Adopt go 1.23 (#4214)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellismg authored Aug 26, 2024
1 parent 19b0459 commit 1c0cb36
Show file tree
Hide file tree
Showing 51 changed files with 156 additions and 150 deletions.
6 changes: 4 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"ghcr.io/devcontainers/features/go:1": {
"version": "1.21"
"version": "1.23"
},
"ghcr.io/guiyomh/features/golangci-lint:0":{
"version": "1.60.1"
},
"ghcr.io/guiyomh/features/golangci-lint:0":{},
"ghcr.io/devcontainers/features/docker-in-docker:2.11.0": {
"version": "latest",
"moby": true
Expand Down
6 changes: 4 additions & 2 deletions .devcontainer/light/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"ghcr.io/devcontainers/features/go:1": {
"version": "1.21"
"version": "1.23"
},
"ghcr.io/guiyomh/features/golangci-lint:0":{
"version": "1.60.1"
},
"ghcr.io/guiyomh/features/golangci-lint:0":{},
"ghcr.io/devcontainers/features/docker-in-docker:2.11.0": {
"version": "latest",
"moby": true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/cli-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: "^1.21.0"
go-version: "^1.23.0"
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54.1
version: v1.60.1
args: -v --timeout 10m0s
working-directory: cli/azd

Expand Down
4 changes: 2 additions & 2 deletions cli/azd/cmd/auth_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func TestAuthTokenSysEnvError(t *testing.T) {
return nil, fmt.Errorf("not an azd env directory")
},
&mockSubscriptionTenantResolver{
Err: fmt.Errorf(expectedError),
Err: errors.New(expectedError),
},
cloud.AzurePublic(),
)
Expand Down Expand Up @@ -184,7 +184,7 @@ func TestAuthTokenAzdEnvError(t *testing.T) {
}), nil
},
&mockSubscriptionTenantResolver{
Err: fmt.Errorf(expectedError),
Err: errors.New(expectedError),
},
cloud.AzurePublic(),
)
Expand Down
10 changes: 5 additions & 5 deletions cli/azd/cmd/cmd_help.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func getCmdHelpDefaultDescription(cmd *cobra.Command) string {
// getCmdHelpDefaultUsage provides the default implementation for displaying the help usage section.
func getCmdHelpDefaultUsage(cmd *cobra.Command) string {
return fmt.Sprintf("%s\n %s\n\n",
output.WithBold(output.WithUnderline("Usage")),
output.WithBold("%s", output.WithUnderline("Usage")),
"{{if .Runnable}}{{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}{{.CommandPath}} [command]{{end}}",
)
}
Expand All @@ -97,13 +97,13 @@ func getCmdHelpDefaultFlags(cmd *cobra.Command) (result string) {
if cmd.HasAvailableLocalFlags() {
flags := getFlagsDetails(cmd.LocalFlags())
result = fmt.Sprintf("%s\n%s\n",
output.WithBold(output.WithUnderline("Flags")),
output.WithBold("%s", output.WithUnderline("Flags")),
flags)
}
if cmd.HasAvailableInheritedFlags() {
globalFlags := getFlagsDetails(cmd.InheritedFlags())
result += fmt.Sprintf("%s\n%s\n",
output.WithBold(output.WithUnderline("Global Flags")),
output.WithBold("%s", output.WithUnderline("Global Flags")),
globalFlags)
}
return result
Expand All @@ -128,7 +128,7 @@ func getCmdHelpCommands(title string, commands string) string {
if commands == "" {
return commands
}
return fmt.Sprintf("%s\n%s\n", output.WithBold(output.WithUnderline(title)), commands)
return fmt.Sprintf("%s\n%s\n", output.WithBold("%s", output.WithUnderline("%s", title)), commands)
}

// getCmdHelpGroupedCommands generates {{ commands - description }} where sub-commands are grouped.
Expand Down Expand Up @@ -280,7 +280,7 @@ func generateCmdHelpSamplesBlock(samples map[string]string) string {
// sorting lines to keep a deterministic output, as map[string]string is not ordered
slices.Sort(lines)
return fmt.Sprintf("%s\n%s\n",
output.WithBold(output.WithUnderline("Examples")),
output.WithBold("%s", output.WithUnderline("Examples")),
strings.Join(lines, "\n\n"),
)
}
6 changes: 2 additions & 4 deletions cli/azd/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"maps"
"path/filepath"
"runtime"
"slices"
Expand All @@ -18,7 +19,6 @@ import (
"github.com/azure/azure-dev/cli/azd/pkg/output"
"github.com/azure/azure-dev/cli/azd/pkg/output/ux"
"github.com/spf13/cobra"
"golang.org/x/exp/maps"
)

var userConfigPath string
Expand Down Expand Up @@ -457,9 +457,7 @@ func (a *configListAlphaAction) Run(ctx context.Context) (*actions.ActionResult,
return nil, err
}

featureKeys := maps.Keys(features)
slices.Sort(featureKeys)

featureKeys := slices.Sorted(maps.Keys(features))
var alphaOutput []string
for _, alphaFeatureKey := range featureKeys {
alphaFeature := features[alphaFeatureKey]
Expand Down
2 changes: 1 addition & 1 deletion cli/azd/cmd/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"net/url"
"os"
"slices"
"strings"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
Expand Down Expand Up @@ -67,7 +68,6 @@ import (
"github.com/azure/azure-dev/cli/azd/pkg/workflow"
"github.com/mattn/go-colorable"
"github.com/spf13/cobra"
"golang.org/x/exp/slices"
)

// Registers a transient action initializer for the specified action name
Expand Down
2 changes: 1 addition & 1 deletion cli/azd/cmd/infra_synth.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (a *infraSynthAction) Run(ctx context.Context) (*actions.ActionResult, erro
if !a.alphaManager.IsEnabled(infraSynthFeature) {
return nil, fmt.Errorf(
"infrastructure synthesis is currently under alpha support and must be explicitly enabled."+
" Run `%s` to enable this feature.", alpha.GetEnableCommand(infraSynthFeature),
" Run `%s` to enable this feature", alpha.GetEnableCommand(infraSynthFeature),
)
}

Expand Down
2 changes: 1 addition & 1 deletion cli/azd/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (i *initAction) Run(ctx context.Context) (*actions.ActionResult, error) {
if i.flags.templateBranch != "" && i.flags.templatePath == "" {
return nil,
errors.New(
"Using branch argument (-b or --branch) requires a template argument (--template or -t) to be specified.")
"using branch argument (-b or --branch) requires a template argument (--template or -t) to be specified")
}

// ensure that git is available
Expand Down
4 changes: 2 additions & 2 deletions cli/azd/cmd/middleware/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (m *HooksMiddleware) registerCommandHooks(
projectConfig *project.ProjectConfig,
next NextFn,
) (*actions.ActionResult, error) {
if projectConfig.Hooks == nil || len(projectConfig.Hooks) == 0 {
if len(projectConfig.Hooks) == 0 {
log.Println(
"azd project is not available or does not contain any command hooks, skipping command hook registrations.",
)
Expand Down Expand Up @@ -139,7 +139,7 @@ func (m *HooksMiddleware) registerServiceHooks(
for _, service := range stableServices {
serviceName := service.Name
// If the service hasn't configured any hooks we can continue on.
if service.Hooks == nil || len(service.Hooks) == 0 {
if len(service.Hooks) == 0 {
log.Printf("service '%s' does not require any command hooks.\n", serviceName)
continue
}
Expand Down
4 changes: 2 additions & 2 deletions cli/azd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func NewRootCmd(

func getCmdRootHelpFooter(cmd *cobra.Command) string {
return fmt.Sprintf("%s\n%s\n%s\n\n%s\n\n%s",
output.WithBold(output.WithUnderline("Deploying a sample application")),
output.WithBold("%s", output.WithUnderline("Deploying a sample application")),
"Initialize from a sample application by running the "+
output.WithHighLightFormat("azd init --template ")+
output.WithWarningFormat("[%s]", "template name")+" command in an empty directory.",
Expand Down Expand Up @@ -425,7 +425,7 @@ func getCmdRootHelpCommands(cmd *cobra.Command) (result string) {
var paragraph []string
for _, title := range groups {
paragraph = append(paragraph, fmt.Sprintf(" %s\n %s\n",
output.WithBold(string(title)),
output.WithBold("%s", string(title)),
strings.Join(commandGroups[string(title)], "\n ")))
}
return strings.Join(paragraph, "\n")
Expand Down
17 changes: 8 additions & 9 deletions cli/azd/internal/appdetect/javascript.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import (
"context"
"encoding/json"
"io/fs"
"maps"
"os"
"path/filepath"
"slices"
"strings"

"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
)

type PackagesJson struct {
Expand Down Expand Up @@ -90,14 +89,14 @@ func (nd *javaScriptDetector) DetectProject(ctx context.Context, path string, en
}

if len(databaseDepMap) > 0 {
project.DatabaseDeps = maps.Keys(databaseDepMap)
slices.SortFunc(project.DatabaseDeps, func(a, b DatabaseDep) bool {
return string(a) < string(b)
})
project.DatabaseDeps = slices.SortedFunc(maps.Keys(databaseDepMap),
func(a, b DatabaseDep) int {
return strings.Compare(string(a), string(b))
})
}

slices.SortFunc(project.Dependencies, func(a, b Dependency) bool {
return string(a) < string(b)
slices.SortFunc(project.Dependencies, func(a, b Dependency) int {
return strings.Compare(string(a), string(b))
})

tsFiles := 0
Expand Down
17 changes: 8 additions & 9 deletions cli/azd/internal/appdetect/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import (
"bufio"
"context"
"io/fs"
"maps"
"os"
"path/filepath"
"slices"
"strings"

"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
)

type pythonDetector struct {
Expand Down Expand Up @@ -82,14 +81,14 @@ func (pd *pythonDetector) DetectProject(ctx context.Context, path string, entrie
}

if len(databaseDepMap) > 0 {
project.DatabaseDeps = maps.Keys(databaseDepMap)
slices.SortFunc(project.DatabaseDeps, func(a, b DatabaseDep) bool {
return string(a) < string(b)
})
project.DatabaseDeps = slices.SortedFunc(maps.Keys(databaseDepMap),
func(a, b DatabaseDep) int {
return strings.Compare(string(a), string(b))
})
}

slices.SortFunc(project.Dependencies, func(a, b Dependency) bool {
return string(a) < string(b)
slices.SortFunc(project.Dependencies, func(a, b Dependency) int {
return strings.Compare(string(a), string(b))
})

return project, nil
Expand Down
2 changes: 1 addition & 1 deletion cli/azd/internal/cmd/cmd_help.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func generateCmdHelpSamplesBlock(samples map[string]string) string {
// sorting lines to keep a deterministic output, as map[string]string is not ordered
slices.Sort(lines)
return fmt.Sprintf("%s\n%s\n",
output.WithBold(output.WithUnderline("Examples")),
output.WithBold("%s", output.WithUnderline("Examples")),
strings.Join(lines, "\n\n"),
)
}
18 changes: 9 additions & 9 deletions cli/azd/internal/cmd/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,30 +268,30 @@ func (p *ProvisionAction) Run(ctx context.Context) (*actions.ActionResult, error
requestAccessLink := "https://go.microsoft.com/fwlink/?linkid=2259205&clcid=0x409"
return nil, &internal.ErrorWithSuggestion{
Err: err,
Suggestion: fmt.Sprintf("\nSuggested Action: The selected subscription does not have access to" +
" Azure OpenAI Services. Please visit " + output.WithLinkFormat(requestAccessLink) +
" to request access."),
Suggestion: "\nSuggested Action: The selected subscription does not have access to" +
" Azure OpenAI Services. Please visit " + output.WithLinkFormat("%s", requestAccessLink) +
" to request access.",
}
}

if strings.Contains(errorMsg, AINotValid) &&
strings.Contains(errorMsg, openAIsubscriptionNoQuotaId) {
return nil, &internal.ErrorWithSuggestion{
Suggestion: fmt.Sprintf("\nSuggested Action: The selected " +
Suggestion: "\nSuggested Action: The selected " +
"subscription has not been enabled for use of Azure AI service and does not have quota for " +
"any pricing tiers. Please visit " + output.WithLinkFormat(p.portalUrlBase) +
" and select 'Create' on specific services to request access."),
"any pricing tiers. Please visit " + output.WithLinkFormat("%s", p.portalUrlBase) +
" and select 'Create' on specific services to request access.",
Err: err,
}
}

//if user haven't agree to Responsible AI terms
if strings.Contains(errorMsg, responsibleAITerms) {
return nil, &internal.ErrorWithSuggestion{
Suggestion: fmt.Sprintf("\nSuggested Action: Please visit azure portal in " +
output.WithLinkFormat(p.portalUrlBase) + ". Create the resource in azure portal " +
Suggestion: "\nSuggested Action: Please visit azure portal in " +
output.WithLinkFormat("%s", p.portalUrlBase) + ". Create the resource in azure portal " +
"to go through Responsible AI terms, and then delete it. " +
"After that, run 'azd provision' again"),
"After that, run 'azd provision' again",
Err: err,
}
}
Expand Down
29 changes: 15 additions & 14 deletions cli/azd/internal/repository/detect_confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import (
"errors"
"fmt"
"log"
"maps"
"os"
"path/filepath"
"slices"
"strings"
"time"

"github.com/AlecAivazis/survey/v2/terminal"
Expand All @@ -18,8 +21,6 @@ import (
"github.com/azure/azure-dev/cli/azd/pkg/output/ux"
"github.com/fatih/color"
"go.opentelemetry.io/otel/attribute"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
)

func projectDisplayName(p appdetect.Project) string {
Expand Down Expand Up @@ -244,7 +245,7 @@ func (d *detectConfirm) remove(ctx context.Context) error {
modifyOptions, fmt.Sprintf("%s in %s", projectDisplayName(svc), relSafe(d.root, svc.Path)))
}

displayDbs := maps.Keys(d.Databases)
displayDbs := slices.Collect(maps.Keys(d.Databases))
for _, db := range displayDbs {
modifyOptions = append(modifyOptions, db.Display())
}
Expand Down Expand Up @@ -307,26 +308,26 @@ func (d *detectConfirm) remove(ctx context.Context) error {
}

func (d *detectConfirm) add(ctx context.Context) error {
languages := maps.Keys(languageMap)
slices.SortFunc(languages, func(a, b appdetect.Language) bool {
return a.Display() < b.Display()
})
languages := slices.SortedFunc(maps.Keys(languageMap),
func(a, b appdetect.Language) int {
return strings.Compare(a.Display(), b.Display())
})

frameworks := maps.Keys(appdetect.WebUIFrameworks)
slices.SortFunc(frameworks, func(a, b appdetect.Dependency) bool {
return a.Display() < b.Display()
})
frameworks := slices.SortedFunc(maps.Keys(appdetect.WebUIFrameworks),
func(a, b appdetect.Dependency) int {
return strings.Compare(a.Display(), b.Display())
})

// only include databases not already added
allDbs := maps.Keys(dbMap)
allDbs := slices.Collect(maps.Keys(dbMap))
databases := make([]appdetect.DatabaseDep, 0, len(allDbs))
for _, db := range allDbs {
if _, ok := d.Databases[db]; !ok {
databases = append(databases, db)
}
}
slices.SortFunc(databases, func(a, b appdetect.DatabaseDep) bool {
return a.Display() < b.Display()
slices.SortFunc(databases, func(a, b appdetect.DatabaseDep) int {
return strings.Compare(a.Display(), b.Display())
})

selections := make([]string, 0, len(languages)+len(frameworks)+len(databases))
Expand Down
Loading

0 comments on commit 1c0cb36

Please sign in to comment.