Skip to content

Commit a6cbb22

Browse files
committed
ant version: the release tag, or the module version go install recorded
scripts/release.ant takes the tag and builds it in with -X main.version; publish.yaml passes GITHUB_REF_NAME. Claude-Session: https://claude.ai/code/session_01KnX6pGSeWfGbYjXUUtvjhj
1 parent 7150b88 commit a6cbb22

7 files changed

Lines changed: 40 additions & 7 deletions

File tree

‎.github/workflows/publish.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
go-version-file: go.mod
2626
cache: false
2727
- name: build
28-
run: go run ./cmd/ant run scripts/release.ant
28+
run: go run ./cmd/ant run scripts/release.ant "$GITHUB_REF_NAME"
2929
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
3030
with:
3131
name: dist

‎cmd/ant/complete.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ var commands = []command{
6060
}},
6161
{name: "lsp"},
6262
{name: "dap"},
63+
{name: "version"},
6364
{name: "help"},
6465
}
6566

6667
// flags are those ant takes in place of a command, as run's switch accepts them.
67-
var flags = []string{"-h", "--help", "--comp"}
68+
var flags = []string{"-h", "--help", "--version", "--comp"}
6869

6970
var shells = []string{"bash", "zsh", "fish"}
7071

‎cmd/ant/complete_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ func TestComplete(t *testing.T) {
1919
line string
2020
want []string
2121
}{
22-
{"ant ", []string{"run", "check", "test", "fmt", "doc", "lsp", "dap", "help", "lib", "main.ant", "my dir"}},
22+
{"ant ", []string{"run", "check", "test", "fmt", "doc", "lsp", "dap", "version", "help", "lib", "main.ant", "my dir"}},
2323
{"ant r", []string{"run"}},
2424
{"ant m", []string{"main.ant", "my dir"}},
25-
{"ant -", []string{"-h", "--help", "--comp"}},
25+
{"ant -", []string{"-h", "--help", "--version", "--comp"}},
2626
{"FOO=1 ant r", []string{"run"}},
2727
{"sudo ./bin/ant run l", []string{"lib"}},
2828
{"ant --comp ", []string{"bash", "zsh", "fish"}},

‎cmd/ant/main.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// ant lsp serve the Language Server Protocol to an editor
1010
// ant dap serve the Debug Adapter Protocol to an editor
1111
// ant --comp bash|zsh|fish print the script that completes ant's commands in the shell
12+
// ant version print the version of ant
1213
// ant start a REPL
1314
//
1415
// Exit status: 0 when the script ends or the check passes, 1 when the script returns an Err, the
@@ -71,6 +72,7 @@ const usage = `usage:
7172
ant lsp
7273
ant dap
7374
ant --comp bash|zsh|fish
75+
ant version
7476
ant`
7577

7678
func main() {
@@ -155,6 +157,9 @@ func run(args []string, stdin io.Reader, stdout, stderr io.Writer) int {
155157
return dapCommand(args[1:], stdin, stdout, stderr)
156158
case "--comp":
157159
return compCommand(args[1:], stdout, stderr)
160+
case "version", "--version":
161+
fmt.Fprintln(stdout, "ant", antVersion())
162+
return 0
158163
case "help", "-h", "--help":
159164
fmt.Fprintln(stdout, usage)
160165
return 0

‎cmd/ant/main_test.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ func TestRunCommand(t *testing.T) {
3636
{"check cannot load", []string{"check", missing}, "", 2, "", "main"},
3737
{"help", []string{"help"}, "", 0, "usage", ""},
3838
{"help flag", []string{"--help"}, "", 0, "usage", ""},
39+
{"version", []string{"version"}, "", 0, "ant ", ""},
40+
{"version flag", []string{"--version"}, "", 0, "ant ", ""},
3941
{"unknown", []string{"frobnicate"}, "", 2, "", "usage"},
4042
{"repl", nil, "1 + 1\nvar s = \"x\"\ns + s\n", 0, "2\n", ""},
4143
{"repl owns stdin", nil, "File.readLine(Os.stdin())\n", 0, "Ok{ value: null }\n", ""},

‎cmd/ant/version.go‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package main
2+
3+
import "runtime/debug"
4+
5+
// version is the release ant was built from, set by scripts/release.ant with
6+
// -ldflags=-X main.version=vX.Y.Z.
7+
var version string
8+
9+
// antVersion is the version ant version prints: the one the release set, else the module version
10+
// go install recorded (v0.1.0 for go install …@v0.1.0, a pseudo-version or (devel) for a checkout).
11+
func antVersion() string {
12+
if version != "" {
13+
return version
14+
}
15+
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Version != "" {
16+
return info.Main.Version
17+
}
18+
return "(devel)"
19+
}

‎scripts/release.ant‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@
44
//! dist/ant_<os>_<arch>, with .exe for windows. The names leave out the version, so
55
//! releases/latest/download/ant_<os>_<arch> always names the newest one, which is what
66
//! ant-lang.org/install.sh downloads. GitHub keeps each release asset's SHA-256 digest, so the
7-
//! release has no checksums file.
7+
//! release has no checksums file. The version, the release's tag, is built in for ant version.
88
//!
9-
//! ant scripts/release.ant
9+
//! ant scripts/release.ant v0.1.0
1010
//!
1111
//! Run it from the repository root, with go on PATH. Every target is pure Go, so one host builds
1212
//! them all.
1313

14+
var args = Os.args()
15+
if len(args) != 1 {
16+
return Result.err(Error{ message: "usage: ant scripts/release.ant vX.Y.Z" })
17+
}
18+
var version = args[0]
19+
1420
var targets = [
1521
"linux/amd64",
1622
"linux/arm64",
@@ -31,7 +37,7 @@ for target in targets {
3137
env["CGO_ENABLED"] = "0"
3238
env["GOOS"] = os
3339
env["GOARCH"] = arch
34-
var build = Cmd.new("go", ["build", "-trimpath", "-ldflags=-s -w", "-o", output, "./cmd/ant"], env: env)
40+
var build = Cmd.new("go", ["build", "-trimpath", "-ldflags=-s -w -X main.version=${version}", "-o", output, "./cmd/ant"], env: env)
3541
var status = try Cmd.run(build)
3642
if status != 0 {
3743
return Result.err(Error{ message: "${Cmd.string(build)}: exit status ${status}" })

0 commit comments

Comments
 (0)