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

Commit1fdff41

Browse files
committed
ensure run in coder repo, use base path fs
1 parentb436540 commit1fdff41

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

‎scripts/release/main.go

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"io/fs"
88
"os"
9+
"os/exec"
910
"path/filepath"
1011
"regexp"
1112
"slices"
@@ -30,8 +31,22 @@ const (
3031
)
3132

3233
funcmain() {
34+
// Pre-flight checks.
35+
toplevel,err:=run("git","rev-parse","--show-toplevel")
36+
iferr!=nil {
37+
_,_=fmt.Fprintf(os.Stderr,"ERROR: %v\n",err)
38+
_,_=fmt.Fprintf(os.Stderr,"NOTE: This command must be run in the coder/coder repository.\n")
39+
os.Exit(1)
40+
}
41+
42+
iferr=checkCoderRepo(toplevel);err!=nil {
43+
_,_=fmt.Fprintf(os.Stderr,"ERROR: %v\n",err)
44+
_,_=fmt.Fprintf(os.Stderr,"NOTE: This command must be run in the coder/coder repository.\n")
45+
os.Exit(1)
46+
}
47+
3348
r:=&releaseCommand{
34-
fs:afero.NewOsFs(),
49+
fs:afero.NewBasePathFs(afero.NewOsFs(),toplevel),
3550
logger:slog.Make(sloghuman.Sink(os.Stderr)).Leveled(slog.LevelInfo),
3651
}
3752

@@ -109,7 +124,7 @@ func main() {
109124
},
110125
}
111126

112-
err:=cmd.Invoke().WithOS().Run()
127+
err=cmd.Invoke().WithOS().Run()
113128
iferr!=nil {
114129
iferrors.Is(err,cliui.Canceled) {
115130
os.Exit(1)
@@ -119,6 +134,17 @@ func main() {
119134
}
120135
}
121136

137+
funccheckCoderRepo(pathstring)error {
138+
remote,err:=run("git","-C",path,"remote","get-url","origin")
139+
iferr!=nil {
140+
returnxerrors.Errorf("get remote failed: %w",err)
141+
}
142+
if!strings.Contains(remote,"github.com")||!strings.Contains(remote,"coder/coder") {
143+
returnxerrors.Errorf("origin is not set to the coder/coder repository on github.com")
144+
}
145+
returnnil
146+
}
147+
122148
typereleaseCommandstruct {
123149
fs afero.Fs
124150
logger slog.Logger
@@ -389,3 +415,12 @@ func (r *releaseCommand) autoversionFile(ctx context.Context, file, channel, ver
389415

390416
returnnil
391417
}
418+
419+
funcrun(commandstring,args...string) (string,error) {
420+
cmd:=exec.Command(command,args...)
421+
out,err:=cmd.CombinedOutput()
422+
iferr!=nil {
423+
return"",xerrors.Errorf("command failed: %q: %w\n%s",fmt.Sprintf("%s %s",command,strings.Join(args," ")),err,out)
424+
}
425+
returnstrings.TrimSpace(string(out)),nil
426+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp