Skip to content

Commit cfd9f52

Browse files
authored
Merge branch 'main' into mafredri/coverage-updates
2 parents db39e46 + 5312296 commit cfd9f52

File tree

342 files changed

+9856
-3744
lines changed

Some content is hidden

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

342 files changed

+9856
-3744
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
site/ @coder/frontend
2+
docs/ @ammario

.github/stale.yaml

Lines changed: 0 additions & 12 deletions
This file was deleted.

.github/workflows/coder.yaml

Lines changed: 146 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,68 @@ concurrency:
3030
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
3131

3232
jobs:
33+
changes:
34+
runs-on: ubuntu-latest
35+
outputs:
36+
docs-only: ${{ steps.filter.outputs.docs_count == steps.filter.outputs.all_count }}
37+
go: ${{ steps.filter.outputs.go }}
38+
sh: ${{ steps.filter.outputs.sh }}
39+
steps:
40+
- uses: actions/checkout@v3
41+
# For pull requests it's not necessary to checkout the code
42+
- uses: dorny/paths-filter@v2
43+
id: filter
44+
with:
45+
filters: |
46+
all:
47+
- '**'
48+
docs:
49+
- 'docs/**'
50+
# For testing:
51+
# - '.github/**'
52+
go:
53+
- "**.go"
54+
- "**.mod"
55+
- "**.sum"
56+
sh:
57+
- "**.sh"
58+
- id: debug
59+
run: |
60+
echo "${{ toJSON(steps.filter )}}"
61+
62+
# Debug step
63+
debug-inputs:
64+
needs:
65+
- changes
66+
- pr-context
67+
runs-on: ubuntu-latest
68+
steps:
69+
- id: log
70+
run: |
71+
echo "${{ toJSON(needs) }}"
72+
echo "${{ contains(needs.pr-context.outputs.skips, 'test/go/postgres') }} "
73+
echo "${{ contains(needs.pr-context.outputs.skips, 'test/e2e') }} "
74+
75+
pr-context:
76+
runs-on: ubuntu-latest
77+
outputs:
78+
skips: ${{ steps.pr-context.outputs.skips }}
79+
steps:
80+
- uses: actions/checkout@v3
81+
- uses: actions/setup-go@v3
82+
with:
83+
go-version: "~1.18"
84+
- id: pr-context
85+
env:
86+
GITHUB_CONTEXT: ${{ toJSON(github) }}
87+
run: |
88+
go run github.com/coder/coder/.github/workflows/prcontext
89+
3390
style-lint-golangci:
3491
name: style/lint/golangci
3592
timeout-minutes: 5
93+
needs: changes
94+
if: needs.changes.outputs.go == 'true'
3695
runs-on: ubuntu-latest
3796
steps:
3897
- uses: actions/checkout@v3
@@ -48,6 +107,8 @@ jobs:
48107
name: style/lint/shellcheck
49108
timeout-minutes: 5
50109
runs-on: ubuntu-latest
110+
needs: changes
111+
if: needs.changes.outputs.sh == 'true'
51112
steps:
52113
- uses: actions/checkout@v3
53114
- name: Run ShellCheck
@@ -60,6 +121,8 @@ jobs:
60121
style-lint-typescript:
61122
name: "style/lint/typescript"
62123
timeout-minutes: 5
124+
needs: changes
125+
if: needs.changes.outputs.docs-only == 'false'
63126
runs-on: ubuntu-latest
64127
steps:
65128
- name: Checkout
@@ -87,6 +150,8 @@ jobs:
87150
name: "style/gen"
88151
timeout-minutes: 5
89152
runs-on: ubuntu-latest
153+
needs: changes
154+
if: needs.changes.outputs.docs-only == 'false'
90155
steps:
91156
- uses: actions/checkout@v3
92157

@@ -111,6 +176,25 @@ jobs:
111176
- uses: actions/setup-go@v3
112177
with:
113178
go-version: "~1.18"
179+
180+
- name: Echo Go Cache Paths
181+
id: go-cache-paths
182+
run: |
183+
echo "::set-output name=go-build::$(go env GOCACHE)"
184+
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
185+
186+
- name: Go Build Cache
187+
uses: actions/cache@v3
188+
with:
189+
path: ${{ steps.go-cache-paths.outputs.go-build }}
190+
key: ${{ github.job }}-go-build-${{ hashFiles('**/go.sum', '**/**.go') }}
191+
192+
- name: Go Mod Cache
193+
uses: actions/cache@v3
194+
with:
195+
path: ${{ steps.go-cache-paths.outputs.go-mod }}
196+
key: ${{ github.job }}-go-mod-${{ hashFiles('**/go.sum') }}
197+
114198
- run: |
115199
curl -sSL https://github.com/kyleconroy/sqlc/releases/download/v1.13.0/sqlc_1.13.0_linux_amd64.tar.gz | sudo tar -C /usr/bin -xz sqlc
116200
@@ -122,6 +206,8 @@ jobs:
122206

123207
style-fmt:
124208
name: "style/fmt"
209+
needs: changes
210+
if: needs.changes.outputs.docs-only == 'false'
125211
runs-on: ubuntu-latest
126212
timeout-minutes: 5
127213
steps:
@@ -154,6 +240,8 @@ jobs:
154240
155241
test-go:
156242
name: "test/go"
243+
needs: changes
244+
if: needs.changes.outputs.docs-only == 'false'
157245
runs-on: ${{ matrix.os }}
158246
timeout-minutes: 20
159247
strategy:
@@ -179,7 +267,7 @@ jobs:
179267
uses: actions/cache@v3
180268
with:
181269
path: ${{ steps.go-cache-paths.outputs.go-build }}
182-
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
270+
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.**', '**.go') }}
183271

184272
- name: Go Mod Cache
185273
uses: actions/cache@v3
@@ -201,14 +289,23 @@ jobs:
201289
terraform_wrapper: false
202290

203291
- name: Test with Mock Database
292+
id: test
204293
shell: bash
205-
run: gotestsum --junitfile="gotests.xml" --packages="./..." --
206-
-covermode=atomic -coverprofile="gotests.coverage"
207-
-coverpkg=./...
208-
-timeout=5m -short -failfast
294+
run: |
295+
# Code coverage is more computationally expensive and also
296+
# prevents test caching, so we disable it on alternate operating
297+
# systems.
298+
if [ "${{ matrix.os }}" == "ubuntu-latest" ]; then
299+
echo ::set-output name=cover::true
300+
export COVERAGE_FLAGS='-covermode=atomic -coverprofile="gotests.coverage" -coverpkg=./...'
301+
else
302+
echo ::set-output name=cover::false
303+
fi
304+
set -x
305+
gotestsum --junitfile="gotests.xml" --packages="./..." -- -parallel=8 -timeout=5m -short -failfast $COVERAGE_FLAGS
209306
210307
- name: Upload DataDog Trace
211-
if: always() && github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
308+
if: github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
212309
env:
213310
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}
214311
DD_DATABASE: fake
@@ -217,18 +314,31 @@ jobs:
217314
run: go run scripts/datadog-cireport/main.go gotests.xml
218315

219316
- uses: codecov/codecov-action@v3
220-
if: github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
317+
# This action has a tendency to error out unexpectedly, it has
318+
# the `fail_ci_if_error` option that defaults to `false`, but
319+
# that is no guarantee, see:
320+
# https://github.com/codecov/codecov-action/issues/788
321+
continue-on-error: true
322+
if: steps.test.outputs.cover && github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
221323
with:
222324
token: ${{ secrets.CODECOV_TOKEN }}
223325
files: ./gotests.coverage
224326
flags: unittest-go-${{ matrix.os }}
225-
# this flakes and sometimes fails the build
226-
fail_ci_if_error: false
227327

228328
test-go-postgres:
229329
name: "test/go/postgres"
330+
needs:
331+
- changes
332+
- pr-context
333+
if: >
334+
needs.changes.outputs.docs-only == 'false' &&
335+
!contains(needs.pr-context.outputs.skips, 'test/go/postgres')
230336
runs-on: ubuntu-latest
231-
timeout-minutes: 20
337+
# This timeout must be greater than the timeout set by `go test` in
338+
# `make test-postgres` to ensure we receive a trace of running
339+
# goroutines. Setting this to the timeout +5m should work quite well
340+
# even if some of the preceding steps are slow.
341+
timeout-minutes: 25
232342
steps:
233343
- uses: actions/checkout@v3
234344

@@ -246,7 +356,7 @@ jobs:
246356
uses: actions/cache@v3
247357
with:
248358
path: ${{ steps.go-cache-paths.outputs.go-build }}
249-
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
359+
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum', '**/**.go') }}
250360

251361
- name: Go Mod Cache
252362
uses: actions/cache@v3
@@ -279,19 +389,25 @@ jobs:
279389
run: go run scripts/datadog-cireport/main.go gotests.xml
280390

281391
- uses: codecov/codecov-action@v3
392+
# This action has a tendency to error out unexpectedly, it has
393+
# the `fail_ci_if_error` option that defaults to `false`, but
394+
# that is no guarantee, see:
395+
# https://github.com/codecov/codecov-action/issues/788
396+
continue-on-error: true
282397
if: github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
283398
with:
284399
token: ${{ secrets.CODECOV_TOKEN }}
285400
files: ./gotests.coverage
286401
flags: unittest-go-postgres-${{ matrix.os }}
287-
# this flakes and sometimes fails the build
288-
fail_ci_if_error: false
289402

290403
deploy:
291404
name: "deploy"
292405
runs-on: ubuntu-latest
293406
timeout-minutes: 30
294-
if: github.ref == 'refs/heads/main' && !github.event.pull_request.head.repo.fork
407+
needs: changes
408+
if: |
409+
github.ref == 'refs/heads/main' && !github.event.pull_request.head.repo.fork
410+
&& needs.changes.outputs.docs-only == 'false'
295411
permissions:
296412
contents: read
297413
id-token: write
@@ -369,7 +485,8 @@ jobs:
369485
./scripts/build_go_matrix.sh \
370486
--output ./dist/ \
371487
--package-linux \
372-
linux:amd64
488+
linux:amd64 \
489+
windows:amd64
373490
374491
- name: Install Release
375492
run: |
@@ -387,6 +504,7 @@ jobs:
387504
name: coder
388505
path: |
389506
./dist/*.zip
507+
./dist/*.exe
390508
./dist/*.tar.gz
391509
./dist/*.apk
392510
./dist/*.deb
@@ -395,6 +513,8 @@ jobs:
395513

396514
test-js:
397515
name: "test/js"
516+
needs: changes
517+
if: needs.changes.outputs.docs-only == 'false'
398518
runs-on: ubuntu-latest
399519
timeout-minutes: 20
400520
steps:
@@ -427,13 +547,16 @@ jobs:
427547
working-directory: site
428548

429549
- uses: codecov/codecov-action@v3
550+
# This action has a tendency to error out unexpectedly, it has
551+
# the `fail_ci_if_error` option that defaults to `false`, but
552+
# that is no guarantee, see:
553+
# https://github.com/codecov/codecov-action/issues/788
554+
continue-on-error: true
430555
if: github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
431556
with:
432557
token: ${{ secrets.CODECOV_TOKEN }}
433558
files: ./site/coverage/lcov.info
434559
flags: unittest-js
435-
# this flakes and sometimes fails the build
436-
fail_ci_if_error: false
437560

438561
- name: Upload DataDog Trace
439562
if: always() && github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
@@ -445,6 +568,10 @@ jobs:
445568

446569
test-e2e:
447570
name: "test/e2e/${{ matrix.os }}"
571+
needs:
572+
- changes
573+
- pr-context
574+
if: needs.changes.outputs.docs-only == 'false' && !contains(needs.pr-context.outputs.skips, 'test/e2e')
448575
runs-on: ${{ matrix.os }}
449576
timeout-minutes: 20
450577
strategy:
@@ -461,9 +588,7 @@ jobs:
461588
path: |
462589
**/node_modules
463590
.eslintcache
464-
key: js-${{ runner.os }}-test-${{ hashFiles('**/yarn.lock') }}
465-
restore-keys: |
466-
js-${{ runner.os }}-
591+
key: js-${{ runner.os }}-e2e-${{ hashFiles('**/yarn.lock') }}
467592

468593
# Go is required for uploading the test results to datadog
469594
- uses: actions/setup-go@v3
@@ -499,6 +624,7 @@ jobs:
499624

500625
- name: Build
501626
run: |
627+
sudo npm install -g prettier
502628
make -B site/out/index.html
503629
504630
- run: yarn playwright:install

.github/workflows/prcontext/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# prcontext
2+
3+
`prcontext` is a simple Go program that extracts CI directives from PRs for a
4+
more efficient merge cycle.
5+
6+
Right now it only supports the `[ci-skip [job ...]]` directive. Since skips are
7+
only possible within PRs, the full suite will still run on merge.

.github/workflows/prcontext/main.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"os"
7+
"strings"
8+
9+
"github.com/coder/flog"
10+
)
11+
12+
// githubContext is structured as documented here:
13+
// https://docs.github.com/en/actions/learn-github-actions/contexts#github-context.
14+
type githubContext struct {
15+
EventName string `json:"event_name"`
16+
Event struct {
17+
PullRequest struct {
18+
Body string `json:"body"`
19+
} `json:"pull_request"`
20+
} `json:"event"`
21+
}
22+
23+
func main() {
24+
var c githubContext
25+
err := json.Unmarshal([]byte(os.Getenv("GITHUB_CONTEXT")), &c)
26+
if err != nil {
27+
flog.Fatal("decode stdin: %+v", err)
28+
}
29+
flog.Info("detected event %q", c.EventName)
30+
if c.EventName != "pull_request" {
31+
flog.Info("aborting since not Pull Request")
32+
return
33+
}
34+
35+
_, _ = fmt.Printf("::group::{PR Body}\n%s\n::endgroup::\n", c.Event.PullRequest.Body)
36+
37+
skips := parseBody(c.Event.PullRequest.Body)
38+
_, _ = fmt.Printf("::echo::on\n::set-output name=skips::[%s]\n", strings.Join(skips, " "))
39+
}

0 commit comments

Comments
 (0)