Skip to content

Commit bd7c296

Browse files
authored
Merge branch 'main' into appdocs
2 parents 0706f0c + aba5cb8 commit bd7c296

39 files changed

+4508
-3711
lines changed

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

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,65 @@
11
name: "Setup Go"
22
description: |
33
Sets up the Go environment for tests, builds, etc.
4+
inputs:
5+
version:
6+
description: "The Go version to use."
7+
default: "1.20.5"
48
runs:
59
using: "composite"
610
steps:
11+
- name: Cache go toolchain
12+
uses: buildjet/cache@v3
13+
with:
14+
path: |
15+
${{ runner.tool_cache }}/go/${{ inputs.version }}
16+
key: gotoolchain-${{ runner.os }}-${{ inputs.version }}
17+
restore-keys: |
18+
gotoolchain-${{ runner.os }}-
19+
720
- uses: buildjet/setup-go@v4
821
with:
9-
cache: true
10-
go-version: "1.20.5"
22+
# We do our own caching for implementation clarity.
23+
cache: false
24+
go-version: ${{ inputs.version }}
25+
26+
- name: Get cache dirs
27+
shell: bash
28+
run: |
29+
set -x
30+
echo "GOMODCACHE=$(go env GOMODCACHE)" >> $GITHUB_ENV
31+
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_ENV
32+
33+
# We split up GOMODCACHE from GOCACHE because the latter must be invalidated
34+
# on code change, but the former can be kept.
35+
- name: Cache $GOMODCACHE
36+
uses: buildjet/cache@v3
37+
with:
38+
path: |
39+
${{ env.GOMODCACHE }}
40+
key: gomodcache-${{ runner.os }}-${{ hashFiles('**/go.sum') }}-${{ github.job }}
41+
restore-keys: |
42+
gomodcache-${{ runner.os }}-${{ hashFiles('**/go.sum') }}-
43+
gomodcache-${{ runner.os }}-
1144
12-
- name: Cache go
45+
- name: Cache $GOCACHE
1346
uses: buildjet/cache@v3
1447
with:
15-
# ~/go/pkg is the same across operating systems.
1648
path: |
17-
~/go/pkg
18-
~/.cache/go-build
19-
~/AppData/Local/go-build
20-
~/Library/Caches/go-build
49+
${{ env.GOCACHE }}
2150
# Job name must be included in the key for effective
2251
# test cache reuse.
23-
key: go-${{ runner.os }}-${{ github.job }}-${{ hashFiles('**/*.go', 'go.**') }}
52+
# The key format is intentionally different than GOMODCACHE, because any
53+
# time a Go file changes we invalidate this cache, whereas GOMODCACHE
54+
# is only invalidated when go.sum changes.
55+
key: gocache-${{ runner.os }}-${{ github.job }}-${{ hashFiles('**/*.go', 'go.**') }}
2456
restore-keys: |
25-
go-${{ runner.os }}-${{ github.job }}-
26-
go-${{ runner.os }}-
27-
go-
57+
gocache-${{ runner.os }}-${{ github.job }}-
58+
gocache-${{ runner.os }}-
2859
2960
- name: Install gotestsum
30-
uses: jaxxstorm/action-install-gh-release@v1.10.0
31-
with:
32-
repo: gotestyourself/gotestsum
33-
tag: v1.9.0
61+
shell: bash
62+
run: go install gotest.tools/gotestsum@latest
3463

3564
# It isn't necessary that we ever do this, but it helps
3665
# separate the "setup" from the "run" times.

.github/workflows/ci.yaml

Lines changed: 37 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -100,49 +100,45 @@ jobs:
100100

101101
- uses: ./.github/actions/setup-go
102102

103-
# Check for any typos!
103+
- uses: ./.github/actions/setup-node
104+
105+
- name: Get golangci-lint cache dir
106+
run: |
107+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.2
108+
dir=$(golangci-lint cache status | awk '/Dir/ { print $2 }')
109+
echo "LINT_CACHE_DIR=$dir" >> $GITHUB_ENV
110+
111+
- name: golangci-lint cache
112+
uses: buildjet/cache@v3
113+
with:
114+
path: |
115+
${{ env.LINT_CACHE_DIR }}
116+
key: golangci-lint-${{ runner.os }}-${{ hashFiles('**/*.go') }}
117+
restore-keys: |
118+
golangci-lint-${{ runner.os }}-
119+
120+
# Check for any typos
104121
- name: Check for typos
105122
uses: crate-ci/typos@v1.14.12
106123
with:
107124
config: .github/workflows/typos.toml
125+
108126
- name: Fix the typos
109127
if: ${{ failure() }}
110128
run: |
111129
echo "::notice:: you can automatically fix typos from your CLI:
112130
cargo install typos-cli
113131
typos -c .github/workflows/typos.toml -w"
114132
115-
# Check for Go linting errors!
116-
- name: Lint Go
117-
uses: golangci/golangci-lint-action@v3.5.0
118-
with:
119-
version: v1.52.2
120-
121-
- name: Lint shell scripts
122-
uses: ludeeus/action-shellcheck@2.0.0
123-
env:
124-
SHELLCHECK_OPTS: --external-sources
125-
with:
126-
ignore: node_modules
127-
128-
- uses: ./.github/actions/setup-node
129-
- name: Lint TypeScript
130-
run: yarn lint
131-
working-directory: site
132-
133-
# Make sure the Helm chart is linted!
133+
# Needed for helm chart linting
134134
- name: Install helm
135135
uses: azure/setup-helm@v3
136136
with:
137137
version: v3.9.2
138-
- name: Lint Helm chart
139-
run: |
140-
cd helm
141-
make lint
142138

143-
# Ensure AGPL and Enterprise are separated!
144-
- name: Check for AGPL code importing Enterprise...
145-
run: ./scripts/check_enterprise_imports.sh
139+
- name: make lint
140+
run: |
141+
make --output-sync=line -j lint
146142
147143
gen:
148144
timeout-minutes: 8
@@ -158,16 +154,14 @@ jobs:
158154
- name: Install sqlc
159155
run: |
160156
curl -sSL https://github.com/kyleconroy/sqlc/releases/download/v1.17.2/sqlc_1.17.2_linux_amd64.tar.gz | sudo tar -C /usr/bin -xz sqlc
161-
- name: Install protoc-gen-go
162-
run: go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.30
163-
- name: Install protoc-gen-go-drpc
164-
run: go install storj.io/drpc/cmd/protoc-gen-go-drpc@v0.0.33
165-
- name: Install goimports
166-
run: go install golang.org/x/tools/cmd/goimports@latest
167-
- name: Install yq
168-
run: go run github.com/mikefarah/yq/v4@v4.30.6
169-
- name: Install mockgen
170-
run: go install github.com/golang/mock/mockgen@v1.6.0
157+
158+
- name: go install tools
159+
run: |
160+
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.30
161+
go install storj.io/drpc/cmd/protoc-gen-go-drpc@v0.0.33
162+
go install golang.org/x/tools/cmd/goimports@latest
163+
go install github.com/mikefarah/yq/v4@v4.30.6
164+
go install github.com/golang/mock/mockgen@v1.6.0
171165
172166
- name: Install Protoc
173167
run: |
@@ -189,7 +183,7 @@ jobs:
189183
run: ./scripts/check_unstaged.sh
190184

191185
fmt:
192-
runs-on: ubuntu-latest
186+
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
193187
timeout-minutes: 5
194188
steps:
195189
- name: Checkout
@@ -250,11 +244,6 @@ jobs:
250244
# By default Go will use the number of logical CPUs, which
251245
# is a fine default.
252246
PARALLEL_FLAG=""
253-
if [ "${{ matrix.os }}" == "windows-2019" ]; then
254-
# Windows appears more I/O bound, so we increase parallelism
255-
# to make better use of CPU.
256-
PARALLEL_FLAG="-parallel=16"
257-
fi
258247
259248
export TS_DEBUG_DISCO=true
260249
gotestsum --junitfile="gotests.xml" --jsonfile="gotests.json" \
@@ -268,7 +257,7 @@ jobs:
268257
go run ./scripts/ci-report/main.go gotests.json | tee gotests_stats.json
269258
270259
- uses: ./.github/actions/upload-datadog
271-
if: always()
260+
if: success() || failure()
272261
with:
273262
api-key: ${{ secrets.DATADOG_API_KEY }}
274263

@@ -315,15 +304,8 @@ jobs:
315304
# so we need to print the test stats to the log.
316305
go run ./scripts/ci-report/main.go gotests.json | tee gotests_stats.json
317306
318-
- uses: actions/upload-artifact@v3
319-
if: success() || failure()
320-
with:
321-
name: gotests-postgres.xml
322-
path: ./gotests.xml
323-
retention-days: 30
324-
325307
- uses: ./.github/actions/upload-datadog
326-
if: always()
308+
if: success() || failure()
327309
with:
328310
api-key: ${{ secrets.DATADOG_API_KEY }}
329311

@@ -349,11 +331,6 @@ jobs:
349331

350332
- uses: ./.github/actions/setup-go
351333

352-
- uses: hashicorp/setup-terraform@v2
353-
with:
354-
terraform_version: 1.1.9
355-
terraform_wrapper: false
356-
357334
- name: Run Tests
358335
run: |
359336
gotestsum --junitfile="gotests.xml" -- -race ./...
@@ -565,14 +542,16 @@ jobs:
565542

566543
required:
567544
runs-on: ubuntu-latest
568-
needs: [gen, test-go, test-go-pg, test-go-race, test-js]
545+
needs: [fmt, lint, gen, test-go, test-go-pg, test-go-race, test-js]
569546
# Allow this job to run even if the needed jobs fail, are skipped or
570547
# cancelled.
571548
if: always()
572549
steps:
573550
- name: Ensure required checks
574551
run: |
575552
echo "Checking required checks"
553+
echo "- fmt: ${{ needs.fmt.result }}"
554+
echo "- lint: ${{ needs.lint.result }}"
576555
echo "- gen: ${{ needs.gen.result }}"
577556
echo "- test-go: ${{ needs.test-go.result }}"
578557
echo "- test-go-pg: ${{ needs.test-go-pg.result }}"

.github/workflows/security.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010

1111
schedule:
1212
# Run every 6 hours Monday-Friday!
13-
- cron: "0 0,6,12,18 * * 1-5"
13+
- cron: "0 0/6 * * 1-5"
1414

1515
# Cancel in-progress runs for pull requests when developers push
1616
# additional changes
@@ -117,8 +117,16 @@ jobs:
117117
make -j "$image_job"
118118
echo "image=$(cat "$image_job")" >> $GITHUB_OUTPUT
119119
120+
- name: Run Prisma Cloud image scan
121+
uses: PaloAltoNetworks/prisma-cloud-scan@v1
122+
with:
123+
pcc_console_url: ${{ secrets.PRISMA_CLOUD_URL }}
124+
pcc_user: ${{ secrets.PRISMA_CLOUD_ACCESS_KEY }}
125+
pcc_pass: ${{ secrets.PRISMA_CLOUD_SECRET_KEY }}
126+
image_name: ${{ steps.build.outputs.image }}
127+
120128
- name: Run Trivy vulnerability scanner
121-
uses: aquasecurity/trivy-action@e5f43133f6e8736992c9f3c1b3296e24b37e17f2
129+
uses: aquasecurity/trivy-action@41f05d9ecffa2ed3f1580af306000f734b733e54
122130
with:
123131
image-ref: ${{ steps.build.outputs.image }}
124132
format: sarif

.golangci.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,11 @@ issues:
200200
max-same-issues: 0
201201

202202
run:
203-
concurrency: 4
204203
skip-dirs:
205204
- node_modules
206205
skip-files:
207206
- scripts/rules.go
208-
timeout: 5m
207+
timeout: 10m
209208

210209
# Over time, add more and more linters from
211210
# https://golangci-lint.run/usage/linters/ as the code improves.

Makefile

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ endif
5050
# Note, all find statements should be written with `.` or `./path` as
5151
# the search path so that these exclusions match.
5252
FIND_EXCLUSIONS= \
53-
-not \( \( -path '*/.git/*' -o -path './build/*' -o -path './vendor/*' -o -path './.coderv2/*' -o -path '*/node_modules/*' -o -path './site/out/*' \) -prune \)
53+
-not \( \( -path '*/.git/*' -o -path './build/*' -o -path './vendor/*' -o -path './.coderv2/*' -o -path '*/node_modules/*' -o -path './site/out/*' -o -path './coderd/apidoc/*' \) -prune \)
5454
# Source files used for make targets, evaluated on use.
5555
GO_SRC_FILES = $(shell find . $(FIND_EXCLUSIONS) -type f -name '*.go')
5656
# All the shell files in the repo, excluding ignored files.
@@ -402,11 +402,17 @@ else
402402
endif
403403
.PHONY: fmt/shfmt
404404

405-
lint: lint/shellcheck lint/go
405+
lint: lint/shellcheck lint/go lint/ts lint/helm
406406
.PHONY: lint
407407

408+
lint/ts:
409+
cd site
410+
yarn && yarn lint
411+
.PHONY: lint/ts
412+
408413
lint/go:
409414
./scripts/check_enterprise_imports.sh
415+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.2
410416
golangci-lint run
411417
.PHONY: lint/go
412418

@@ -416,6 +422,11 @@ lint/shellcheck: $(SHELL_SRC_FILES)
416422
shellcheck --external-sources $(SHELL_SRC_FILES)
417423
.PHONY: lint/shellcheck
418424

425+
lint/helm:
426+
cd helm
427+
make lint
428+
.PHONY: lint/helm
429+
419430
# all gen targets should be added here and to gen/mark-fresh
420431
gen: \
421432
coderd/database/dump.sql \
@@ -475,7 +486,7 @@ coderd/database/dump.sql: coderd/database/gen/dump/main.go $(wildcard coderd/dat
475486
go run ./coderd/database/gen/dump/main.go
476487

477488
# Generates Go code for querying the database.
478-
coderd/database/querier.go: coderd/database/sqlc.yaml coderd/database/dump.sql $(wildcard coderd/database/queries/*.sql) coderd/database/gen/enum/main.go
489+
coderd/database/querier.go: coderd/database/sqlc.yaml coderd/database/dump.sql $(wildcard coderd/database/queries/*.sql) coderd/database/gen/enum/main.go coderd/database/gen/fake/main.go
479490
./coderd/database/generate.sh
480491

481492

@@ -511,7 +522,7 @@ docs/admin/prometheus.md: scripts/metricsdocgen/main.go scripts/metricsdocgen/me
511522
cd site
512523
yarn run format:write:only ../docs/admin/prometheus.md
513524

514-
docs/cli.md: scripts/clidocgen/main.go $(GO_SRC_FILES) docs/manifest.json
525+
docs/cli.md: scripts/clidocgen/main.go $(GO_SRC_FILES)
515526
BASE_PATH="." go run ./scripts/clidocgen
516527
cd site
517528
yarn run format:write:only ../docs/cli.md ../docs/cli/*.md ../docs/manifest.json

cli/ssh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (r *RootCmd) ssh() *clibase.Cmd {
110110
}
111111
go func() {
112112
wg.Wait()
113-
logFile.Close()
113+
_ = logFile.Close()
114114
}()
115115

116116
logger = slog.Make(sloghuman.Sink(logFile))

cli/templateversions.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,12 @@ func templateVersionsToRows(activeVersionID uuid.UUID, templateVersions ...coder
105105
}
106106

107107
rows[i] = templateVersionRow{
108-
Name: templateVersion.Name,
109-
CreatedAt: templateVersion.CreatedAt,
110-
CreatedBy: templateVersion.CreatedBy.Username,
111-
Status: strings.Title(string(templateVersion.Job.Status)),
112-
Active: activeStatus,
108+
TemplateVersion: templateVersion,
109+
Name: templateVersion.Name,
110+
CreatedAt: templateVersion.CreatedAt,
111+
CreatedBy: templateVersion.CreatedBy.Username,
112+
Status: strings.Title(string(templateVersion.Job.Status)),
113+
Active: activeStatus,
113114
}
114115
}
115116

coderd/apidoc/docs.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)