chore: update to go 1.20 (#5968)

Co-authored-by: Colin Adler <colin1adler@gmail.com>
This commit is contained in:
Kyle Carberry 2023-02-02 12:36:27 -06:00 committed by GitHub
parent 4df1031f8b
commit 026b1cd2a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 91 additions and 93 deletions

View File

@ -57,7 +57,7 @@ RUN mkdir -p /etc/apt/keyrings \
&& echo '{"cgroup-parent":"/actions_job","storage-driver":"vfs"}' >> /etc/docker/daemon.json
# install golang and language tooling
ENV GO_VERSION=1.19
ENV GO_VERSION=1.20
ENV GOPATH=$HOME/go-packages
ENV GOROOT=$HOME/go
ENV PATH=$GOROOT/bin:$GOPATH/bin:$PATH

View File

@ -37,7 +37,7 @@ jobs:
# Install Go!
- uses: actions/setup-go@v3
with:
go-version: "~1.19"
go-version: "~1.20"
# Check for any typos!
- name: Check for typos
@ -55,7 +55,7 @@ jobs:
- name: Lint Go
uses: golangci/golangci-lint-action@v3.3.1
with:
version: v1.48.0
version: v1.51.0
- name: Lint shell scripts
uses: ludeeus/action-shellcheck@2.0.0
@ -151,7 +151,7 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version: "~1.19"
go-version: "~1.20"
- name: Echo Go Cache Paths
id: go-cache-paths
@ -250,7 +250,7 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version: "~1.19"
go-version: "~1.20"
# Sadly the new "set output" syntax (of writing env vars to
# $GITHUB_OUTPUT) does not work on both powershell and bash so we use the
@ -333,7 +333,7 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version: "~1.19"
go-version: "~1.20"
- name: Echo Go Cache Paths
id: go-cache-paths
@ -416,7 +416,7 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version: "~1.19"
go-version: "~1.20"
- name: Echo Go Cache Paths
id: go-cache-paths
@ -545,7 +545,7 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version: "~1.19"
go-version: "~1.20"
- uses: hashicorp/setup-terraform@v2
with:

View File

@ -91,7 +91,7 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version: "~1.19"
go-version: "~1.20"
- name: Cache Node
id: cache-node

View File

@ -38,7 +38,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: "~1.19"
go-version: "~1.20"
- name: Go Cache Paths
id: go-cache-paths
@ -68,7 +68,7 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version: "~1.19"
go-version: "~1.20"
- name: Go Cache Paths
id: go-cache-paths

View File

@ -69,12 +69,12 @@ func gitAskpass() *cobra.Command {
if token.Password != "" {
if user == "" {
fmt.Fprintln(cmd.OutOrStdout(), token.Username)
_, _ = fmt.Fprintln(cmd.OutOrStdout(), token.Username)
} else {
fmt.Fprintln(cmd.OutOrStdout(), token.Password)
_, _ = fmt.Fprintln(cmd.OutOrStdout(), token.Password)
}
} else {
fmt.Fprintln(cmd.OutOrStdout(), token.Username)
_, _ = fmt.Fprintln(cmd.OutOrStdout(), token.Username)
}
return nil

View File

@ -30,8 +30,6 @@ var updateGoldenFiles = flag.Bool("update", false, "update .golden files")
//nolint:tparallel,paralleltest // These test sets env vars.
func TestCommandHelp(t *testing.T) {
t.Parallel()
commonEnv := map[string]string{
"CODER_CONFIG_DIR": "/tmp/coder-cli-test-config",
}

View File

@ -24,7 +24,7 @@ import (
func randRemoteAddr() string {
var b [4]byte
// nolint:gosec
rand.Read(b[:])
_, _ = rand.Read(b[:])
// nolint:gosec
return fmt.Sprintf("%s:%v", net.IP(b[:]).String(), rand.Int31()%(1<<16))
}

View File

@ -360,6 +360,7 @@ func TestIsOrgRole(t *testing.T) {
// nolint:paralleltest
for _, c := range testCases {
c := c
t.Run(c.RoleName, func(t *testing.T) {
t.Parallel()
orgID, ok := rbac.IsOrgRole(c.RoleName)

View File

@ -46,9 +46,9 @@ func ConvertRegoAst(cfg ConvertConfig, partial *rego.PartialQueries) (sqltypes.B
}
if i != 0 {
builder.WriteString("\n")
_, _ = builder.WriteString("\n")
}
builder.WriteString(q.String())
_, _ = builder.WriteString(q.String())
queries = append(queries, converted)
}

View File

@ -44,7 +44,7 @@ func TestChecker_Notify(t *testing.T) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(b)
_, _ = w.Write(b)
}
}))
defer srv.Close()

View File

@ -8,7 +8,7 @@ FROM ubuntu AS go
RUN apt-get update && apt-get install --yes curl gcc
# Install Go manually, so that we can control the version
ARG GO_VERSION=1.19
ARG GO_VERSION=1.20
RUN mkdir --parents /usr/local/go
# Boring Go is needed to build FIPS-compliant binaries.
@ -210,7 +210,7 @@ RUN systemctl enable \
ARG CLOUD_SQL_PROXY_VERSION=1.26.0 \
DIVE_VERSION=0.10.0 \
DOCKER_GCR_VERSION=2.1.0 \
GOLANGCI_LINT_VERSION=1.48.0 \
GOLANGCI_LINT_VERSION=1.51.0 \
GRYPE_VERSION=0.24.0 \
HELM_VERSION=3.8.0 \
KUBE_LINTER_VERSION=0.2.5 \

View File

@ -16,5 +16,4 @@ Pin-Priority: 500
# containerd runtime
Package: containerd.io
Pin: origin download.docker.com
Pin: version 1.5.11-1
Pin-Priority: 500

View File

@ -317,7 +317,7 @@ func Test_diff(t *testing.T) {
},
exp: audit.Map{
"id": audit.OldNew{Old: "", New: uuid.UUID{1}.String()},
"template_id": audit.OldNew{Old: "", New: uuid.UUID{2}.String()},
"template_id": audit.OldNew{Old: "null", New: uuid.UUID{2}.String()},
"created_by": audit.OldNew{Old: "", New: uuid.UUID{4}.String()},
"name": audit.OldNew{Old: "", New: "rust"},
},
@ -386,7 +386,7 @@ func Test_diff(t *testing.T) {
"owner_id": audit.OldNew{Old: "", New: uuid.UUID{2}.String()},
"template_id": audit.OldNew{Old: "", New: uuid.UUID{3}.String()},
"name": audit.OldNew{Old: "", New: "rust workspace"},
"autostart_schedule": audit.OldNew{Old: "", New: "0 12 * * 1-5"},
"autostart_schedule": audit.OldNew{Old: "null", New: "0 12 * * 1-5"},
"ttl": audit.OldNew{Old: int64(0), New: int64(8 * time.Hour)}, // XXX: pq still does not support time.Duration
},
},
@ -417,8 +417,8 @@ func runDiffTests(t *testing.T, tests []diffTest) {
t.Helper()
for _, test := range tests {
test := test
typName := reflect.TypeOf(test.left).Name()
t.Run(typName+"/"+test.name, func(t *testing.T) {
t.Parallel()
require.Equal(t,

View File

@ -568,9 +568,9 @@ func (c *haCoordinator) handlePubsubMessage(ctx context.Context, message []byte)
func (c *haCoordinator) formatCallMeMaybe(recipient uuid.UUID, nodes []*agpl.Node) ([]byte, error) {
buf := bytes.Buffer{}
buf.WriteString(c.id.String() + "|")
buf.WriteString("callmemaybe|")
buf.WriteString(recipient.String() + "|")
_, _ = buf.WriteString(c.id.String() + "|")
_, _ = buf.WriteString("callmemaybe|")
_, _ = buf.WriteString(recipient.String() + "|")
err := json.NewEncoder(&buf).Encode(nodes)
if err != nil {
return nil, xerrors.Errorf("encode node: %w", err)
@ -583,9 +583,9 @@ func (c *haCoordinator) formatCallMeMaybe(recipient uuid.UUID, nodes []*agpl.Nod
func (c *haCoordinator) formatAgentHello(id uuid.UUID) ([]byte, error) {
buf := bytes.Buffer{}
buf.WriteString(c.id.String() + "|")
buf.WriteString("agenthello|")
buf.WriteString(id.String() + "|")
_, _ = buf.WriteString(c.id.String() + "|")
_, _ = buf.WriteString("agenthello|")
_, _ = buf.WriteString(id.String() + "|")
return buf.Bytes(), nil
}
@ -594,9 +594,9 @@ func (c *haCoordinator) formatAgentHello(id uuid.UUID) ([]byte, error) {
func (c *haCoordinator) formatClientHello(id uuid.UUID) ([]byte, error) {
buf := bytes.Buffer{}
buf.WriteString(c.id.String() + "|")
buf.WriteString("clienthello|")
buf.WriteString(id.String() + "|")
_, _ = buf.WriteString(c.id.String() + "|")
_, _ = buf.WriteString("clienthello|")
_, _ = buf.WriteString(id.String() + "|")
return buf.Bytes(), nil
}
@ -605,9 +605,9 @@ func (c *haCoordinator) formatClientHello(id uuid.UUID) ([]byte, error) {
func (c *haCoordinator) formatAgentUpdate(id uuid.UUID, node *agpl.Node) ([]byte, error) {
buf := bytes.Buffer{}
buf.WriteString(c.id.String() + "|")
buf.WriteString("agentupdate|")
buf.WriteString(id.String() + "|")
_, _ = buf.WriteString(c.id.String() + "|")
_, _ = buf.WriteString("agentupdate|")
_, _ = buf.WriteString(id.String() + "|")
err := json.NewEncoder(&buf).Encode(node)
if err != nil {
return nil, xerrors.Errorf("encode node: %w", err)
@ -622,8 +622,8 @@ func (c *haCoordinator) ServeHTTPDebug(w http.ResponseWriter, r *http.Request) {
c.mutex.RLock()
defer c.mutex.RUnlock()
fmt.Fprintln(w, "<h1>high-availability wireguard coordinator debug</h1>")
fmt.Fprintln(w, "<h4 style=\"margin-top:-25px\">warning: this only provides info from the node that served the request, if there are multiple replicas this data may be incomplete</h4>")
_, _ = fmt.Fprintln(w, "<h1>high-availability wireguard coordinator debug</h1>")
_, _ = fmt.Fprintln(w, "<h4 style=\"margin-top:-25px\">warning: this only provides info from the node that served the request, if there are multiple replicas this data may be incomplete</h4>")
agpl.CoordinatorHTTPDebug(c.agentSockets, c.agentToConnectionSockets, c.agentNameCache)(w, r)
}

View File

@ -24,7 +24,7 @@
getopt
git
go-migrate
go_1_19
go_1_20
golangci-lint
gopls
gotestsum

2
go.mod
View File

@ -1,6 +1,6 @@
module github.com/coder/coder
go 1.19
go 1.20
// Required until https://github.com/manifoldco/promptui/pull/169 is merged.
replace github.com/manifoldco/promptui => github.com/kylecarbs/promptui v0.8.1-0.20201231190244-d8f2159af2b2

View File

@ -19,7 +19,7 @@ import (
const unsafeEnvCanary = "CODER_DONT_PASS"
func init() {
os.Setenv(unsafeEnvCanary, "true")
_ = os.Setenv(unsafeEnvCanary, "true")
}
func envName(env string) string {

View File

@ -37,7 +37,7 @@ func main() {
}
// Just cat the output to a file to capture it
fmt.Println(output)
_, _ = fmt.Println(output)
}
func Generate(directory string) (string, error) {
@ -307,11 +307,11 @@ func (g *Generator) generateOne(m *Maps, obj types.Object) error {
var str strings.Builder
_, _ = str.WriteString(g.posLine(obj))
if ts.AboveTypeLine != "" {
str.WriteString(ts.AboveTypeLine)
str.WriteRune('\n')
_, _ = str.WriteString(ts.AboveTypeLine)
_, _ = str.WriteRune('\n')
}
// Use similar output syntax to enums.
str.WriteString(fmt.Sprintf("export type %s = %s\n", obj.Name(), ts.ValueType))
_, _ = str.WriteString(fmt.Sprintf("export type %s = %s\n", obj.Name(), ts.ValueType))
m.Structs[obj.Name()] = str.String()
case *types.Interface:
// Interfaces are used as generics. Non-generic interfaces are
@ -353,7 +353,7 @@ func (g *Generator) generateOne(m *Maps, obj types.Object) error {
case *types.Func:
// Noop
default:
fmt.Println(obj.Name())
_, _ = fmt.Println(obj.Name())
}
return nil
}
@ -387,7 +387,7 @@ func (g *Generator) buildUnion(obj types.Object, st *types.Union) (string, error
allTypes = slice.Unique(allTypes)
s.WriteString(fmt.Sprintf("export type %s = %s\n", obj.Name(), strings.Join(allTypes, " | ")))
_, _ = s.WriteString(fmt.Sprintf("export type %s = %s\n", obj.Name(), strings.Join(allTypes, " | ")))
return s.String(), nil
}

View File

@ -110,11 +110,11 @@ func updateAuditDoc(doc []byte, auditableResourcesMap AuditableResourcesMap) ([]
tableEndIndex := tableStartIndex + j
var buffer bytes.Buffer
buffer.Write(doc[:tableStartIndex])
buffer.WriteByte('\n')
_, _ = buffer.Write(doc[:tableStartIndex])
_ = buffer.WriteByte('\n')
buffer.WriteString("|<b>Resource<b>||\n")
buffer.WriteString("|--|-----------------|\n")
_, _ = buffer.WriteString("|<b>Resource<b>||\n")
_, _ = buffer.WriteString("|--|-----------------|\n")
for _, resourceName := range sortedResourceNames {
readableResourceName := resourceName
@ -131,21 +131,21 @@ func updateAuditDoc(doc []byte, auditableResourcesMap AuditableResourcesMap) ([]
}
auditActionsString := strings.Join(auditActions, ", ")
buffer.WriteString("|" + readableResourceName + "<br><i>" + auditActionsString + "</i>|<table><thead><tr><th>Field</th><th>Tracked</th></tr></thead><tbody>")
_, _ = buffer.WriteString("|" + readableResourceName + "<br><i>" + auditActionsString + "</i>|<table><thead><tr><th>Field</th><th>Tracked</th></tr></thead><tbody>")
// We must sort the field names to ensure sub-table ordering
sortedFieldNames := sortKeys(auditableResourcesMap[resourceName])
for _, fieldName := range sortedFieldNames {
isTracked := auditableResourcesMap[resourceName][fieldName]
buffer.WriteString("<tr><td>" + fieldName + "</td><td>" + strconv.FormatBool(isTracked) + "</td></tr>")
_, _ = buffer.WriteString("<tr><td>" + fieldName + "</td><td>" + strconv.FormatBool(isTracked) + "</td></tr>")
}
buffer.WriteString("</tbody></table>\n")
_, _ = buffer.WriteString("</tbody></table>\n")
}
buffer.WriteString("\n")
buffer.Write(doc[tableEndIndex:])
_, _ = buffer.WriteString("\n")
_, _ = buffer.Write(doc[tableEndIndex:])
return buffer.Bytes(), nil
}

View File

@ -104,21 +104,21 @@ func updatePrometheusDoc(doc []byte, metricFamilies []dto.MetricFamily) ([]byte,
tableEndIndex := tableStartIndex + j
var buffer bytes.Buffer
buffer.Write(doc[:tableStartIndex])
buffer.WriteByte('\n')
_, _ = buffer.Write(doc[:tableStartIndex])
_ = buffer.WriteByte('\n')
buffer.WriteString("| Name | Type | Description | Labels |\n")
buffer.WriteString("| - | - | - | - |\n")
_, _ = buffer.WriteString("| Name | Type | Description | Labels |\n")
_, _ = buffer.WriteString("| - | - | - | - |\n")
for _, mf := range metricFamilies {
buffer.WriteString("| ")
buffer.Write([]byte("`" + *mf.Name + "`"))
buffer.WriteString(" | ")
buffer.Write([]byte(strings.ToLower(mf.Type.String())))
buffer.WriteString(" | ")
_, _ = buffer.WriteString("| ")
_, _ = buffer.Write([]byte("`" + *mf.Name + "`"))
_, _ = buffer.WriteString(" | ")
_, _ = buffer.Write([]byte(strings.ToLower(mf.Type.String())))
_, _ = buffer.WriteString(" | ")
if mf.Help != nil {
buffer.Write([]byte(*mf.Help))
_, _ = buffer.Write([]byte(*mf.Help))
}
buffer.WriteString(" | ")
_, _ = buffer.WriteString(" | ")
labels := map[string]struct{}{}
metrics := mf.GetMetric()
@ -129,14 +129,14 @@ func updatePrometheusDoc(doc []byte, metricFamilies []dto.MetricFamily) ([]byte,
}
if len(labels) > 0 {
buffer.WriteString(strings.Join(sortedKeys(labels), " "))
_, _ = buffer.WriteString(strings.Join(sortedKeys(labels), " "))
}
buffer.WriteString(" |\n")
_, _ = buffer.WriteString(" |\n")
}
buffer.WriteByte('\n')
buffer.Write(doc[tableEndIndex:])
_ = buffer.WriteByte('\n')
_, _ = buffer.Write(doc[tableEndIndex:])
return buffer.Bytes(), nil
}

View File

@ -456,7 +456,7 @@ func (c *coordinator) ServeHTTPDebug(w http.ResponseWriter, r *http.Request) {
c.mutex.RLock()
defer c.mutex.RUnlock()
fmt.Fprintln(w, "<h1>in-memory wireguard coordinator debug</h1>")
_, _ = fmt.Fprintln(w, "<h1>in-memory wireguard coordinator debug</h1>")
CoordinatorHTTPDebug(c.agentSockets, c.agentToConnectionSockets, c.agentNameCache)(w, r)
}
@ -475,8 +475,8 @@ func CoordinatorHTTPDebug(
}
{
fmt.Fprintf(w, "<h2 id=agents><a href=#agents>#</a> agents: total %d</h2>\n", len(agentSocketsMap))
fmt.Fprintln(w, "<ul>")
_, _ = fmt.Fprintf(w, "<h2 id=agents><a href=#agents>#</a> agents: total %d</h2>\n", len(agentSocketsMap))
_, _ = fmt.Fprintln(w, "<ul>")
agentSockets := make([]idConn, 0, len(agentSocketsMap))
for id, conn := range agentSocketsMap {
@ -488,7 +488,7 @@ func CoordinatorHTTPDebug(
})
for _, agent := range agentSockets {
fmt.Fprintf(w, "<li style=\"margin-top:4px\"><b>%s</b> (<code>%s</code>): created %v ago, write %v ago, overwrites %d </li>\n",
_, _ = fmt.Fprintf(w, "<li style=\"margin-top:4px\"><b>%s</b> (<code>%s</code>): created %v ago, write %v ago, overwrites %d </li>\n",
agent.conn.Name,
agent.id.String(),
now.Sub(time.Unix(agent.conn.Start, 0)).Round(time.Second),
@ -497,7 +497,7 @@ func CoordinatorHTTPDebug(
)
if conns := agentToConnectionSocketsMap[agent.id]; len(conns) > 0 {
fmt.Fprintf(w, "<h3 style=\"margin:0px;font-size:16px;font-weight:400\">connections: total %d</h3>\n", len(conns))
_, _ = fmt.Fprintf(w, "<h3 style=\"margin:0px;font-size:16px;font-weight:400\">connections: total %d</h3>\n", len(conns))
connSockets := make([]idConn, 0, len(conns))
for id, conn := range conns {
@ -507,20 +507,20 @@ func CoordinatorHTTPDebug(
return a.id.String() < b.id.String()
})
fmt.Fprintln(w, "<ul>")
_, _ = fmt.Fprintln(w, "<ul>")
for _, connSocket := range connSockets {
fmt.Fprintf(w, "<li><b>%s</b> (<code>%s</code>): created %v ago, write %v ago </li>\n",
_, _ = fmt.Fprintf(w, "<li><b>%s</b> (<code>%s</code>): created %v ago, write %v ago </li>\n",
connSocket.conn.Name,
connSocket.id.String(),
now.Sub(time.Unix(connSocket.conn.Start, 0)).Round(time.Second),
now.Sub(time.Unix(connSocket.conn.LastWrite, 0)).Round(time.Second),
)
}
fmt.Fprintln(w, "</ul>")
_, _ = fmt.Fprintln(w, "</ul>")
}
}
fmt.Fprintln(w, "</ul>")
_, _ = fmt.Fprintln(w, "</ul>")
}
{
@ -551,8 +551,8 @@ func CoordinatorHTTPDebug(
return a.id.String() < b.id.String()
})
fmt.Fprintf(w, "<h2 id=missing-agents><a href=#missing-agents>#</a> missing agents: total %d</h2>\n", len(missingAgents))
fmt.Fprintln(w, "<ul>")
_, _ = fmt.Fprintf(w, "<h2 id=missing-agents><a href=#missing-agents>#</a> missing agents: total %d</h2>\n", len(missingAgents))
_, _ = fmt.Fprintln(w, "<ul>")
for _, agentConns := range missingAgents {
agentName, ok := agentNameCache.Get(agentConns.id)
@ -560,24 +560,24 @@ func CoordinatorHTTPDebug(
agentName = "unknown"
}
fmt.Fprintf(w, "<li style=\"margin-top:4px\"><b>%s</b> (<code>%s</code>): created ? ago, write ? ago, overwrites ? </li>\n",
_, _ = fmt.Fprintf(w, "<li style=\"margin-top:4px\"><b>%s</b> (<code>%s</code>): created ? ago, write ? ago, overwrites ? </li>\n",
agentName,
agentConns.id.String(),
)
fmt.Fprintf(w, "<h3 style=\"margin:0px;font-size:16px;font-weight:400\">connections: total %d</h3>\n", len(agentConns.conns))
fmt.Fprintln(w, "<ul>")
_, _ = fmt.Fprintf(w, "<h3 style=\"margin:0px;font-size:16px;font-weight:400\">connections: total %d</h3>\n", len(agentConns.conns))
_, _ = fmt.Fprintln(w, "<ul>")
for _, agentConn := range agentConns.conns {
fmt.Fprintf(w, "<li><b>%s</b> (<code>%s</code>): created %v ago, write %v ago </li>\n",
_, _ = fmt.Fprintf(w, "<li><b>%s</b> (<code>%s</code>): created %v ago, write %v ago </li>\n",
agentConn.conn.Name,
agentConn.id.String(),
now.Sub(time.Unix(agentConn.conn.Start, 0)).Round(time.Second),
now.Sub(time.Unix(agentConn.conn.LastWrite, 0)).Round(time.Second),
)
}
fmt.Fprintln(w, "</ul>")
_, _ = fmt.Fprintln(w, "</ul>")
}
fmt.Fprintln(w, "</ul>")
_, _ = fmt.Fprintln(w, "</ul>")
}
}
}

View File

@ -30,11 +30,11 @@ func Eventually(ctx context.Context, t testing.TB, condition func(ctx context.Co
msg := "Eventually timed out"
if len(msgAndArgs) > 0 {
if m, ok := msgAndArgs[0].(string); ok {
msg = fmt.Sprintf(m, msgAndArgs[1:]...)
} else {
m, ok := msgAndArgs[0].(string)
if !ok {
panic("developer error: first argument of msgAndArgs must be a string")
}
msg = fmt.Sprintf(m, msgAndArgs[1:]...)
}
ticker := time.NewTicker(tick)