Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: generate version.go #183

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) // nolint: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.