-
-
Notifications
You must be signed in to change notification settings - Fork 287
/
main.go
46 lines (38 loc) · 997 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
"text/template"
)
func check(err error) {
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func main() {
dir, err := os.Getwd()
check(err)
// Read the current version from the top-level VERSION file in the Alda repo.
versionFile := filepath.Join(filepath.Dir(dir), "VERSION")
contents, err := os.ReadFile(versionFile)
check(err)
version := strings.TrimSpace(string(contents))
// Create generated/version.go
outputFilepath := filepath.Join(dir, "generated", "version.go")
err = os.MkdirAll(filepath.Dir(outputFilepath), os.ModePerm)
check(err)
outputFile, err := os.Create(outputFilepath)
check(err)
defer outputFile.Close()
// Generate source code into generated/version.go.
tmpl, err := template.New("generated/version.go").
Parse(`package generated
// ClientVersion is the version of the Alda client.
const ClientVersion = "{{.}}"`)
check(err)
err = tmpl.Execute(outputFile, version)
check(err)
}