Skip to content

Commit 0e9437e

Browse files
committed
Merge branch 'main' into dean/user-maintenance-window
2 parents 3dbd077 + 19f5835 commit 0e9437e

File tree

160 files changed

+3490
-2263
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+3490
-2263
lines changed

.devcontainer/Dockerfile

-83
This file was deleted.

.devcontainer/devcontainer.json

+9-21
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
1-
// For format details, see https://aka.ms/devcontainer.json
21
{
32
"name": "Development environments on your infrastructure",
4-
5-
// Sets the run context to one level up instead of the .devcontainer folder.
6-
"context": ".",
7-
8-
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
9-
"dockerFile": "Dockerfile",
10-
11-
// Use 'forwardPorts' to make a list of ports inside the container available locally.
12-
// "forwardPorts": [],
13-
14-
"postStartCommand": "dockerd",
15-
16-
// privileged is required by GitHub codespaces - https://github.com/microsoft/vscode-dev-containers/issues/727
17-
"runArgs": [
18-
"--cap-add=SYS_PTRACE",
19-
"--security-opt",
20-
"seccomp=unconfined",
21-
"--privileged",
22-
"--init"
23-
]
3+
"image": "codercom/oss-dogfood:latest",
4+
5+
"features": {
6+
// See all possible options here https://github.com/devcontainers/features/tree/main/src/docker-in-docker
7+
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
8+
},
9+
// SYS_PTRACE to enable go debugging
10+
// without --priviliged the Github Codespace build fails (not required otherwise)
11+
"runArgs": ["--cap-add=SYS_PTRACE", "--privileged"]
2412
}

.github/actions/setup-go/action.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: |
44
inputs:
55
version:
66
description: "The Go version to use."
7-
default: "1.20.5"
7+
default: "1.20.6"
88
runs:
99
using: "composite"
1010
steps:

.github/dependabot.yaml

+31-15
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ updates:
4848
patterns:
4949
- "go.nhat.io/otelsql"
5050
- "go.opentelemetry.io/otel*"
51+
golang-x:
52+
patterns:
53+
- "golang.org/x/*"
5154

5255
# Update our Dockerfile.
5356
- package-ecosystem: "docker"
@@ -89,23 +92,36 @@ updates:
8992
- dependency-name: "@types/node"
9093
update-types:
9194
- version-update:semver-major
92-
93-
- package-ecosystem: "terraform"
94-
directory: "/examples/templates"
95-
schedule:
96-
interval: "monthly"
97-
time: "06:00"
98-
timezone: "America/Chicago"
99-
commit-message:
100-
prefix: "chore"
101-
labels: []
102-
ignore:
103-
# We likely want to update this ourselves.
104-
- dependency-name: "coder/coder"
10595
groups:
106-
examples-terraform:
96+
npm-react:
10797
patterns:
108-
- "*"
98+
- "react*"
99+
- "@types/react*"
100+
npm-xterm:
101+
patterns:
102+
- "xterm*"
103+
npm-xstate:
104+
patterns:
105+
- "xstate"
106+
- "@xstate*"
107+
npm-mui:
108+
patterns:
109+
- "@mui*"
110+
npm-storybook:
111+
patterns:
112+
- "@storybook*"
113+
- "storybook*"
114+
npm-eslint:
115+
patterns:
116+
- "eslint*"
117+
- "@eslint*"
118+
- "@typescript-eslint/eslint-plugin"
119+
- "@typescript-eslint/parser"
120+
npm-jest:
121+
patterns:
122+
- "jest*"
123+
- "@swc/jest"
124+
- "@types/jest"
109125

110126
# Update dogfood.
111127
- package-ecosystem: "docker"

.github/workflows/ci.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ jobs:
122122
123123
# Check for any typos
124124
- name: Check for typos
125-
uses: crate-ci/typos@v1.14.12
125+
uses: crate-ci/typos@v1.16.0
126126
with:
127127
config: .github/workflows/typos.toml
128128

.github/workflows/typos.toml

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Jetbrains = "JetBrains"
44
IST = "IST"
55
MacOS = "macOS"
66
AKS = "AKS"
7+
O_WRONLY = "O_WRONLY"
78

89
[default.extend-words]
910
AKS = "AKS"
@@ -25,4 +26,6 @@ extend-exclude = [
2526
"**XService**.ts",
2627
"**identity.go",
2728
"scripts/ci-report/testdata/**",
29+
"**/*_test.go",
30+
"**/*.test.tsx"
2831
]

.golangci.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
# Over time we should try tightening some of these.
33

44
linters-settings:
5+
exhaustruct:
6+
include:
7+
# Gradually extend to cover more of the codebase.
8+
- 'httpmw\.\w+'
59
gocognit:
610
min-complexity: 46 # Min code complexity (def 30).
711

@@ -195,6 +199,10 @@ issues:
195199
# We use assertions rather than explicitly checking errors in tests
196200
- errcheck
197201
- forcetypeassert
202+
- exhaustruct # This is unhelpful in tests.
203+
- path: scripts/*
204+
linters:
205+
- exhaustruct
198206

199207
fix: true
200208
max-issues-per-linter: 0
@@ -219,6 +227,7 @@ linters:
219227
- errcheck
220228
- errname
221229
- errorlint
230+
- exhaustruct
222231
- exportloopref
223232
- forcetypeassert
224233
- gocritic

agent/usershell/usershell_darwin.go

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
package usershell
22

3-
import "os"
3+
import (
4+
"os"
5+
"os/exec"
6+
"path/filepath"
7+
"strings"
8+
9+
"golang.org/x/xerrors"
10+
)
411

512
// Get returns the $SHELL environment variable.
6-
func Get(_ string) (string, error) {
7-
return os.Getenv("SHELL"), nil
13+
func Get(username string) (string, error) {
14+
// This command will output "UserShell: /bin/zsh" if successful, we
15+
// can ignore the error since we have fallback behavior.
16+
out, _ := exec.Command("dscl", ".", "-read", filepath.Join("/Users", username), "UserShell").Output()
17+
s, ok := strings.CutPrefix(string(out), "UserShell: ")
18+
if ok {
19+
return strings.TrimSpace(s), nil
20+
}
21+
if s = os.Getenv("SHELL"); s != "" {
22+
return s, nil
23+
}
24+
return "", xerrors.Errorf("shell for user %q not found via dscl or in $SHELL", username)
825
}

agent/usershell/usershell_other.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,8 @@ func Get(username string) (string, error) {
2727
}
2828
return parts[6], nil
2929
}
30-
return "", xerrors.Errorf("user %q not found in /etc/passwd", username)
30+
if s := os.Getenv("SHELL"); s != "" {
31+
return s, nil
32+
}
33+
return "", xerrors.Errorf("shell for user %q not found in /etc/passwd or $SHELL", username)
3134
}

agent/usershell/usershell_other_test.go

-27
This file was deleted.

agent/usershell/usershell_test.go

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package usershell_test
2+
3+
import (
4+
"os/user"
5+
"runtime"
6+
"testing"
7+
8+
"github.com/stretchr/testify/require"
9+
10+
"github.com/coder/coder/agent/usershell"
11+
)
12+
13+
//nolint:paralleltest,tparallel // This test sets an environment variable.
14+
func TestGet(t *testing.T) {
15+
if runtime.GOOS == "windows" {
16+
t.SkipNow()
17+
}
18+
19+
t.Run("Fallback", func(t *testing.T) {
20+
t.Setenv("SHELL", "/bin/sh")
21+
22+
t.Run("NonExistentUser", func(t *testing.T) {
23+
shell, err := usershell.Get("notauser")
24+
require.NoError(t, err)
25+
require.Equal(t, "/bin/sh", shell)
26+
})
27+
})
28+
29+
t.Run("NoFallback", func(t *testing.T) {
30+
// Disable env fallback for these tests.
31+
t.Setenv("SHELL", "")
32+
33+
t.Run("NotFound", func(t *testing.T) {
34+
_, err := usershell.Get("notauser")
35+
require.Error(t, err)
36+
})
37+
38+
t.Run("User", func(t *testing.T) {
39+
u, err := user.Current()
40+
require.NoError(t, err)
41+
shell, err := usershell.Get(u.Username)
42+
require.NoError(t, err)
43+
require.NotEmpty(t, shell)
44+
})
45+
})
46+
}

cli/clibase/cmd.go

+12
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,18 @@ func (inv *Invocation) run(state *runState) error {
333333
)
334334
}
335335

336+
// All options should be set. Check all required options have sources,
337+
// meaning they were set by the user in some way (env, flag, etc).
338+
var missing []string
339+
for _, opt := range inv.Command.Options {
340+
if opt.Required && opt.ValueSource == ValueSourceNone {
341+
missing = append(missing, opt.Flag)
342+
}
343+
}
344+
if len(missing) > 0 {
345+
return xerrors.Errorf("Missing values for the required flags: %s", strings.Join(missing, ", "))
346+
}
347+
336348
if inv.Command.RawArgs {
337349
// If we're at the root command, then the name is omitted
338350
// from the arguments, so we can just use the entire slice.

0 commit comments

Comments
 (0)