Skip to content

Commit 2cb90f5

Browse files
committed
Adopt go 1.21
This change moves us to use Go 1.21 for building `azd`. As part of go 1.21, the `maps`, `slices` and `slog` packages, previously in `golang.org/x/exp` have been moved into the standard libary. As part of this change, I've moved to use these versions of the packages instead of using the experimental versions. However, there were a few places where we were using `maps.Keys`, which was not added to the standard library. https://go-review.googlesource.com/c/go/+/513715 explains the rationale here, they may want `Keys` to return an iterator, and were not comfortable locking the name at this time. This functionality will be added to the `maps` package in a future release, it seems, likely under a name like `KeysSlice`. For now, I just kept the existing use of the the experimental package. We can update the import path and move to the stdlib version when it lands later. This change also updates `go.mod` to declare that we need at least go 1.21 to build `azd`. Developers which haven't upgraded will see build errors due to references of `maps`, `slices` and `log/slog` which do not exist in earlier versions of the standard libary. I've also enabled the loopvar experiment for our CI builds and tests. https://github.com/golang/go/wiki/LoopvarExperiment gives more information on what this does, but the long and short of it is that this behavior is likely to become the default in a future version of go, and the semantics of it more closely match what developers expect, so I would like us to just lock in the changes now (we are presently clean on this, so there are no changes, I just don't want us to introduce any new bad uses).
1 parent 6d0dc5c commit 2cb90f5

File tree

27 files changed

+44
-30
lines changed

27 files changed

+44
-30
lines changed

.github/workflows/cli-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
steps:
2222
- uses: actions/setup-go@v3
2323
with:
24-
go-version: "^1.20.0"
24+
go-version: "^1.21.0"
2525
- uses: actions/checkout@v3
2626
- name: golangci-lint
2727
uses: golangci/golangci-lint-action@v3

cli/azd/ci-build.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ param(
55
[switch] $BuildRecordMode
66
)
77

8+
# Enable the loopvar experiment, which makes the loop variaible for go loops like `range` behave as most folks would expect.
9+
# the go team is exploring making this default in the future, and we'd like to opt into the behavior now.
10+
$env:GOEXPERIMENT="loopvar"
11+
812
# Remove any previously built binaries
913
go clean
1014

cli/azd/ci-test.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ param(
55
[string] $IntegrationTestCoverageDir = 'cover-int'
66
)
77

8+
# Enable the loopvar experiment, which makes the loop variaible for go loops like `range` behave as most folks would expect.
9+
# the go team is exploring making this default in the future, and we'd like to opt into the behavior now.
10+
$env:GOEXPERIMENT="loopvar"
11+
812
$ErrorActionPreference = 'Stop'
913

1014
$gopath = go env GOPATH

cli/azd/cmd/cmd_help.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ package cmd
55

66
import (
77
"fmt"
8+
"slices"
89
"strings"
910

1011
"github.com/azure/azure-dev/cli/azd/pkg/output"
1112
"github.com/spf13/cobra"
1213
"github.com/spf13/pflag"
13-
"golang.org/x/exp/slices"
1414
)
1515

1616
const (

cli/azd/cmd/cobra_builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66
"log"
7+
"slices"
78
"strconv"
89
"strings"
910

@@ -19,7 +20,6 @@ import (
1920
"github.com/azure/azure-dev/cli/azd/pkg/tools"
2021
"github.com/azure/azure-dev/cli/azd/pkg/tools/azcli"
2122
"github.com/spf13/cobra"
22-
"golang.org/x/exp/slices"
2323
)
2424

2525
const cDocsFlagName = "docs"

cli/azd/internal/repository/initializer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"path/filepath"
99
"runtime"
10+
"slices"
1011
"strings"
1112
"testing"
1213

@@ -21,7 +22,6 @@ import (
2122
"github.com/azure/azure-dev/cli/azd/test/mocks/mockinput"
2223
"github.com/stretchr/testify/assert"
2324
"github.com/stretchr/testify/require"
24-
"golang.org/x/exp/slices"
2525
)
2626

2727
func Test_Initializer_Initialize(t *testing.T) {

cli/azd/internal/telemetry/storage_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8+
"slices"
89
"testing"
910
"time"
1011

1112
"github.com/azure/azure-dev/cli/azd/pkg/osutil"
1213
"github.com/benbjohnson/clock"
1314
"github.com/stretchr/testify/assert"
1415
"github.com/stretchr/testify/require"
15-
"golang.org/x/exp/slices"
1616
)
1717

1818
// The tests in this file intentionally interacts with the filesystem (important implementation detail).

cli/azd/internal/telemetry/uploader_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import (
44
"context"
55
"fmt"
66
"math/rand"
7+
"slices"
78
"strconv"
89
"testing"
910
"time"
1011

1112
appinsightsexporter "github.com/azure/azure-dev/cli/azd/internal/telemetry/appinsights-exporter"
1213
"github.com/benbjohnson/clock"
1314
"github.com/stretchr/testify/assert"
14-
"golang.org/x/exp/slices"
1515
)
1616

1717
type InMemoryItem struct {

cli/azd/internal/tracing/baggage/baggage.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
package baggage
55

66
import (
7-
"go.opentelemetry.io/otel/attribute"
87
"golang.org/x/exp/maps"
8+
9+
"go.opentelemetry.io/otel/attribute"
910
)
1011

1112
// An immutable object safe for concurrent use.

cli/azd/pkg/account/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import (
66
"fmt"
77
"log"
88
"os"
9+
"slices"
910

1011
"github.com/azure/azure-dev/cli/azd/pkg/config"
11-
"golang.org/x/exp/slices"
1212
)
1313

1414
// JSON document path locations for default subscription & location

cli/azd/pkg/account/manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"net/http"
7+
"slices"
78
"testing"
89

910
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions"
@@ -15,7 +16,6 @@ import (
1516
"github.com/azure/azure-dev/cli/azd/test/mocks/mockhttp"
1617
"github.com/azure/azure-dev/cli/azd/test/mocks/mockinput"
1718
"github.com/stretchr/testify/require"
18-
"golang.org/x/exp/slices"
1919
)
2020

2121
func Test_GetAccountDefaults(t *testing.T) {

cli/azd/pkg/auth/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
"io"
99
"log"
1010
"net/http"
11+
"slices"
1112

1213
msal "github.com/AzureAD/microsoft-authentication-library-for-go/apps/errors"
13-
"golang.org/x/exp/slices"
1414
)
1515

1616
const cLoginCmd = "azd auth login"

cli/azd/pkg/azureutil/location.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import (
77
"context"
88
"fmt"
99
"os"
10+
"slices"
1011
"strings"
1112

1213
"github.com/azure/azure-dev/cli/azd/pkg/account"
1314
"github.com/azure/azure-dev/cli/azd/pkg/environment"
1415
"github.com/azure/azure-dev/cli/azd/pkg/input"
15-
"golang.org/x/exp/slices"
1616
)
1717

1818
// PromptLocation asks the user to select a location from a list of supported azure locations for a given subscription.
@@ -48,9 +48,9 @@ func PromptLocationWithFilter(
4848
}
4949
}
5050

51-
slices.SortFunc(locations, func(a, b account.Location) bool {
51+
slices.SortFunc(locations, func(a, b account.Location) int {
5252
return strings.Compare(
53-
strings.ToLower(a.RegionalDisplayName), strings.ToLower(b.RegionalDisplayName)) < 0
53+
strings.ToLower(a.RegionalDisplayName), strings.ToLower(b.RegionalDisplayName))
5454
})
5555

5656
// Allow the environment variable `AZURE_LOCATION` to control the default value for the location

cli/azd/pkg/environment/environment.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ import (
1111
"regexp"
1212
"strings"
1313

14+
"maps"
15+
1416
"github.com/azure/azure-dev/cli/azd/internal/tracing"
1517
"github.com/azure/azure-dev/cli/azd/internal/tracing/fields"
1618
"github.com/azure/azure-dev/cli/azd/pkg/config"
1719
"github.com/azure/azure-dev/cli/azd/pkg/environment/azdcontext"
1820
"github.com/azure/azure-dev/cli/azd/pkg/osutil"
1921
"github.com/joho/godotenv"
20-
"golang.org/x/exp/maps"
2122
)
2223

2324
// EnvNameEnvVarName is the name of the key used to store the envname property in the environment.

cli/azd/pkg/infra/provisioning/bicep/bicep_provider.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"math"
1313
"os"
1414
"path/filepath"
15+
"slices"
1516
"strconv"
1617
"strings"
1718
"time"
@@ -38,7 +39,6 @@ import (
3839
"github.com/benbjohnson/clock"
3940
"github.com/drone/envsubst"
4041
"golang.org/x/exp/maps"
41-
"golang.org/x/exp/slices"
4242
)
4343

4444
const DefaultModule = "main"
@@ -715,8 +715,8 @@ func (p *BicepProvider) findCompletedDeployments(
715715
return nil, err
716716
}
717717

718-
slices.SortFunc(deployments, func(x, y *armresources.DeploymentExtended) bool {
719-
return x.Properties.Timestamp.After(*y.Properties.Timestamp)
718+
slices.SortFunc(deployments, func(x, y *armresources.DeploymentExtended) int {
719+
return x.Properties.Timestamp.Compare(*y.Properties.Timestamp)
720720
})
721721

722722
// If hint is not provided, use the environment name as the hint

cli/azd/pkg/infra/provisioning/bicep/prompt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"slices"
78
"strconv"
89

910
"github.com/azure/azure-dev/cli/azd/pkg/account"
1011
"github.com/azure/azure-dev/cli/azd/pkg/azure"
1112
"github.com/azure/azure-dev/cli/azd/pkg/input"
1213
"github.com/azure/azure-dev/cli/azd/pkg/output"
13-
"golang.org/x/exp/slices"
1414

1515
. "github.com/azure/azure-dev/cli/azd/pkg/infra/provisioning"
1616
)

cli/azd/pkg/pipeline/github_provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"net/url"
1414
"path/filepath"
1515
"regexp"
16+
"slices"
1617
"strings"
1718

1819
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
@@ -31,7 +32,6 @@ import (
3132
"github.com/azure/azure-dev/cli/azd/pkg/tools/azcli"
3233
"github.com/azure/azure-dev/cli/azd/pkg/tools/git"
3334
"github.com/azure/azure-dev/cli/azd/pkg/tools/github"
34-
"golang.org/x/exp/slices"
3535
)
3636

3737
// GitHubScmProvider implements ScmProvider using GitHub as the provider

cli/azd/pkg/pipeline/pipeline_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"log"
1111
"path/filepath"
12+
"slices"
1213
"strings"
1314
"time"
1415

@@ -25,7 +26,6 @@ import (
2526
"github.com/azure/azure-dev/cli/azd/pkg/tools/azcli"
2627
"github.com/azure/azure-dev/cli/azd/pkg/tools/git"
2728
"github.com/sethvargo/go-retry"
28-
"golang.org/x/exp/slices"
2929
)
3030

3131
type PipelineAuthType string

cli/azd/pkg/project/project.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"log"
88
"os"
99
"path/filepath"
10+
"slices"
1011
"strings"
1112

1213
"github.com/azure/azure-dev/cli/azd/internal"
@@ -16,7 +17,6 @@ import (
1617
"github.com/azure/azure-dev/cli/azd/pkg/infra/provisioning"
1718
"github.com/azure/azure-dev/cli/azd/pkg/osutil"
1819
"github.com/blang/semver/v4"
19-
"golang.org/x/exp/slices"
2020
"gopkg.in/yaml.v3"
2121
)
2222

cli/azd/pkg/prompt/prompter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"log"
77
"os"
8+
"slices"
89
"strings"
910

1011
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
@@ -15,7 +16,6 @@ import (
1516
"github.com/azure/azure-dev/cli/azd/pkg/environment"
1617
"github.com/azure/azure-dev/cli/azd/pkg/input"
1718
"github.com/azure/azure-dev/cli/azd/pkg/tools/azcli"
18-
"golang.org/x/exp/slices"
1919
)
2020

2121
type LocationFilterPredicate func(loc account.Location) bool
@@ -112,8 +112,8 @@ func (p *DefaultPrompter) PromptResourceGroup(ctx context.Context) (string, erro
112112
return "", fmt.Errorf("listing resource groups: %w", err)
113113
}
114114

115-
slices.SortFunc(groups, func(a, b azcli.AzCliResource) bool {
116-
return strings.Compare(a.Name, b.Name) < 0
115+
slices.SortFunc(groups, func(a, b azcli.AzCliResource) int {
116+
return strings.Compare(a.Name, b.Name)
117117
})
118118

119119
choices := make([]string, len(groups)+1)

cli/azd/pkg/tools/azcli/container_registry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"log"
88
"net/http"
99
"net/url"
10+
"slices"
1011
"strings"
1112

1213
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
@@ -17,7 +18,6 @@ import (
1718
"github.com/azure/azure-dev/cli/azd/pkg/azure"
1819
"github.com/azure/azure-dev/cli/azd/pkg/httputil"
1920
"github.com/azure/azure-dev/cli/azd/pkg/tools/docker"
20-
"golang.org/x/exp/slices"
2121
)
2222

2323
type dockerCredentials struct {

cli/azd/test/functional/cli_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"path"
2121
"path/filepath"
2222
"runtime"
23+
"slices"
2324
"strings"
2425
"testing"
2526
"time"
@@ -43,7 +44,6 @@ import (
4344
"github.com/stretchr/testify/assert"
4445
"github.com/stretchr/testify/require"
4546
"go.opentelemetry.io/otel/attribute"
46-
"golang.org/x/exp/slices"
4747
)
4848

4949
// The current running configuration for the test suite.

cli/azd/test/recording/proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import (
1111
"fmt"
1212
"io"
1313
"io/fs"
14+
"log/slog"
1415
"net"
1516
"net/http"
1617
"net/url"
1718
"strings"
1819

19-
"golang.org/x/exp/slog"
2020
"gopkg.in/dnaeon/go-vcr.v3/recorder"
2121
)
2222

cli/azd/test/recording/recording.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"errors"
1515
"fmt"
1616
"io"
17+
"log/slog"
1718
"net/http"
1819
"net/http/httptest"
1920
"net/url"
@@ -24,7 +25,6 @@ import (
2425
"testing"
2526
"time"
2627

27-
"golang.org/x/exp/slog"
2828
"gopkg.in/dnaeon/go-vcr.v3/cassette"
2929
"gopkg.in/dnaeon/go-vcr.v3/recorder"
3030
"gopkg.in/yaml.v3"

eng/pipelines/templates/steps/setup-go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
GoVersion: 1.20.3
2+
GoVersion: 1.21.0
33
Condition: succeeded()
44

55
steps:

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/azure/azure-dev
22

3-
go 1.20
3+
go 1.21
44

55
require (
66
github.com/AlecAivazis/survey/v2 v2.3.2

0 commit comments

Comments
 (0)