Skip to content

Commit 945fe4c

Browse files
authored
Move VERSION to top-level package (webrpc#169)
1 parent 30ed299 commit 945fe4c

File tree

7 files changed

+32
-24
lines changed

7 files changed

+32
-24
lines changed

.github/workflows/.goreleaser.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ builds:
1313
- amd64
1414
- arm64
1515
ldflags:
16-
- -s -w -X github.com/webrpc/webrpc/gen.VERSION=v{{.Version}}
16+
- -s -w -X github.com/webrpc/webrpc.VERSION=v{{.Version}}
1717
- id: webrpc-test
1818
main: ./cmd/webrpc-test
1919
binary: webrpc-test
@@ -25,7 +25,7 @@ builds:
2525
- amd64
2626
- arm64
2727
ldflags:
28-
- -s -w -X github.com/webrpc/webrpc/gen.VERSION=v{{.Version}}
28+
- -s -w -X github.com/webrpc/webrpc.VERSION=v{{.Version}}
2929

3030
archives:
3131
- id: webrpc-gen
@@ -59,7 +59,7 @@ release:
5959
6060
## Build from source
6161
```
62-
go install -ldflags="-s -w -X github.com/webrpc/webrpc/gen.VERSION=v{{.Version}}" github.com/webrpc/webrpc/cmd/webrpc-gen@v{{.Version}}
62+
go install -ldflags="-s -w -X github.com/webrpc/webrpc.VERSION=v{{.Version}}" github.com/webrpc/webrpc/cmd/webrpc-gen@v{{.Version}}
6363
```
6464
6565
## Download binaries

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ RUN apk add --update git
99
ADD ./ /src
1010

1111
WORKDIR /src
12-
RUN go build -ldflags="-s -w -X github.com/webrpc/webrpc/gen.VERSION=${VERSION}" -o /usr/bin/webrpc-gen ./cmd/webrpc-gen
12+
RUN go build -ldflags="-s -w -X github.com/webrpc/webrpc.VERSION=${VERSION}" -o /usr/bin/webrpc-gen ./cmd/webrpc-gen
1313

1414
# -----------------------------------------------------------------
1515
# Runner

cmd/webrpc-gen/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
var flags = flag.NewFlagSet("webrpc-gen", flag.ExitOnError)
1717

1818
func main() {
19-
versionFlag := flags.Bool("version", false, "print webrpc version and exit")
19+
versionFlag := flags.Bool("version", false, "print version and exit")
2020
schemaFlag := flags.String("schema", "", "webrpc schema file (required)")
2121
targetFlag := flags.String("target", "", "target generator (required), ie. golang or [email protected]")
2222
outFlag := flags.String("out", "", "generated output file, default: stdout")
@@ -51,7 +51,7 @@ func main() {
5151
flags.Parse(cliFlags)
5252

5353
if *versionFlag {
54-
fmt.Printf("%s %s\n", flags.Name(), gen.VERSION)
54+
fmt.Println("webrpc-gen", webrpc.VERSION)
5555
os.Exit(0)
5656
}
5757

@@ -119,7 +119,7 @@ func main() {
119119
fmt.Println("=======================================")
120120
fmt.Println("| webrpc generated summary |")
121121
fmt.Println("=======================================")
122-
fmt.Println(" webrpc-gen version :", gen.VERSION)
122+
fmt.Println(" webrpc-gen version :", webrpc.VERSION)
123123
fmt.Println(" target :", genOutput.TmplVersion)
124124
if !genOutput.IsLocal {
125125
fmt.Println(" target cache :", genOutput.TmplDir)

cmd/webrpc-test/main.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ import (
99
"os"
1010
"time"
1111

12+
"github.com/webrpc/webrpc"
1213
"github.com/webrpc/webrpc/tests/client"
1314
"github.com/webrpc/webrpc/tests/server"
1415
)
1516

1617
var (
17-
flags = flag.NewFlagSet("webrpc-test", flag.ContinueOnError)
18-
clientFlag = flags.Bool("client", false, "client mode")
19-
serverFlag = flags.Bool("server", false, "server mode")
18+
flags = flag.NewFlagSet("webrpc-test", flag.ContinueOnError)
19+
clientFlag = flags.Bool("client", false, "client mode")
20+
serverFlag = flags.Bool("server", false, "server mode")
21+
versionFlag = flags.Bool("version", false, "print version and exit")
2022

2123
// -client
2224
clientFlags = flag.NewFlagSet("webrpc-test -client", flag.ExitOnError)
@@ -35,6 +37,12 @@ func main() {
3537
}
3638

3739
_ = flags.Parse(os.Args[1:2])
40+
41+
if *versionFlag {
42+
fmt.Println("webrpc-test", webrpc.VERSION)
43+
os.Exit(0)
44+
}
45+
3846
if !*serverFlag && !*clientFlag {
3947
fmt.Fprintf(os.Stderr, "-server or -client flag is required\n")
4048
os.Exit(1)

gen/gen.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"path/filepath"
88
"strings"
99

10+
"github.com/webrpc/webrpc"
1011
"github.com/webrpc/webrpc/schema"
1112
)
1213

@@ -49,7 +50,7 @@ func Generate(proto *schema.WebRPCSchema, target string, config *Config) (*GenOu
4950
}{
5051
proto,
5152
schemaHash,
52-
VERSION,
53+
webrpc.VERSION,
5354
getWebrpcGenCommand(),
5455
target,
5556
config.TemplateOptions,

gen/version.go

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

version.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package webrpc
2+
3+
// VERSION defines version of webrpc tools, such as webrpc-gen.
4+
//
5+
// Please update major/minor version by hand when changing webrpc-gen
6+
// Template Functions API or when making any backward-incompatible changes.
7+
// The patch value is automatically updated with the latest git tag in CI.
8+
//
9+
// Available as {{.WebrpcGenVersion}} in generator templates. Templates can
10+
// check against {{.WebrpcGenVersion}} to require minimal major/minor version
11+
// to guarantees certain Template functions API.
12+
var VERSION = "v0.8.x-dev"

0 commit comments

Comments
 (0)