Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc91b3cc

Browse files
committed
Merge branch 'main' into ssh
2 parentsfb9fbb6 +13cef7d commitc91b3cc

39 files changed

+919
-674
lines changed

‎.github/workflows/coder-test-stability.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ on:
1414
workflow_dispatch:
1515
inputs:
1616
iterationCount:
17-
description:'Iteration Count'
17+
description:"Iteration Count"
1818
required:false
19-
default:'10'
19+
default:"10"
2020

2121
# Cancel in-progress runs for pull requests when developers push
2222
# additional changes, and serialize builds in branches.
@@ -43,7 +43,7 @@ jobs:
4343

4444
-uses:actions/setup-go@v2
4545
with:
46-
go-version:"^1.17"
46+
go-version:"~1.18"
4747

4848
-uses:actions/cache@v3
4949
with:

‎.github/workflows/coder.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
-name:golangci-lint
4545
uses:golangci/golangci-lint-action@v3.1.0
4646
with:
47-
version:v1.43.0
47+
version:v1.45.2
4848

4949
style-lint-typescript:
5050
name:"style/lint/typescript"
@@ -201,7 +201,7 @@ jobs:
201201

202202
-uses:actions/setup-go@v2
203203
with:
204-
go-version:"~1.17"
204+
go-version:"~1.18"
205205

206206
-name:Echo Go Cache Paths
207207
id:go-cache-paths
@@ -299,7 +299,7 @@ jobs:
299299

300300
-uses:actions/setup-go@v2
301301
with:
302-
go-version:"~1.17"
302+
go-version:"~1.18"
303303

304304
-name:Echo Go Cache Paths
305305
id:go-cache-paths
@@ -362,7 +362,7 @@ jobs:
362362
# Go is required for uploading the test results to datadog
363363
-uses:actions/setup-go@v2
364364
with:
365-
go-version:"~1.17"
365+
go-version:"~1.18"
366366

367367
-uses:actions/setup-node@v3
368368
with:

‎.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
fetch-depth:0
1313
-uses:actions/setup-go@v2
1414
with:
15-
go-version:"^1.17"
15+
go-version:"~1.18"
1616

1717
-name:Run GoReleaser
1818
uses:goreleaser/goreleaser-action@v2.9.1

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ node_modules
1313
vendor
1414
.eslintcache
1515
yarn-error.log
16+
.idea
1617

1718
# Front-end ignore
1819
.next/

‎.golangci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ linters-settings:
154154
-name:import-shadowing
155155
-name:increment-decrement
156156
-name:indent-error-flow
157-
-name:modifies-parameter
157+
#- name: modifies-parameter
158158
-name:modifies-value-receiver
159159
-name:package-comments
160160
-name:range
@@ -185,6 +185,8 @@ linters-settings:
185185
-i
186186
-db
187187
-t
188+
-id
189+
-wg
188190
# Optional list of variable declarations that should be ignored completely. (defaults to empty list)
189191
# Entries must be in the form of "<variable name> <type>" or "<variable name> *<type>" for
190192
# variables, or "const <name>" for constants.
@@ -193,6 +195,8 @@ linters-settings:
193195
-r *http.Request
194196
-t testing.T
195197
-t testing.TB
198+
-ok bool
199+
-wg sync.WaitGroup
196200

197201
issues:
198202
# Rules listed here: https://github.com/securego/gosec#available-rules

‎Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,7 @@ site/out:
8888
# Restores GITKEEP files!
8989
git checkout HEAD site/out
9090
.PHONY: site/out
91+
92+
lint:
93+
golangci-lint run
94+
.PHONY: lint

‎cli/cliflag/cliflag.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Package cliflag extends flagset with environment variable defaults.
2+
//
3+
// Usage:
4+
//
5+
// cliflag.String(root.Flags(), &address, "address", "a", "CODER_ADDRESS", "127.0.0.1:3000", "The address to serve the API and dashboard")
6+
//
7+
// Will produce the following usage docs:
8+
//
9+
// -a, --address string The address to serve the API and dashboard (uses $CODER_ADDRESS). (default "127.0.0.1:3000")
10+
//
11+
package cliflag
12+
13+
import (
14+
"fmt"
15+
"os"
16+
"strconv"
17+
18+
"github.com/spf13/pflag"
19+
)
20+
21+
// StringVarP sets a string flag on the given flag set.
22+
funcStringVarP(flagset*pflag.FlagSet,p*string,namestring,shorthandstring,envstring,defstring,usagestring) {
23+
v,ok:=os.LookupEnv(env)
24+
if!ok||v=="" {
25+
v=def
26+
}
27+
flagset.StringVarP(p,name,shorthand,v,fmtUsage(usage,env))
28+
}
29+
30+
// Uint8VarP sets a uint8 flag on the given flag set.
31+
funcUint8VarP(flagset*pflag.FlagSet,ptr*uint8,namestring,shorthandstring,envstring,defuint8,usagestring) {
32+
val,ok:=os.LookupEnv(env)
33+
if!ok||val=="" {
34+
flagset.Uint8VarP(ptr,name,shorthand,def,fmtUsage(usage,env))
35+
return
36+
}
37+
38+
vi64,err:=strconv.ParseUint(val,10,8)
39+
iferr!=nil {
40+
flagset.Uint8VarP(ptr,name,shorthand,def,fmtUsage(usage,env))
41+
return
42+
}
43+
44+
flagset.Uint8VarP(ptr,name,shorthand,uint8(vi64),fmtUsage(usage,env))
45+
}
46+
47+
// BoolVarP sets a bool flag on the given flag set.
48+
funcBoolVarP(flagset*pflag.FlagSet,ptr*bool,namestring,shorthandstring,envstring,defbool,usagestring) {
49+
val,ok:=os.LookupEnv(env)
50+
if!ok||val=="" {
51+
flagset.BoolVarP(ptr,name,shorthand,def,fmtUsage(usage,env))
52+
return
53+
}
54+
55+
valb,err:=strconv.ParseBool(val)
56+
iferr!=nil {
57+
flagset.BoolVarP(ptr,name,shorthand,def,fmtUsage(usage,env))
58+
return
59+
}
60+
61+
flagset.BoolVarP(ptr,name,shorthand,valb,fmtUsage(usage,env))
62+
}
63+
64+
funcfmtUsage(ustring,envstring)string {
65+
ifenv=="" {
66+
returnfmt.Sprintf("%s.",u)
67+
}
68+
69+
returnfmt.Sprintf("%s - consumes $%s.",u,env)
70+
}

‎cli/cliflag/cliflag_test.go

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
package cliflag_test
2+
3+
import (
4+
"fmt"
5+
"strconv"
6+
"testing"
7+
8+
"github.com/spf13/pflag"
9+
"github.com/stretchr/testify/require"
10+
11+
"github.com/coder/coder/cli/cliflag"
12+
"github.com/coder/coder/cryptorand"
13+
)
14+
15+
// Testcliflag cannot run in parallel because it uses t.Setenv.
16+
//nolint:paralleltest
17+
funcTestCliflag(t*testing.T) {
18+
t.Run("StringDefault",func(t*testing.T) {
19+
varptrstring
20+
flagset,name,shorthand,env,usage:=randomFlag()
21+
def,_:=cryptorand.String(10)
22+
23+
cliflag.StringVarP(flagset,&ptr,name,shorthand,env,def,usage)
24+
got,err:=flagset.GetString(name)
25+
require.NoError(t,err)
26+
require.Equal(t,def,got)
27+
require.Contains(t,flagset.FlagUsages(),usage)
28+
require.Contains(t,flagset.FlagUsages(),fmt.Sprintf(" - consumes $%s",env))
29+
})
30+
31+
t.Run("StringEnvVar",func(t*testing.T) {
32+
varptrstring
33+
flagset,name,shorthand,env,usage:=randomFlag()
34+
envValue,_:=cryptorand.String(10)
35+
t.Setenv(env,envValue)
36+
def,_:=cryptorand.String(10)
37+
38+
cliflag.StringVarP(flagset,&ptr,name,shorthand,env,def,usage)
39+
got,err:=flagset.GetString(name)
40+
require.NoError(t,err)
41+
require.Equal(t,envValue,got)
42+
})
43+
44+
t.Run("EmptyEnvVar",func(t*testing.T) {
45+
varptrstring
46+
flagset,name,shorthand,_,usage:=randomFlag()
47+
def,_:=cryptorand.String(10)
48+
49+
cliflag.StringVarP(flagset,&ptr,name,shorthand,"",def,usage)
50+
got,err:=flagset.GetString(name)
51+
require.NoError(t,err)
52+
require.Equal(t,def,got)
53+
require.Contains(t,flagset.FlagUsages(),usage)
54+
require.NotContains(t,flagset.FlagUsages()," - consumes")
55+
})
56+
57+
t.Run("IntDefault",func(t*testing.T) {
58+
varptruint8
59+
flagset,name,shorthand,env,usage:=randomFlag()
60+
def,_:=cryptorand.Int63n(10)
61+
62+
cliflag.Uint8VarP(flagset,&ptr,name,shorthand,env,uint8(def),usage)
63+
got,err:=flagset.GetUint8(name)
64+
require.NoError(t,err)
65+
require.Equal(t,uint8(def),got)
66+
require.Contains(t,flagset.FlagUsages(),usage)
67+
require.Contains(t,flagset.FlagUsages(),fmt.Sprintf(" - consumes $%s",env))
68+
})
69+
70+
t.Run("IntEnvVar",func(t*testing.T) {
71+
varptruint8
72+
flagset,name,shorthand,env,usage:=randomFlag()
73+
envValue,_:=cryptorand.Int63n(10)
74+
t.Setenv(env,strconv.FormatUint(uint64(envValue),10))
75+
def,_:=cryptorand.Int()
76+
77+
cliflag.Uint8VarP(flagset,&ptr,name,shorthand,env,uint8(def),usage)
78+
got,err:=flagset.GetUint8(name)
79+
require.NoError(t,err)
80+
require.Equal(t,uint8(envValue),got)
81+
})
82+
83+
t.Run("IntFailParse",func(t*testing.T) {
84+
varptruint8
85+
flagset,name,shorthand,env,usage:=randomFlag()
86+
envValue,_:=cryptorand.String(10)
87+
t.Setenv(env,envValue)
88+
def,_:=cryptorand.Int63n(10)
89+
90+
cliflag.Uint8VarP(flagset,&ptr,name,shorthand,env,uint8(def),usage)
91+
got,err:=flagset.GetUint8(name)
92+
require.NoError(t,err)
93+
require.Equal(t,uint8(def),got)
94+
})
95+
96+
t.Run("BoolDefault",func(t*testing.T) {
97+
varptrbool
98+
flagset,name,shorthand,env,usage:=randomFlag()
99+
def,_:=cryptorand.Bool()
100+
101+
cliflag.BoolVarP(flagset,&ptr,name,shorthand,env,def,usage)
102+
got,err:=flagset.GetBool(name)
103+
require.NoError(t,err)
104+
require.Equal(t,def,got)
105+
require.Contains(t,flagset.FlagUsages(),usage)
106+
require.Contains(t,flagset.FlagUsages(),fmt.Sprintf(" - consumes $%s",env))
107+
})
108+
109+
t.Run("BoolEnvVar",func(t*testing.T) {
110+
varptrbool
111+
flagset,name,shorthand,env,usage:=randomFlag()
112+
envValue,_:=cryptorand.Bool()
113+
t.Setenv(env,strconv.FormatBool(envValue))
114+
def,_:=cryptorand.Bool()
115+
116+
cliflag.BoolVarP(flagset,&ptr,name,shorthand,env,def,usage)
117+
got,err:=flagset.GetBool(name)
118+
require.NoError(t,err)
119+
require.Equal(t,envValue,got)
120+
})
121+
122+
t.Run("BoolFailParse",func(t*testing.T) {
123+
varptrbool
124+
flagset,name,shorthand,env,usage:=randomFlag()
125+
envValue,_:=cryptorand.String(10)
126+
t.Setenv(env,envValue)
127+
def,_:=cryptorand.Bool()
128+
129+
cliflag.BoolVarP(flagset,&ptr,name,shorthand,env,def,usage)
130+
got,err:=flagset.GetBool(name)
131+
require.NoError(t,err)
132+
require.Equal(t,def,got)
133+
})
134+
}
135+
136+
funcrandomFlag() (*pflag.FlagSet,string,string,string,string) {
137+
fsname,_:=cryptorand.String(10)
138+
flagset:=pflag.NewFlagSet(fsname,pflag.PanicOnError)
139+
name,_:=cryptorand.String(10)
140+
shorthand,_:=cryptorand.String(1)
141+
env,_:=cryptorand.String(10)
142+
usage,_:=cryptorand.String(10)
143+
144+
returnflagset,name,shorthand,env,usage
145+
}

‎cli/cliui/prompt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func Prompt(cmd *cobra.Command, opts PromptOptions) (string, error) {
3636
signal.Notify(interrupt,os.Interrupt)
3737
defersignal.Stop(interrupt)
3838

39-
errCh:=make(chanerror)
39+
errCh:=make(chanerror,1)
4040
lineCh:=make(chanstring)
4141
gofunc() {
4242
varlinestring

‎cli/cliui/provisionerjob.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ type ProvisionerJobOptions struct {
3434
Logsfunc() (<-chan codersdk.ProvisionerJobLog,error)
3535

3636
FetchInterval time.Duration
37+
// Verbose determines whether debug and trace logs will be shown.
38+
Verbosebool
3739
}
3840

3941
// ProvisionerJob renders a provisioner job with interactive cancellation.
@@ -48,7 +50,7 @@ func ProvisionerJob(cmd *cobra.Command, opts ProvisionerJobOptions) error {
4850
didLogBetweenStage=false
4951
ctx,cancelFunc=context.WithCancel(cmd.Context())
5052

51-
errChan=make(chanerror)
53+
errChan=make(chanerror,1)
5254
job codersdk.ProvisionerJob
5355
jobMutex sync.Mutex
5456
)
@@ -143,8 +145,6 @@ func ProvisionerJob(cmd *cobra.Command, opts ProvisionerJobOptions) error {
143145
updateJob()
144146
caselog,ok:=<-logs:
145147
if!ok {
146-
// The logs stream will end when the job does,
147-
// so it's safe to
148148
updateJob()
149149
jobMutex.Lock()
150150
ifjob.CompletedAt!=nil {
@@ -165,9 +165,12 @@ func ProvisionerJob(cmd *cobra.Command, opts ProvisionerJobOptions) error {
165165
}
166166
output:=""
167167
switchlog.Level {
168-
casedatabase.LogLevelDebug:
169-
continue
170-
casedatabase.LogLevelTrace,database.LogLevelError:
168+
casedatabase.LogLevelTrace,database.LogLevelDebug:
169+
if!opts.Verbose {
170+
continue
171+
}
172+
output=Styles.Placeholder.Render(log.Output)
173+
casedatabase.LogLevelError:
171174
output=defaultStyles.Error.Render(log.Output)
172175
casedatabase.LogLevelWarn:
173176
output=Styles.Warn.Render(log.Output)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp