Skip to content

Commit 656490b

Browse files
authored
Merge branch 'main' into mafredri/fix-coderd-metadata-test
2 parents 78f9bb6 + 5de1084 commit 656490b

File tree

62 files changed

+1401
-486
lines changed

Some content is hidden

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

62 files changed

+1401
-486
lines changed

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

+24
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,32 @@ runs:
88
with:
99
cache: true
1010
go-version: "1.20.5"
11+
12+
- name: Cache go
13+
uses: buildjet/cache@v3
14+
with:
15+
# ~/go/pkg is the same across operating systems.
16+
path: |
17+
~/go/pkg
18+
~/.cache/go-build
19+
~/AppData/Local/go-build
20+
~/Library/Caches/go-build
21+
# Job name must be included in the key for effective
22+
# test cache reuse.
23+
key: go-${{ runner.os }}-${{ github.job }}-${{ hashFiles('**/*.go', 'go.**') }}
24+
restore-keys: |
25+
go-${{ runner.os }}-${{ github.job }}-
26+
go-${{ runner.os }}-
27+
go-
28+
1129
- name: Install gotestsum
1230
uses: jaxxstorm/action-install-gh-release@v1.10.0
1331
with:
1432
repo: gotestyourself/gotestsum
1533
tag: v1.9.0
34+
35+
# It isn't necessary that we ever do this, but it helps
36+
# separate the "setup" from the "run" times.
37+
- name: go mod download
38+
shell: bash
39+
run: go mod download -x

.github/workflows/ci.yaml

+116-64
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,71 @@ concurrency:
2727
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
2828

2929
jobs:
30+
changes:
31+
runs-on: ubuntu-latest
32+
outputs:
33+
docs-only: ${{ steps.filter.outputs.docs_count == steps.filter.outputs.all_count }}
34+
go: ${{ steps.filter.outputs.go }}
35+
ts: ${{ steps.filter.outputs.ts }}
36+
k8s: ${{ steps.filter.outputs.k8s }}
37+
ci: ${{ steps.filter.outputs.ci }}
38+
steps:
39+
- uses: actions/checkout@v3
40+
# For pull requests it's not necessary to checkout the code
41+
- uses: dorny/paths-filter@v2
42+
id: filter
43+
with:
44+
filters: |
45+
all:
46+
- "**"
47+
docs:
48+
- "docs/**"
49+
- "README.md"
50+
# For testing:
51+
# - ".github/**"
52+
go:
53+
- "**.sql"
54+
- "**.go"
55+
- "**.golden"
56+
- "go.mod"
57+
- "go.sum"
58+
# Other non-Go files that may affect Go code:
59+
- "**.rego"
60+
- "**.sh"
61+
- "**.tpl"
62+
- "**.gotmpl"
63+
- "**.gotpl"
64+
- "Makefile"
65+
- "site/static/error.html"
66+
# Main repo directories for completeness in case other files are
67+
# touched:
68+
- "agent/**"
69+
- "cli/**"
70+
- "cmd/**"
71+
- "coderd/**"
72+
- "enterprise/**"
73+
- "examples/**"
74+
- "provisioner/**"
75+
- "provisionerd/**"
76+
- "provisionersdk/**"
77+
- "pty/**"
78+
- "scaletest/**"
79+
- "tailnet/**"
80+
- "testutil/**"
81+
ts:
82+
- "site/**"
83+
- "Makefile"
84+
k8s:
85+
- "helm/**"
86+
- "scripts/Dockerfile"
87+
- "scripts/Dockerfile.base"
88+
- "scripts/helm.sh"
89+
ci:
90+
- ".github/**"
91+
- id: debug
92+
run: |
93+
echo "${{ toJSON(steps.filter )}}"
94+
3095
lint:
3196
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
3297
steps:
@@ -79,44 +144,11 @@ jobs:
79144
- name: Check for AGPL code importing Enterprise...
80145
run: ./scripts/check_enterprise_imports.sh
81146

82-
changes:
83-
runs-on: ubuntu-latest
84-
outputs:
85-
docs-only: ${{ steps.filter.outputs.docs_count == steps.filter.outputs.all_count }}
86-
sh: ${{ steps.filter.outputs.sh }}
87-
ts: ${{ steps.filter.outputs.ts }}
88-
k8s: ${{ steps.filter.outputs.k8s }}
89-
steps:
90-
- uses: actions/checkout@v3
91-
# For pull requests it's not necessary to checkout the code
92-
- uses: dorny/paths-filter@v2
93-
id: filter
94-
with:
95-
filters: |
96-
all:
97-
- '**'
98-
docs:
99-
- 'docs/**'
100-
# For testing:
101-
# - '.github/**'
102-
sh:
103-
- "**.sh"
104-
ts:
105-
- 'site/**'
106-
k8s:
107-
- 'helm/**'
108-
- scripts/Dockerfile
109-
- scripts/Dockerfile.base
110-
- scripts/helm.sh
111-
- id: debug
112-
run: |
113-
echo "${{ toJSON(steps.filter )}}"
114-
115147
gen:
116148
timeout-minutes: 8
117149
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
118150
needs: changes
119-
if: needs.changes.outputs.docs-only == 'false'
151+
if: needs.changes.outputs.docs-only == 'false' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
120152
steps:
121153
- uses: actions/checkout@v3
122154

@@ -181,7 +213,9 @@ jobs:
181213
run: ./scripts/check_unstaged.sh
182214

183215
test-go:
184-
runs-on: ${{ matrix.os == 'ubuntu-latest' && github.repository_owner == 'coder' && 'buildjet-4vcpu-ubuntu-2204' || matrix.os == 'windows-2019' && github.repository_owner == 'coder' && 'windows-latest-8-cores'|| matrix.os }}
216+
runs-on: ${{ matrix.os == 'ubuntu-latest' && github.repository_owner == 'coder' && 'buildjet-4vcpu-ubuntu-2204' || matrix.os == 'macos-latest' && github.repository_owner == 'coder' && 'macos-latest-xl' || matrix.os == 'windows-2019' && github.repository_owner == 'coder' && 'windows-latest-8-cores' || matrix.os }}
217+
needs: changes
218+
if: needs.changes.outputs.go == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
185219
timeout-minutes: 20
186220
strategy:
187221
matrix:
@@ -192,11 +226,6 @@ jobs:
192226
steps:
193227
- uses: actions/checkout@v3
194228

195-
- uses: buildjet/setup-go@v4
196-
with:
197-
cache: false
198-
go-version: ${{ env.CODER_GO_VERSION }}
199-
200229
- uses: ./.github/actions/setup-go
201230

202231
- uses: hashicorp/setup-terraform@v2
@@ -218,8 +247,18 @@ jobs:
218247
echo "cover=false" >> $GITHUB_OUTPUT
219248
fi
220249
250+
# By default Go will use the number of logical CPUs, which
251+
# is a fine default.
252+
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
258+
221259
export TS_DEBUG_DISCO=true
222-
gotestsum --junitfile="gotests.xml" --jsonfile="gotests.json" --packages="./..." -- -parallel=8 -timeout=7m -short -failfast $COVERAGE_FLAGS
260+
gotestsum --junitfile="gotests.xml" --jsonfile="gotests.json" \
261+
--packages="./..." -- $PARALLEL_FLAG -short -failfast $COVERAGE_FLAGS
223262
224263
- name: Print test stats
225264
if: success() || failure()
@@ -228,13 +267,6 @@ jobs:
228267
# so we need to print the test stats to the log.
229268
go run ./scripts/ci-report/main.go gotests.json | tee gotests_stats.json
230269
231-
- uses: actions/upload-artifact@v3
232-
if: success() || failure()
233-
with:
234-
name: gotests-${{ matrix.os }}.xml
235-
path: ./gotests.xml
236-
retention-days: 30
237-
238270
- uses: ./.github/actions/upload-datadog
239271
if: always()
240272
with:
@@ -254,6 +286,8 @@ jobs:
254286

255287
test-go-pg:
256288
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
289+
needs: changes
290+
if: needs.changes.outputs.go == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
257291
# This timeout must be greater than the timeout set by `go test` in
258292
# `make test-postgres` to ensure we receive a trace of running
259293
# goroutines. Setting this to the timeout +5m should work quite well
@@ -307,6 +341,8 @@ jobs:
307341

308342
test-go-race:
309343
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
344+
needs: changes
345+
if: needs.changes.outputs.go == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
310346
timeout-minutes: 25
311347
steps:
312348
- uses: actions/checkout@v3
@@ -352,11 +388,6 @@ jobs:
352388
- name: Set up Google Cloud SDK
353389
uses: google-github-actions/setup-gcloud@v1
354390

355-
- uses: buildjet/setup-go@v4
356-
with:
357-
cache: false
358-
go-version: ${{ env.CODER_GO_VERSION }}
359-
360391
- uses: ./.github/actions/setup-go
361392
- uses: ./.github/actions/setup-node
362393

@@ -423,13 +454,15 @@ jobs:
423454

424455
test-js:
425456
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
457+
needs: changes
458+
if: needs.changes.outputs.ts == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
426459
timeout-minutes: 20
427460
steps:
428461
- uses: actions/checkout@v3
429462

430463
- uses: ./.github/actions/setup-node
431464

432-
- run: yarn test:ci --max-workers ${{ steps.cpu-cores.outputs.count }}
465+
- run: yarn test:ci --max-workers $(nproc)
433466
working-directory: site
434467

435468
- uses: codecov/codecov-action@v3
@@ -445,10 +478,9 @@ jobs:
445478
flags: unittest-js
446479

447480
test-e2e:
448-
needs:
449-
- changes
450-
if: needs.changes.outputs.docs-only == 'false'
451481
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
482+
needs: changes
483+
if: needs.changes.outputs.go == 'true' || needs.changes.outputs.ts == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
452484
timeout-minutes: 20
453485
steps:
454486
- uses: actions/checkout@v3
@@ -461,10 +493,6 @@ jobs:
461493
terraform_version: 1.1.9
462494
terraform_wrapper: false
463495

464-
- uses: buildjet/setup-node@v3
465-
with:
466-
node-version: "16.16.0"
467-
468496
- name: Build
469497
run: |
470498
sudo npm install -g prettier
@@ -489,9 +517,8 @@ jobs:
489517
chromatic:
490518
# REMARK: this is only used to build storybook and deploy it to Chromatic.
491519
runs-on: ubuntu-latest
492-
needs:
493-
- changes
494-
if: needs.changes.outputs.ts == 'true'
520+
needs: changes
521+
if: needs.changes.outputs.ts == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
495522
steps:
496523
- uses: actions/checkout@v3
497524
with:
@@ -535,3 +562,28 @@ jobs:
535562
buildScriptName: "storybook:build"
536563
projectToken: 695c25b6cb65
537564
workingDir: "./site"
565+
566+
required:
567+
runs-on: ubuntu-latest
568+
needs: [gen, test-go, test-go-pg, test-go-race, test-js]
569+
# Allow this job to run even if the needed jobs fail, are skipped or
570+
# cancelled.
571+
if: always()
572+
steps:
573+
- name: Ensure required checks
574+
run: |
575+
echo "Checking required checks"
576+
echo "- gen: ${{ needs.gen.result }}"
577+
echo "- test-go: ${{ needs.test-go.result }}"
578+
echo "- test-go-pg: ${{ needs.test-go-pg.result }}"
579+
echo "- test-go-race: ${{ needs.test-go-race.result }}"
580+
echo "- test-js: ${{ needs.test-js.result }}"
581+
echo
582+
583+
# We allow skipped jobs to pass, but not failed or cancelled jobs.
584+
if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" || "${{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
585+
echo "One of the required checks has failed or has been cancelled"
586+
exit 1
587+
fi
588+
589+
echo "Required checks have passed"

Makefile

+7-3
Original file line numberDiff line numberDiff line change
@@ -525,13 +525,17 @@ coderd/apidoc/swagger.json: $(shell find ./scripts/apidocgen $(FIND_EXCLUSIONS)
525525
./scripts/apidocgen/generate.sh
526526
yarn run --cwd=site format:write:only ../docs/api ../docs/manifest.json ../coderd/apidoc/swagger.json
527527

528-
update-golden-files: cli/testdata/.gen-golden helm/tests/testdata/.gen-golden scripts/ci-report/testdata/.gen-golden
528+
update-golden-files: cli/testdata/.gen-golden helm/tests/testdata/.gen-golden scripts/ci-report/testdata/.gen-golden enterprise/cli/testdata/.gen-golden
529529
.PHONY: update-golden-files
530530

531531
cli/testdata/.gen-golden: $(wildcard cli/testdata/*.golden) $(wildcard cli/*.tpl) $(GO_SRC_FILES)
532532
go test ./cli -run="Test(CommandHelp|ServerYAML)" -update
533533
touch "$@"
534534

535+
enterprise/cli/testdata/.gen-golden: $(wildcard enterprise/cli/testdata/*.golden) $(wildcard cli/*.tpl) $(GO_SRC_FILES)
536+
go test ./enterprise/cli -run="TestEnterpriseCommandHelp" -update
537+
touch "$@"
538+
535539
helm/tests/testdata/.gen-golden: $(wildcard helm/tests/testdata/*.yaml) $(wildcard helm/tests/testdata/*.golden) $(GO_SRC_FILES)
536540
go test ./helm/tests -run=TestUpdateGoldenFiles -update
537541
touch "$@"
@@ -606,15 +610,15 @@ test: test-clean
606610

607611
# When updating -timeout for this test, keep in sync with
608612
# test-go-postgres (.github/workflows/coder.yaml).
613+
# Do add coverage flags so that test caching works.
609614
test-postgres: test-clean test-postgres-docker
610615
# The postgres test is prone to failure, so we limit parallelism for
611616
# more consistent execution.
612617
DB=ci DB_FROM=$(shell go run scripts/migrate-ci/main.go) gotestsum \
613618
--junitfile="gotests.xml" \
614619
--jsonfile="gotests.json" \
615620
--packages="./..." -- \
616-
-covermode=atomic -coverprofile="gotests.coverage" -timeout=20m \
617-
-coverpkg=./... \
621+
-timeout=20m \
618622
-failfast
619623
.PHONY: test-postgres
620624

cli/clibase/cmd.go

+13
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,19 @@ func (inv *Invocation) Run() (err error) {
448448
panic(err)
449449
}
450450
}()
451+
// We close Stdin to prevent deadlocks, e.g. when the command
452+
// has ended but an io.Copy is still reading from Stdin.
453+
defer func() {
454+
if inv.Stdin == nil {
455+
return
456+
}
457+
rc, ok := inv.Stdin.(io.ReadCloser)
458+
if !ok {
459+
return
460+
}
461+
e := rc.Close()
462+
err = errors.Join(err, e)
463+
}()
451464
err = inv.run(&runState{
452465
allArgs: inv.Args,
453466
})

0 commit comments

Comments
 (0)