Skip to content

Commit

Permalink
chore: generate version.go
Browse files Browse the repository at this point in the history
  • Loading branch information
stoffeastrom committed Dec 9, 2023
1 parent 750c8a0 commit 4f10013
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 2 deletions.
10 changes: 10 additions & 0 deletions cmd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### Versioner

Before a release run in project root:

```sh
go run cmd/versioner.go v1.5.1
```

where tag is the next tag to be used.

5 changes: 5 additions & 0 deletions cmd/version.go.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Code generated from versioner.go; DO NOT EDIT.

package dbsql

var DriverVersion = "{{.Version}}"
39 changes: 39 additions & 0 deletions cmd/versioner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import (
"fmt"
"os"
"path"
"regexp"
"runtime"
"text/template"
)

func getTemplateFilePath() string {
_, filename, _, _ := runtime.Caller(0)

Check failure on line 13 in cmd/versioner.go

View workflow job for this annotation

GitHub Actions / Lint

declaration has 3 blank identifiers (dogsled)
dir := path.Dir(filename)
return path.Join(dir, "version.go.tmpl")
}

func main() {
tag := os.Args[1] // The first argument is the tag
// If the tag is not a valid semantic version, then it is not a release tag
re := regexp.MustCompile(`^v\d+\.\d+\.\d+$`)
if !re.MatchString(tag) {
panic(fmt.Errorf("tag %s is not a valid semantic version", tag))
}
tmpl, err := template.ParseFiles(getTemplateFilePath())
if err != nil {
panic(err)
}
f, err := os.Create("version.go")
if err != nil {
panic(err)
}
defer f.Close()
if err := tmpl.Execute(f, map[string]string{
"Version": string(tag),
}); err != nil {
panic(err)
}
}
2 changes: 0 additions & 2 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ func init() {
sql.Register("databricks", &databricksDriver{})
}

var DriverVersion = "1.3.1" // update version before each release

type databricksDriver struct{}

// Open returns a new connection to Databricks database with a DSN string.
Expand Down
5 changes: 5 additions & 0 deletions version.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4f10013

Please sign in to comment.