Skip to content

Commit 114b36f

Browse files
Fusionshipperizerwolsen
authored
Final merge from Dev to Master (#344)
* build: make build vars optional and passable via env * build: use . for BUILD_FILES var to allow buildvcs flag * build: create mkbindir, build and sha256 targets * build: reuse build target for each platform specific compilation * Ensure same go version for main and plugins * chore: release 2.3.0 Release-As: 2.3.0 * release-please * Fix(plugins)!: Rename the groups table to ldapgroups (#326) The groups table name is a reserved keyword in mysql and requires that the table name be escaped with backticks in order to use the groups name. Other databases such as postgres do not support the use of the backticks in the query statements. This change renames the groups table to ldapgroups in oder to avoid this problem altogether. This does have a dependency on the backend sql plugins to alter the schema to match the new name. Signed-off-by: Billy Olsen <billy.olsen@gmail.com> Co-authored-by: Chris F Ravenscroft <chris@voilaweb.com> * chore: update docker sqlite with ldapgroups (#338) * feat: Update migration code to support table names (#339) * chore(dev): release 2.3.0 (#337) * ci: change pr name pattern for release please * ci: switch to use master as default branch and plan to drop dev * fix: exploit release-please for tagging in code * fix: use runtime/debug to fetch git build info * fix: use newer function to fetch git info for version * build: drop build tags --------- Signed-off-by: Billy Olsen <billy.olsen@gmail.com> Co-authored-by: shipperizer <alexcabb@gmail.com> Co-authored-by: Billy Olsen <wolsen@users.noreply.github.com>
1 parent 0904a24 commit 114b36f

5 files changed

Lines changed: 82 additions & 55 deletions

File tree

.github/workflows/release-please.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,8 @@ jobs:
2020
release-type: go
2121
package-name: GLAuth
2222
path: v2
23-
default-branch: dev
23+
default-branch: master
24+
pull-request-title-pattern: "ci: release ${version}"
2425
token: ${{ secrets.RELEASE_PLEASE_TOKEN }}
26+
extra-files: |
27+
v2/internal/version/const.go

v2/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ GIT_IS_TAG_COMMIT=$(shell git describe --abbrev=0 --tags > /dev/null 2> /dev/nul
1616
GIT_BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
1717

1818
# Build variables
19-
BUILD_VARS?=-s -w -X main.GitCommit=${GIT_COMMIT} -X main.GitBranch=${GIT_BRANCH} -X main.BuildTime=${BUILD_TIME} -X main.GitClean=${GIT_CLEAN} -X main.LastGitTag=${LAST_GIT_TAG} -X main.GitTagIsCommit=${GIT_IS_TAG_COMMIT}
19+
BUILD_VARS?=-s -w
2020
BUILD_FILES=.
2121
TRIM_FLAGS>?=-trimpath
2222

@@ -87,7 +87,7 @@ mkbindir:
8787
.PHONY: mkbindir
8888

8989
build: mkbindir
90-
@go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/$(GOOS)$(GOARCH)/glauth -buildvcs .
90+
@go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/$(GOOS)$(GOARCH)/glauth -buildvcs=false .
9191
$(MAKE) sha256
9292
.PHONY: build
9393

v2/glauth.go

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/arl/statsviz"
88
docopt "github.com/docopt/docopt-go"
99
"github.com/fsnotify/fsnotify"
10+
"github.com/glauth/glauth/v2/internal/version"
1011
"github.com/glauth/glauth/v2/pkg/config"
1112
"github.com/glauth/glauth/v2/pkg/frontend"
1213
"github.com/glauth/glauth/v2/pkg/logging"
@@ -25,14 +26,6 @@ import (
2526
"time"
2627
)
2728

28-
// Set with buildtime vars
29-
var LastGitTag string
30-
var BuildTime string
31-
var GitCommit string
32-
var GitClean string
33-
var GitBranch string
34-
var GitTagIsCommit string
35-
3629
const programName = "glauth"
3730

3831
var usage = `glauth: securely expose your LDAP for external auth
@@ -65,48 +58,6 @@ var (
6558
activeConfig = &config.Config{}
6659
)
6760

68-
// Reads builtime vars and returns a full string containing info about
69-
// the currently running version of the software. Primarily used by the
70-
// --version flag at runtime.
71-
func getVersionString() string {
72-
73-
var versionstr string
74-
75-
versionstr = "GLauth"
76-
77-
// Notate the git context of the build
78-
switch {
79-
// If a release, use the tag
80-
case GitClean == "1" && GitTagIsCommit == "1":
81-
versionstr += " " + LastGitTag + "\n\n"
82-
83-
// If this branch had a tag before, mention the branch and the tag to give a rough idea of the base version
84-
case len(GitBranch) > 1 && len(LastGitTag) > 1:
85-
versionstr += "\nNon-release build from branch " + GitBranch + ", based on tag " + LastGitTag + "\n\n"
86-
87-
// If no previous tag specified, just mention the branch
88-
case len(GitBranch) > 1:
89-
versionstr += "\nNon-release build from branch " + GitBranch + "\n\n"
90-
91-
// Fallback message, if all else fails
92-
default:
93-
versionstr += "\nNon-release build\n\n"
94-
}
95-
96-
// Include build time
97-
if len(BuildTime) > 1 {
98-
versionstr += "Build time: " + BuildTime + "\n"
99-
}
100-
101-
// Add commit hash
102-
if GitClean == "1" && len(GitCommit) > 1 {
103-
versionstr += "Commit: " + GitCommit + "\n"
104-
}
105-
106-
return versionstr
107-
108-
}
109-
11061
func main() {
11162
if err := parseArgs(); err != nil {
11263
fmt.Println("Could not parse command-line arguments")
@@ -135,7 +86,7 @@ func main() {
13586

13687
func startService() {
13788
// stats
138-
stats.General.Set("version", stats.Stringer(LastGitTag))
89+
stats.General.Set("version", stats.Stringer(version.Version))
13990

14091
// web API
14192
if activeConfig.API.Enabled {
@@ -250,7 +201,7 @@ func startConfigWatcher() {
250201
func parseArgs() error {
251202
var err error
252203

253-
if args, err = docopt.Parse(usage, nil, true, getVersionString(), false); err != nil {
204+
if args, err = docopt.Parse(usage, nil, true, version.GetVersion(), false); err != nil {
254205
return err
255206
}
256207

v2/internal/version/const.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package version
2+
3+
// Version is the tag of the latest release, it gets changed by the ci
4+
// process when a release is happening
5+
const Version = "v2.3.0" // x-release-please-version

v2/internal/version/vcs.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package version
2+
3+
import (
4+
"fmt"
5+
"runtime/debug"
6+
)
7+
8+
type gitInfo struct {
9+
BuildTime string
10+
Commit string
11+
Dirty bool
12+
}
13+
14+
// GetVersion reads builtime vars and returns a full string containing info about
15+
// the currently running version of the software. Primarily used by the
16+
// --version flag at runtime.
17+
func GetVersion() string {
18+
19+
// TODO @shipperizer see if it's worth replacing with info.Main.Path
20+
// aka github.com/glauth/glauth/v2 - not great but worth checking
21+
22+
name := "GLauth"
23+
24+
info, ok := debug.ReadBuildInfo()
25+
26+
if !ok {
27+
return fmt.Sprintf(`
28+
%s
29+
Non-release build`,
30+
name)
31+
}
32+
33+
gitInfo := vcsInfo(info.Settings)
34+
35+
// If a release, use the tag
36+
if !gitInfo.Dirty {
37+
return fmt.Sprintf(`%s %s
38+
Build time: %s
39+
Commit: %s`, name, Version, gitInfo.BuildTime, gitInfo.Commit)
40+
}
41+
42+
return fmt.Sprintf(`%s
43+
Non-release build based on tag %s
44+
Build time: %s
45+
Commit: %s`, name, Version, gitInfo.BuildTime, gitInfo.Commit)
46+
47+
}
48+
49+
func vcsInfo(settings []debug.BuildSetting) *gitInfo {
50+
info := new(gitInfo)
51+
52+
info.BuildTime = "unknown"
53+
info.Commit = "unknown"
54+
info.Dirty = false
55+
56+
for _, v := range settings {
57+
switch v.Key {
58+
case "vcs.revision":
59+
info.Commit = v.Value
60+
case "vcs.modified":
61+
info.Dirty = v.Value == "true"
62+
case "vcs.time":
63+
info.BuildTime = v.Value
64+
}
65+
}
66+
67+
return info
68+
}

0 commit comments

Comments
 (0)