Skip to content

Commit c5e2338

Browse files
committed
Merge branch 'main' into colorful-rebased
2 parents a3f1a55 + 5b071f4 commit c5e2338

File tree

367 files changed

+12948
-5692
lines changed

Some content is hidden

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

367 files changed

+12948
-5692
lines changed

.github/workflows/ci.yaml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ jobs:
144144
145145
# Check for any typos
146146
- name: Check for typos
147-
uses: crate-ci/typos@v1.16.24
147+
uses: crate-ci/typos@v1.16.25
148148
with:
149149
config: .github/workflows/typos.toml
150150

@@ -322,7 +322,9 @@ jobs:
322322

323323
test-go-pg:
324324
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
325-
needs: changes
325+
needs:
326+
- changes
327+
- sqlc-vet # No point in testing the DB if the queries are invalid
326328
if: needs.changes.outputs.go == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
327329
# This timeout must be greater than the timeout set by `go test` in
328330
# `make test-postgres` to ensure we receive a trace of running
@@ -478,15 +480,15 @@ jobs:
478480

479481
- name: Upload Playwright Failed Tests
480482
if: always() && github.actor != 'dependabot[bot]' && runner.os == 'Linux' && !github.event.pull_request.head.repo.fork
481-
uses: actions/upload-artifact@v3
483+
uses: actions/upload-artifact@v4
482484
with:
483485
name: failed-test-videos
484486
path: ./site/test-results/**/*.webm
485487
retention-days: 7
486488

487489
- name: Upload pprof dumps
488490
if: always() && github.actor != 'dependabot[bot]' && runner.os == 'Linux' && !github.event.pull_request.head.repo.fork
489-
uses: actions/upload-artifact@v3
491+
uses: actions/upload-artifact@v4
490492
with:
491493
name: debug-pprof-dumps
492494
path: ./site/test-results/**/debug-pprof-*.txt
@@ -734,7 +736,7 @@ jobs:
734736
prune-untagged: true
735737

736738
- name: Upload build artifacts
737-
uses: actions/upload-artifact@v3
739+
uses: actions/upload-artifact@v4
738740
with:
739741
name: coder
740742
path: |
@@ -775,7 +777,7 @@ jobs:
775777
uses: fluxcd/flux2/action@main
776778
with:
777779
# Keep this up to date with the version of flux installed in dogfood cluster
778-
version: "2.2.0"
780+
version: "2.2.1"
779781

780782
- name: Get Cluster Credentials
781783
uses: "google-github-actions/get-gke-credentials@v2"
@@ -853,7 +855,7 @@ jobs:
853855
uses: google-github-actions/setup-gcloud@v2
854856

855857
- name: Download build artifacts
856-
uses: actions/download-artifact@v3
858+
uses: actions/download-artifact@v4
857859
with:
858860
name: coder
859861
path: ./build
@@ -896,7 +898,7 @@ jobs:
896898
sqlc-vet:
897899
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
898900
needs: changes
899-
if: needs.changes.outputs.db == 'true' || github.ref == 'refs/heads/main'
901+
if: needs.changes.outputs.db == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
900902
steps:
901903
- name: Checkout
902904
uses: actions/checkout@v4

.github/workflows/pr-deploy.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ on:
99
- main
1010
workflow_dispatch:
1111
inputs:
12-
pr_number:
13-
description: "PR number"
14-
type: number
15-
required: true
1612
experiments:
1713
description: "Experiments to enable"
1814
required: false
@@ -355,6 +351,7 @@ jobs:
355351
- name: Install/Upgrade Helm chart
356352
run: |
357353
set -euo pipefail
354+
helm dependency update --skip-refresh ./helm/coder
358355
helm upgrade --install "pr${{ env.PR_NUMBER }}" ./helm/coder \
359356
--namespace "pr${{ env.PR_NUMBER }}" \
360357
--values ./pr-deploy-values.yaml \

.github/workflows/release.yaml

Lines changed: 16 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ jobs:
306306
307307
- name: Upload artifacts to actions (if dry-run)
308308
if: ${{ inputs.dry_run }}
309-
uses: actions/upload-artifact@v3
309+
uses: actions/upload-artifact@v4
310310
with:
311311
name: release-artifacts
312312
path: |
@@ -480,65 +480,28 @@ jobs:
480480
# different repo.
481481
GH_TOKEN: ${{ secrets.CDRCI_GITHUB_TOKEN }}
482482

483-
publish-chocolatey:
484-
name: Publish to Chocolatey
485-
runs-on: windows-latest
483+
# publish-sqlc pushes the latest schema to sqlc cloud.
484+
# At present these pushes cannot be tagged, so the last push is always the latest.
485+
publish-sqlc:
486+
name: "Publish to schema sqlc cloud"
487+
runs-on: "ubuntu-latest"
486488
needs: release
487489
if: ${{ !inputs.dry_run }}
488-
489490
steps:
490491
- name: Checkout
491492
uses: actions/checkout@v4
492493
with:
493-
fetch-depth: 0
494-
495-
# Same reason as for release.
496-
- name: Fetch git tags
497-
run: git fetch --tags --force
494+
fetch-depth: 1
498495

499-
# From https://chocolatey.org
500-
- name: Install Chocolatey
501-
run: |
502-
Set-ExecutionPolicy Bypass -Scope Process -Force
503-
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
496+
# We need golang to run the migration main.go
497+
- name: Setup Go
498+
uses: ./.github/actions/setup-go
504499

505-
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
500+
- name: Setup sqlc
501+
uses: ./.github/actions/setup-sqlc
506502

507-
- name: Build chocolatey package
503+
- name: Push schema to sqlc cloud
504+
# Don't block a release on this
505+
continue-on-error: true
508506
run: |
509-
cd scripts/chocolatey
510-
511-
# The package version is the same as the tag minus the leading "v".
512-
# The version in this output already has the leading "v" removed but
513-
# we do it again to be safe.
514-
$version = "${{ needs.release.outputs.version }}".Trim('v')
515-
516-
$release_assets = gh release view --repo coder/coder "v${version}" --json assets | `
517-
ConvertFrom-Json
518-
519-
# Get the URL for the Windows ZIP from the release assets.
520-
$zip_url = $release_assets.assets | `
521-
Where-Object name -Match ".*_windows_amd64.zip$" | `
522-
Select -ExpandProperty url
523-
524-
echo "ZIP URL: ${zip_url}"
525-
echo "Package version: ${version}"
526-
527-
echo "Downloading ZIP..."
528-
Invoke-WebRequest $zip_url -OutFile assets.zip
529-
530-
echo "Extracting ZIP..."
531-
Expand-Archive assets.zip -DestinationPath assets/
532-
533-
# No need to specify nuspec if there's only one in the directory.
534-
choco pack --version=$version binary_path=assets/coder.exe
535-
536-
choco apikey --api-key $env:CHOCO_API_KEY --source https://push.chocolatey.org/
537-
538-
# No need to specify nupkg if there's only one in the directory.
539-
choco push --source https://push.chocolatey.org/
540-
541-
env:
542-
CHOCO_API_KEY: ${{ secrets.CHOCO_API_KEY }}
543-
# We need a GitHub token for the gh CLI to function under GitHub Actions
544-
GH_TOKEN: ${{ secrets.CDRCI_GITHUB_TOKEN }}
507+
make sqlc-push

.github/workflows/security.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
uses: actions/checkout@v4
3030

3131
- name: Initialize CodeQL
32-
uses: github/codeql-action/init@v2
32+
uses: github/codeql-action/init@v3
3333
with:
3434
languages: go, javascript
3535

@@ -42,7 +42,7 @@ jobs:
4242
rm Makefile
4343
4444
- name: Perform CodeQL Analysis
45-
uses: github/codeql-action/analyze@v2
45+
uses: github/codeql-action/analyze@v3
4646

4747
- name: Send Slack notification on failure
4848
if: ${{ failure() }}
@@ -130,13 +130,13 @@ jobs:
130130
severity: "CRITICAL,HIGH"
131131

132132
- name: Upload Trivy scan results to GitHub Security tab
133-
uses: github/codeql-action/upload-sarif@v2
133+
uses: github/codeql-action/upload-sarif@v3
134134
with:
135135
sarif_file: trivy-results.sarif
136136
category: "Trivy"
137137

138138
- name: Upload Trivy scan results as an artifact
139-
uses: actions/upload-artifact@v3
139+
uses: actions/upload-artifact@v4
140140
with:
141141
name: trivy
142142
path: trivy-results.sarif

.github/workflows/typos.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ extend-exclude = [
3030
"**/*_test.go",
3131
"**/*.test.tsx",
3232
"**/pnpm-lock.yaml",
33+
"tailnet/testdata/**",
3334
]

Makefile

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ docs/cli.md: scripts/clidocgen/main.go examples/examples.gen.json $(GO_SRC_FILES
588588
CI=true BASE_PATH="." go run ./scripts/clidocgen
589589
pnpm run format:write:only ./docs/cli.md ./docs/cli/*.md ./docs/manifest.json
590590

591-
docs/admin/audit-logs.md: scripts/auditdocgen/main.go enterprise/audit/table.go coderd/rbac/object_gen.go
591+
docs/admin/audit-logs.md: coderd/database/querier.go scripts/auditdocgen/main.go enterprise/audit/table.go coderd/rbac/object_gen.go
592592
go run scripts/auditdocgen/main.go
593593
pnpm run format:write:only ./docs/admin/audit-logs.md
594594

@@ -708,6 +708,27 @@ test:
708708
gotestsum --format standard-quiet -- -v -short -count=1 ./...
709709
.PHONY: test
710710

711+
# sqlc-cloud-is-setup will fail if no SQLc auth token is set. Use this as a
712+
# dependency for any sqlc-cloud related targets.
713+
sqlc-cloud-is-setup:
714+
if [[ "$(SQLC_AUTH_TOKEN)" == "" ]]; then
715+
echo "ERROR: 'SQLC_AUTH_TOKEN' must be set to auth with sqlc cloud before running verify." 1>&2
716+
exit 1
717+
fi
718+
.PHONY: sqlc-cloud-is-setup
719+
720+
sqlc-push: sqlc-cloud-is-setup test-postgres-docker
721+
echo "--- sqlc push"
722+
SQLC_DATABASE_URL="postgresql://postgres:postgres@localhost:5432/$(shell go run scripts/migrate-ci/main.go)" \
723+
sqlc push -f coderd/database/sqlc.yaml && echo "Passed sqlc push"
724+
.PHONY: sqlc-push
725+
726+
sqlc-verify: sqlc-cloud-is-setup test-postgres-docker
727+
echo "--- sqlc verify"
728+
SQLC_DATABASE_URL="postgresql://postgres:postgres@localhost:5432/$(shell go run scripts/migrate-ci/main.go)" \
729+
sqlc verify -f coderd/database/sqlc.yaml && echo "Passed sqlc verify"
730+
.PHONY: sqlc-verify
731+
711732
sqlc-vet: test-postgres-docker
712733
echo "--- sqlc vet"
713734
SQLC_DATABASE_URL="postgresql://postgres:postgres@localhost:5432/$(shell go run scripts/migrate-ci/main.go)" \

agent/agent_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,9 +1635,10 @@ func TestAgent_Dial(t *testing.T) {
16351635
go func() {
16361636
defer close(done)
16371637
c, err := l.Accept()
1638-
assert.NoError(t, err, "accept connection")
1639-
defer c.Close()
1640-
testAccept(ctx, t, c)
1638+
if assert.NoError(t, err, "accept connection") {
1639+
defer c.Close()
1640+
testAccept(ctx, t, c)
1641+
}
16411642
}()
16421643

16431644
//nolint:dogsled

agent/agentscripts/agentscripts.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,18 @@ func (r *Runner) StartCron() {
129129
// has exited by the time the `cron.Stop()` context returns, so we need to
130130
// track it manually.
131131
err := r.trackCommandGoroutine(func() {
132-
r.cron.Run()
132+
// Since this is run async, in quick unit tests, it is possible the
133+
// Close() function gets called before we even start the cron.
134+
// In these cases, the Run() will never end.
135+
// So if we are closed, we just return, and skip the Run() entirely.
136+
select {
137+
case <-r.cronCtx.Done():
138+
// The cronCtx is canceled before cron.Close() happens. So if the ctx is
139+
// canceled, then Close() will be called, or it is about to be called.
140+
// So do nothing!
141+
default:
142+
r.cron.Run()
143+
}
133144
})
134145
if err != nil {
135146
r.Logger.Warn(context.Background(), "start cron failed", slog.Error(err))
@@ -315,6 +326,7 @@ func (r *Runner) Close() error {
315326
return nil
316327
}
317328
close(r.closed)
329+
// Must cancel the cron ctx BEFORE stopping the cron.
318330
r.cronCtxCancel()
319331
<-r.cron.Stop().Done()
320332
r.cmdCloseWait.Wait()

agent/agentscripts/agentscripts_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ func TestTimeout(t *testing.T) {
5353
require.ErrorIs(t, runner.Execute(context.Background(), nil), agentscripts.ErrTimeout)
5454
}
5555

56+
// TestCronClose exists because cron.Run() can happen after cron.Close().
57+
// If this happens, there used to be a deadlock.
58+
func TestCronClose(t *testing.T) {
59+
t.Parallel()
60+
runner := agentscripts.New(agentscripts.Options{})
61+
runner.StartCron()
62+
require.NoError(t, runner.Close(), "close runner")
63+
}
64+
5665
func setup(t *testing.T, patchLogs func(ctx context.Context, req agentsdk.PatchLogs) error) *agentscripts.Runner {
5766
t.Helper()
5867
if patchLogs == nil {

agent/agenttest/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func NewClient(t testing.TB,
2424
agentID uuid.UUID,
2525
manifest agentsdk.Manifest,
2626
statsChan chan *agentsdk.Stats,
27-
coordinator tailnet.Coordinator,
27+
coordinator tailnet.CoordinatorV1,
2828
) *Client {
2929
if manifest.AgentID == uuid.Nil {
3030
manifest.AgentID = agentID
@@ -47,7 +47,7 @@ type Client struct {
4747
manifest agentsdk.Manifest
4848
metadata map[string]agentsdk.Metadata
4949
statsChan chan *agentsdk.Stats
50-
coordinator tailnet.Coordinator
50+
coordinator tailnet.CoordinatorV1
5151
LastWorkspaceAgent func()
5252
PatchWorkspaceLogs func() error
5353
GetServiceBannerFunc func() (codersdk.ServiceBannerConfig, error)

0 commit comments

Comments
 (0)