Skip to content

Commit 42dcab5

Browse files
committed
Merge branch 'main' of github.com:coder/coder into spike/3125_ssh_tty_exit_code
2 parents 713a496 + 9bf5537 commit 42dcab5

File tree

104 files changed

+2214
-618
lines changed

Some content is hidden

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

104 files changed

+2214
-618
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ trim_trailing_whitespace = true
77
insert_final_newline = true
88
indent_style = tab
99

10-
[*.{md,json,yaml,tf,tfvars}]
10+
[*.{md,json,yaml,yml,tf,tfvars}]
1111
indent_style = space
1212
indent_size = 2
1313

.github/codecov.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ ignore:
3434
- scripts
3535
- site/.storybook
3636
- rules.go
37+
# Packages used for writing tests.
38+
- cli/clitest
39+
- coderd/coderdtest
40+
- pty/ptytest

.github/workflows/coder.yaml

Lines changed: 124 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ on:
66
- main
77
tags:
88
- "*"
9-
paths-ignore:
10-
- "docs/**"
119

1210
pull_request:
1311

@@ -32,9 +30,68 @@ concurrency:
3230
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
3331

3432
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+
3590
style-lint-golangci:
3691
name: style/lint/golangci
3792
timeout-minutes: 5
93+
needs: changes
94+
if: needs.changes.outputs.go == 'true'
3895
runs-on: ubuntu-latest
3996
steps:
4097
- uses: actions/checkout@v3
@@ -50,6 +107,8 @@ jobs:
50107
name: style/lint/shellcheck
51108
timeout-minutes: 5
52109
runs-on: ubuntu-latest
110+
needs: changes
111+
if: needs.changes.outputs.sh == 'true'
53112
steps:
54113
- uses: actions/checkout@v3
55114
- name: Run ShellCheck
@@ -62,6 +121,8 @@ jobs:
62121
style-lint-typescript:
63122
name: "style/lint/typescript"
64123
timeout-minutes: 5
124+
needs: changes
125+
if: needs.changes.outputs.docs-only == 'false'
65126
runs-on: ubuntu-latest
66127
steps:
67128
- name: Checkout
@@ -87,8 +148,10 @@ jobs:
87148

88149
gen:
89150
name: "style/gen"
90-
timeout-minutes: 5
151+
timeout-minutes: 8
91152
runs-on: ubuntu-latest
153+
needs: changes
154+
if: needs.changes.outputs.docs-only == 'false'
92155
steps:
93156
- uses: actions/checkout@v3
94157

@@ -113,6 +176,25 @@ jobs:
113176
- uses: actions/setup-go@v3
114177
with:
115178
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+
116198
- run: |
117199
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
118200
@@ -124,6 +206,8 @@ jobs:
124206

125207
style-fmt:
126208
name: "style/fmt"
209+
needs: changes
210+
if: needs.changes.outputs.docs-only == 'false'
127211
runs-on: ubuntu-latest
128212
timeout-minutes: 5
129213
steps:
@@ -156,6 +240,8 @@ jobs:
156240
157241
test-go:
158242
name: "test/go"
243+
needs: changes
244+
if: needs.changes.outputs.docs-only == 'false'
159245
runs-on: ${{ matrix.os }}
160246
timeout-minutes: 20
161247
strategy:
@@ -181,7 +267,7 @@ jobs:
181267
uses: actions/cache@v3
182268
with:
183269
path: ${{ steps.go-cache-paths.outputs.go-build }}
184-
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
270+
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.**', '**.go') }}
185271

186272
- name: Go Mod Cache
187273
uses: actions/cache@v3
@@ -203,14 +289,23 @@ jobs:
203289
terraform_wrapper: false
204290

205291
- name: Test with Mock Database
292+
id: test
206293
shell: bash
207-
run: gotestsum --junitfile="gotests.xml" --packages="./..." --
208-
-covermode=atomic -coverprofile="gotests.coverage"
209-
-coverpkg=./...,github.com/coder/coder/codersdk
210-
-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
211306
212307
- name: Upload DataDog Trace
213-
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
214309
env:
215310
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}
216311
DD_DATABASE: fake
@@ -224,14 +319,20 @@ jobs:
224319
# that is no guarantee, see:
225320
# https://github.com/codecov/codecov-action/issues/788
226321
continue-on-error: true
227-
if: github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
322+
if: steps.test.outputs.cover && github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
228323
with:
229324
token: ${{ secrets.CODECOV_TOKEN }}
230325
files: ./gotests.coverage
231326
flags: unittest-go-${{ matrix.os }}
232327

233328
test-go-postgres:
234329
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')
235336
runs-on: ubuntu-latest
236337
# This timeout must be greater than the timeout set by `go test` in
237338
# `make test-postgres` to ensure we receive a trace of running
@@ -255,7 +356,7 @@ jobs:
255356
uses: actions/cache@v3
256357
with:
257358
path: ${{ steps.go-cache-paths.outputs.go-build }}
258-
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
359+
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum', '**/**.go') }}
259360

260361
- name: Go Mod Cache
261362
uses: actions/cache@v3
@@ -303,7 +404,10 @@ jobs:
303404
name: "deploy"
304405
runs-on: ubuntu-latest
305406
timeout-minutes: 30
306-
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'
307411
permissions:
308412
contents: read
309413
id-token: write
@@ -409,6 +513,8 @@ jobs:
409513

410514
test-js:
411515
name: "test/js"
516+
needs: changes
517+
if: needs.changes.outputs.docs-only == 'false'
412518
runs-on: ubuntu-latest
413519
timeout-minutes: 20
414520
steps:
@@ -462,6 +568,10 @@ jobs:
462568

463569
test-e2e:
464570
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')
465575
runs-on: ${{ matrix.os }}
466576
timeout-minutes: 20
467577
strategy:
@@ -478,9 +588,7 @@ jobs:
478588
path: |
479589
**/node_modules
480590
.eslintcache
481-
key: js-${{ runner.os }}-test-${{ hashFiles('**/yarn.lock') }}
482-
restore-keys: |
483-
js-${{ runner.os }}-
591+
key: js-${{ runner.os }}-e2e-${{ hashFiles('**/yarn.lock') }}
484592

485593
# Go is required for uploading the test results to datadog
486594
- uses: actions/setup-go@v3
@@ -516,6 +624,7 @@ jobs:
516624

517625
- name: Build
518626
run: |
627+
sudo npm install -g prettier
519628
make -B site/out/index.html
520629
521630
- 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+
}

.github/workflows/prcontext/parse.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"regexp"
5+
"strings"
6+
)
7+
8+
const ciSkipPrefix = "ci-skip"
9+
10+
var skipDirective = regexp.MustCompile(`\[` + ciSkipPrefix + ` ([\w-\/ ]+)]`)
11+
12+
func parseBody(body string) (skips []string) {
13+
matches := skipDirective.FindAllStringSubmatch(body, -1)
14+
// flog.Info("matches: %+v", matches)
15+
16+
var skipMatches []string
17+
for i := range matches {
18+
for j := range matches[i] {
19+
v := matches[i][j]
20+
// flog.Info("%q", v)
21+
if !strings.Contains(v, ciSkipPrefix) {
22+
skipMatches = append(skipMatches, strings.Split(v, " ")...)
23+
}
24+
}
25+
}
26+
27+
return skipMatches
28+
}

0 commit comments

Comments
 (0)