Skip to content

Commit 51b0079

Browse files
committed
Merge branch 'main' into execscripts
2 parents 7199651 + da0ef92 commit 51b0079

File tree

331 files changed

+9215
-5177
lines changed

Some content is hidden

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

331 files changed

+9215
-5177
lines changed

.github/workflows/ci.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ jobs:
137137
138138
# Check for any typos
139139
- name: Check for typos
140-
uses: crate-ci/typos@v1.16.8
140+
uses: crate-ci/typos@v1.16.10
141141
with:
142142
config: .github/workflows/typos.toml
143143

@@ -554,7 +554,7 @@ jobs:
554554
- run: pnpm playwright:install
555555
working-directory: site
556556

557-
- run: pnpm playwright:test
557+
- run: pnpm playwright:test --workers 1
558558
env:
559559
DEBUG: pw:api
560560
working-directory: site
@@ -567,6 +567,14 @@ jobs:
567567
path: ./site/test-results/**/*.webm
568568
retention-days: 7
569569

570+
- name: Upload pprof dumps
571+
if: always() && github.actor != 'dependabot[bot]' && runner.os == 'Linux' && !github.event.pull_request.head.repo.fork
572+
uses: actions/upload-artifact@v3
573+
with:
574+
name: debug-pprof-dumps
575+
path: ./site/test-results/**/debug-pprof-*.txt
576+
retention-days: 7
577+
570578
chromatic:
571579
# REMARK: this is only used to build storybook and deploy it to Chromatic.
572580
runs-on: ubuntu-latest

.github/workflows/release.yaml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,85 @@ jobs:
328328
event-type: coder-release
329329
client-payload: '{"coder_version": "${{ steps.version.outputs.version }}"}'
330330

331+
publish-homebrew:
332+
name: Publish to Homebrew tap
333+
runs-on: ubuntu-latest
334+
needs: release
335+
if: ${{ !inputs.dry_run }}
336+
337+
steps:
338+
# TODO: skip this if it's not a new release (i.e. a backport). This is
339+
# fine right now because it just makes a PR that we can close.
340+
- name: Update homebrew
341+
env:
342+
# Variables used by the `gh` command
343+
GH_REPO: coder/homebrew-coder
344+
GH_TOKEN: ${{ secrets.CDRCI_GITHUB_TOKEN }}
345+
run: |
346+
# Keep version number around for reference, removing any potential leading v
347+
coder_version="$(echo "${{ needs.release.outputs.version }}" | tr -d v)"
348+
349+
set -euxo pipefail
350+
351+
# Setup Git
352+
git config --global user.email "ci@coder.com"
353+
git config --global user.name "Coder CI"
354+
git config --global credential.helper "store"
355+
356+
temp_dir="$(mktemp -d)"
357+
cd "$temp_dir"
358+
359+
# Download checksums
360+
checksums_url="$(gh release view --repo coder/coder v2.1.4 --json assets \
361+
| jq -r ".assets | map(.url) | .[]" \
362+
| grep -e ".checksums.txt\$")"
363+
wget "$checksums_url" -O checksums.txt
364+
365+
# Get the SHAs
366+
darwin_arm_sha="$(cat checksums.txt | grep "darwin_arm64.zip" | awk '{ print $1 }')"
367+
darwin_intel_sha="$(cat checksums.txt | grep "darwin_amd64.zip" | awk '{ print $1 }')"
368+
linux_sha="$(cat checksums.txt | grep "linux_amd64.tar.gz" | awk '{ print $1 }')"
369+
370+
echo "macOS arm64: $darwin_arm_sha"
371+
echo "macOS amd64: $darwin_intel_sha"
372+
echo "Linux amd64: $linux_sha"
373+
374+
# Check out the homebrew repo
375+
git clone "https://github.com/$GH_REPO" homebrew-coder
376+
brew_branch="auto-release/$coder_version"
377+
cd homebrew-coder
378+
379+
# Check if a PR already exists.
380+
pr_count="$(gh pr list --search "head:$brew_branch" --json id,closed | jq -r ".[] | select(.closed == false) | .id" | wc -l)"
381+
if [[ "$pr_count" > 0 ]]; then
382+
echo "Bailing out as PR already exists" 2>&1
383+
exit 0
384+
fi
385+
386+
# Set up cdrci credentials for pushing to homebrew-coder
387+
echo "https://x-access-token:$GH_TOKEN@github.com" >> ~/.git-credentials
388+
# Update the formulae and push
389+
git checkout -b "$brew_branch"
390+
./scripts/update-v2.sh "$coder_version" "$darwin_arm_sha" "$darwin_intel_sha" "$linux_sha"
391+
git add .
392+
git commit -m "coder $coder_version"
393+
git push -u origin -f "$brew_branch"
394+
395+
# Create PR
396+
gh pr create \
397+
-B master -H "$brew_branch" \
398+
-t "coder $coder_version" \
399+
-b "" \
400+
-r "${{ github.actor }}" \
401+
-a "${{ github.actor }}" \
402+
-b "This automatic PR was triggered by the release of Coder v$coder_version"
403+
331404
publish-winget:
332405
name: Publish to winget-pkgs
333406
runs-on: windows-latest
334407
needs: release
335408
if: ${{ !inputs.dry_run }}
409+
336410
steps:
337411
- name: Checkout
338412
uses: actions/checkout@v3
@@ -412,6 +486,7 @@ jobs:
412486
runs-on: windows-latest
413487
needs: release
414488
if: ${{ !inputs.dry_run }}
489+
415490
steps:
416491
- name: Checkout
417492
uses: actions/checkout@v3

.github/workflows/security.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ jobs:
122122
image_name: ${{ steps.build.outputs.image }}
123123

124124
- name: Run Trivy vulnerability scanner
125-
uses: aquasecurity/trivy-action@41f05d9ecffa2ed3f1580af306000f734b733e54
125+
uses: aquasecurity/trivy-action@fbd16365eb88e12433951383f5e99bd901fc618f
126126
with:
127127
image-ref: ${{ steps.build.outputs.image }}
128128
format: sarif

.golangci.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ linters-settings:
131131
- trialer
132132

133133
nestif:
134-
min-complexity: 4 # Min complexity of if statements (def 5, goal 4)
134+
# goal: 10
135+
min-complexity: 20
135136

136137
revive:
137138
# see https://github.com/mgechev/revive#available-rules for details.
@@ -237,6 +238,7 @@ linters:
237238
# create a good culture around cognitive complexity.
238239
# - gocyclo
239240
- gocognit
241+
- nestif
240242
- goimports
241243
- gomodguard
242244
- gosec

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,6 @@ scripts/apitypings/testdata/**/*.ts
8383
site/e2e/provisionerGenerated.ts
8484

8585
**/pnpm-lock.yaml
86+
87+
# Ignore generated JSON (e.g. examples/examples.gen.json).
88+
**/*.gen.json

.prettierignore.include

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ scripts/apitypings/testdata/**/*.ts
1313
site/e2e/provisionerGenerated.ts
1414

1515
**/pnpm-lock.yaml
16+
17+
# Ignore generated JSON (e.g. examples/examples.gen.json).
18+
**/*.gen.json

Makefile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,8 @@ gen: \
471471
site/.prettierrc.yaml \
472472
site/.prettierignore \
473473
site/.eslintignore \
474-
site/e2e/provisionerGenerated.ts
474+
site/e2e/provisionerGenerated.ts \
475+
examples/examples.gen.json
475476
.PHONY: gen
476477

477478
# Mark all generated files as fresh so make thinks they're up-to-date. This is
@@ -494,6 +495,7 @@ gen/mark-fresh:
494495
site/.prettierignore \
495496
site/.eslintignore \
496497
site/e2e/provisionerGenerated.ts \
498+
examples/examples.gen.json \
497499
"
498500
for file in $$files; do
499501
echo "$$file"
@@ -545,14 +547,18 @@ site/e2e/provisionerGenerated.ts:
545547
../scripts/pnpm_install.sh
546548
pnpm run gen:provisioner
547549

550+
551+
examples/examples.gen.json: scripts/examplegen/main.go examples/examples.go $(shell find ./examples/templates)
552+
go run ./scripts/examplegen/main.go > examples/examples.gen.json
553+
548554
coderd/rbac/object_gen.go: scripts/rbacgen/main.go coderd/rbac/object.go
549555
go run scripts/rbacgen/main.go ./coderd/rbac > coderd/rbac/object_gen.go
550556

551557
docs/admin/prometheus.md: scripts/metricsdocgen/main.go scripts/metricsdocgen/metrics
552558
go run scripts/metricsdocgen/main.go
553559
pnpm run format:write:only ./docs/admin/prometheus.md
554560

555-
docs/cli.md: scripts/clidocgen/main.go $(GO_SRC_FILES)
561+
docs/cli.md: scripts/clidocgen/main.go examples/examples.gen.json $(GO_SRC_FILES)
556562
BASE_PATH="." go run ./scripts/clidocgen
557563
pnpm run format:write:only ./docs/cli.md ./docs/cli/*.md ./docs/manifest.json
558564

@@ -605,7 +611,7 @@ site/.prettierrc.yaml: .prettierrc.yaml
605611
# - ./ -> ../
606612
# - ./site -> ./
607613
yq \
608-
'.overrides[].files |= map(. | sub("^./"; "") | sub("^"; "../") | sub("../site/"; "./"))' \
614+
'.overrides[].files |= map(. | sub("^./"; "") | sub("^"; "../") | sub("../site/"; "./") | sub("../!"; "!../"))' \
609615
"$<" >> "$@"
610616

611617
# Combine .gitignore with .prettierignore.include to generate .prettierignore.

agent/agent.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ import (
3737
"github.com/coder/coder/v2/agent/agentssh"
3838
"github.com/coder/coder/v2/agent/reconnectingpty"
3939
"github.com/coder/coder/v2/buildinfo"
40-
"github.com/coder/coder/v2/coderd/database"
41-
"github.com/coder/coder/v2/coderd/gitauth"
40+
"github.com/coder/coder/v2/cli/gitauth"
41+
"github.com/coder/coder/v2/coderd/database/dbtime"
4242
"github.com/coder/coder/v2/codersdk"
4343
"github.com/coder/coder/v2/codersdk/agentsdk"
4444
"github.com/coder/coder/v2/tailnet"
@@ -523,7 +523,7 @@ func (a *agent) reportLifecycleLoop(ctx context.Context) {
523523
func (a *agent) setLifecycle(ctx context.Context, state codersdk.WorkspaceAgentLifecycle) {
524524
report := agentsdk.PostLifecycleRequest{
525525
State: state,
526-
ChangedAt: database.Now(),
526+
ChangedAt: dbtime.Now(),
527527
}
528528

529529
a.lifecycleMu.Lock()

cli/cliui/provisionerjob_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
"github.com/coder/coder/v2/cli/clibase"
1515
"github.com/coder/coder/v2/cli/cliui"
16-
"github.com/coder/coder/v2/coderd/database"
16+
"github.com/coder/coder/v2/coderd/database/dbtime"
1717
"github.com/coder/coder/v2/codersdk"
1818
"github.com/coder/coder/v2/pty/ptytest"
1919
)
@@ -29,13 +29,13 @@ func TestProvisionerJob(t *testing.T) {
2929
<-test.Next
3030
test.JobMutex.Lock()
3131
test.Job.Status = codersdk.ProvisionerJobRunning
32-
now := database.Now()
32+
now := dbtime.Now()
3333
test.Job.StartedAt = &now
3434
test.JobMutex.Unlock()
3535
<-test.Next
3636
test.JobMutex.Lock()
3737
test.Job.Status = codersdk.ProvisionerJobSucceeded
38-
now = database.Now()
38+
now = dbtime.Now()
3939
test.Job.CompletedAt = &now
4040
close(test.Logs)
4141
test.JobMutex.Unlock()
@@ -56,17 +56,17 @@ func TestProvisionerJob(t *testing.T) {
5656
<-test.Next
5757
test.JobMutex.Lock()
5858
test.Job.Status = codersdk.ProvisionerJobRunning
59-
now := database.Now()
59+
now := dbtime.Now()
6060
test.Job.StartedAt = &now
6161
test.Logs <- codersdk.ProvisionerJobLog{
62-
CreatedAt: database.Now(),
62+
CreatedAt: dbtime.Now(),
6363
Stage: "Something",
6464
}
6565
test.JobMutex.Unlock()
6666
<-test.Next
6767
test.JobMutex.Lock()
6868
test.Job.Status = codersdk.ProvisionerJobSucceeded
69-
now = database.Now()
69+
now = dbtime.Now()
7070
test.Job.CompletedAt = &now
7171
close(test.Logs)
7272
test.JobMutex.Unlock()
@@ -99,7 +99,7 @@ func TestProvisionerJob(t *testing.T) {
9999
<-test.Next
100100
test.JobMutex.Lock()
101101
test.Job.Status = codersdk.ProvisionerJobCanceled
102-
now := database.Now()
102+
now := dbtime.Now()
103103
test.Job.CompletedAt = &now
104104
close(test.Logs)
105105
test.JobMutex.Unlock()
@@ -123,7 +123,7 @@ type provisionerJobTest struct {
123123
func newProvisionerJob(t *testing.T) provisionerJobTest {
124124
job := &codersdk.ProvisionerJob{
125125
Status: codersdk.ProvisionerJobPending,
126-
CreatedAt: database.Now(),
126+
CreatedAt: dbtime.Now(),
127127
}
128128
jobLock := sync.Mutex{}
129129
logs := make(chan codersdk.ProvisionerJobLog, 1)

cli/cliui/resources.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import (
99
"github.com/jedib0t/go-pretty/v6/table"
1010
"golang.org/x/mod/semver"
1111

12-
"github.com/coder/coder/v2/coderd/database"
13-
12+
"github.com/coder/coder/v2/coderd/database/dbtime"
1413
"github.com/coder/coder/v2/codersdk"
1514
)
1615

@@ -122,15 +121,15 @@ func WorkspaceResources(writer io.Writer, resources []codersdk.WorkspaceResource
122121
func renderAgentStatus(agent codersdk.WorkspaceAgent) string {
123122
switch agent.Status {
124123
case codersdk.WorkspaceAgentConnecting:
125-
since := database.Now().Sub(agent.CreatedAt)
124+
since := dbtime.Now().Sub(agent.CreatedAt)
126125
return DefaultStyles.Warn.Render("⦾ connecting") + " " +
127126
DefaultStyles.Placeholder.Render("["+strconv.Itoa(int(since.Seconds()))+"s]")
128127
case codersdk.WorkspaceAgentDisconnected:
129-
since := database.Now().Sub(*agent.DisconnectedAt)
128+
since := dbtime.Now().Sub(*agent.DisconnectedAt)
130129
return DefaultStyles.Error.Render("⦾ disconnected") + " " +
131130
DefaultStyles.Placeholder.Render("["+strconv.Itoa(int(since.Seconds()))+"s]")
132131
case codersdk.WorkspaceAgentTimeout:
133-
since := database.Now().Sub(agent.CreatedAt)
132+
since := dbtime.Now().Sub(agent.CreatedAt)
134133
return fmt.Sprintf(
135134
"%s %s",
136135
DefaultStyles.Warn.Render("⦾ timeout"),

cli/cliui/resources_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/stretchr/testify/assert"
88

99
"github.com/coder/coder/v2/cli/cliui"
10-
"github.com/coder/coder/v2/coderd/database"
10+
"github.com/coder/coder/v2/coderd/database/dbtime"
1111
"github.com/coder/coder/v2/codersdk"
1212
"github.com/coder/coder/v2/pty/ptytest"
1313
)
@@ -44,7 +44,7 @@ func TestWorkspaceResources(t *testing.T) {
4444
t.Run("MultipleStates", func(t *testing.T) {
4545
t.Parallel()
4646
ptty := ptytest.New(t)
47-
disconnected := database.Now().Add(-4 * time.Second)
47+
disconnected := dbtime.Now().Add(-4 * time.Second)
4848
done := make(chan struct{})
4949
go func() {
5050
err := cliui.WorkspaceResources(ptty.Output(), []codersdk.WorkspaceResource{{
@@ -60,7 +60,7 @@ func TestWorkspaceResources(t *testing.T) {
6060
Type: "google_compute_instance",
6161
Name: "dev",
6262
Agents: []codersdk.WorkspaceAgent{{
63-
CreatedAt: database.Now().Add(-10 * time.Second),
63+
CreatedAt: dbtime.Now().Add(-10 * time.Second),
6464
Status: codersdk.WorkspaceAgentConnecting,
6565
LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
6666
Name: "dev",

cli/dotfiles.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ func (r *RootCmd) dotfiles() *clibase.Cmd {
176176

177177
var dotfiles []string
178178
for _, f := range files {
179-
// make sure we do not copy `.git*` files
180-
if strings.HasPrefix(f.Name(), ".") && !strings.HasPrefix(f.Name(), ".git") {
179+
// make sure we do not copy `.git*` files except `.gitconfig`
180+
if strings.HasPrefix(f.Name(), ".") && (!strings.HasPrefix(f.Name(), ".git") || f.Name() == ".gitconfig") {
181181
dotfiles = append(dotfiles, f.Name())
182182
}
183183
}

cli/gitaskpass.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
"github.com/coder/coder/v2/cli/clibase"
1313
"github.com/coder/coder/v2/cli/cliui"
14-
"github.com/coder/coder/v2/coderd/gitauth"
14+
"github.com/coder/coder/v2/cli/gitauth"
1515
"github.com/coder/coder/v2/codersdk"
1616
"github.com/coder/retry"
1717
)
@@ -44,7 +44,13 @@ func (r *RootCmd) gitAskpass() *clibase.Cmd {
4444
if errors.As(err, &apiError) && apiError.StatusCode() == http.StatusNotFound {
4545
// This prevents the "Run 'coder --help' for usage"
4646
// message from occurring.
47-
cliui.Errorf(inv.Stderr, "%s\n", apiError.Message)
47+
lines := []string{apiError.Message}
48+
if apiError.Detail != "" {
49+
lines = append(lines, apiError.Detail)
50+
}
51+
cliui.Warn(inv.Stderr, "Coder was unable to handle this git request. The default git behavior will be used instead.",
52+
lines...,
53+
)
4854
return cliui.Canceled
4955
}
5056
return xerrors.Errorf("get git token: %w", err)
File renamed without changes.

coderd/gitauth/askpass_test.go renamed to cli/gitauth/askpass_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55

66
"github.com/stretchr/testify/require"
77

8-
"github.com/coder/coder/v2/coderd/gitauth"
8+
"github.com/coder/coder/v2/cli/gitauth"
99
)
1010

1111
func TestCheckCommand(t *testing.T) {
File renamed without changes.

0 commit comments

Comments
 (0)