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>
This commit is contained in:
Chris F Ravenscroft
2023-10-07 12:51:00 -07:00
committed by GitHub
parent 0904a24564
commit 114b36f677
5 changed files with 82 additions and 55 deletions
+4 -1
View File
@@ -20,5 +20,8 @@ jobs:
release-type: go
package-name: GLAuth
path: v2
default-branch: dev
default-branch: master
pull-request-title-pattern: "ci: release ${version}"
token: ${{ secrets.RELEASE_PLEASE_TOKEN }}
extra-files: |
v2/internal/version/const.go
+2 -2
View File
@@ -16,7 +16,7 @@ GIT_IS_TAG_COMMIT=$(shell git describe --abbrev=0 --tags > /dev/null 2> /dev/nul
GIT_BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
# Build variables
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}
BUILD_VARS?=-s -w
BUILD_FILES=.
TRIM_FLAGS>?=-trimpath
@@ -87,7 +87,7 @@ mkbindir:
.PHONY: mkbindir
build: mkbindir
@go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/$(GOOS)$(GOARCH)/glauth -buildvcs .
@go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/$(GOOS)$(GOARCH)/glauth -buildvcs=false .
$(MAKE) sha256
.PHONY: build
+3 -52
View File
@@ -7,6 +7,7 @@ import (
"github.com/arl/statsviz"
docopt "github.com/docopt/docopt-go"
"github.com/fsnotify/fsnotify"
"github.com/glauth/glauth/v2/internal/version"
"github.com/glauth/glauth/v2/pkg/config"
"github.com/glauth/glauth/v2/pkg/frontend"
"github.com/glauth/glauth/v2/pkg/logging"
@@ -25,14 +26,6 @@ import (
"time"
)
// Set with buildtime vars
var LastGitTag string
var BuildTime string
var GitCommit string
var GitClean string
var GitBranch string
var GitTagIsCommit string
const programName = "glauth"
var usage = `glauth: securely expose your LDAP for external auth
@@ -65,48 +58,6 @@ var (
activeConfig = &config.Config{}
)
// Reads builtime vars and returns a full string containing info about
// the currently running version of the software. Primarily used by the
// --version flag at runtime.
func getVersionString() string {
var versionstr string
versionstr = "GLauth"
// Notate the git context of the build
switch {
// If a release, use the tag
case GitClean == "1" && GitTagIsCommit == "1":
versionstr += " " + LastGitTag + "\n\n"
// If this branch had a tag before, mention the branch and the tag to give a rough idea of the base version
case len(GitBranch) > 1 && len(LastGitTag) > 1:
versionstr += "\nNon-release build from branch " + GitBranch + ", based on tag " + LastGitTag + "\n\n"
// If no previous tag specified, just mention the branch
case len(GitBranch) > 1:
versionstr += "\nNon-release build from branch " + GitBranch + "\n\n"
// Fallback message, if all else fails
default:
versionstr += "\nNon-release build\n\n"
}
// Include build time
if len(BuildTime) > 1 {
versionstr += "Build time: " + BuildTime + "\n"
}
// Add commit hash
if GitClean == "1" && len(GitCommit) > 1 {
versionstr += "Commit: " + GitCommit + "\n"
}
return versionstr
}
func main() {
if err := parseArgs(); err != nil {
fmt.Println("Could not parse command-line arguments")
@@ -135,7 +86,7 @@ func main() {
func startService() {
// stats
stats.General.Set("version", stats.Stringer(LastGitTag))
stats.General.Set("version", stats.Stringer(version.Version))
// web API
if activeConfig.API.Enabled {
@@ -250,7 +201,7 @@ func startConfigWatcher() {
func parseArgs() error {
var err error
if args, err = docopt.Parse(usage, nil, true, getVersionString(), false); err != nil {
if args, err = docopt.Parse(usage, nil, true, version.GetVersion(), false); err != nil {
return err
}
+5
View File
@@ -0,0 +1,5 @@
package version
// Version is the tag of the latest release, it gets changed by the ci
// process when a release is happening
const Version = "v2.3.0" // x-release-please-version
+68
View File
@@ -0,0 +1,68 @@
package version
import (
"fmt"
"runtime/debug"
)
type gitInfo struct {
BuildTime string
Commit string
Dirty bool
}
// GetVersion reads builtime vars and returns a full string containing info about
// the currently running version of the software. Primarily used by the
// --version flag at runtime.
func GetVersion() string {
// TODO @shipperizer see if it's worth replacing with info.Main.Path
// aka github.com/glauth/glauth/v2 - not great but worth checking
name := "GLauth"
info, ok := debug.ReadBuildInfo()
if !ok {
return fmt.Sprintf(`
%s
Non-release build`,
name)
}
gitInfo := vcsInfo(info.Settings)
// If a release, use the tag
if !gitInfo.Dirty {
return fmt.Sprintf(`%s %s
Build time: %s
Commit: %s`, name, Version, gitInfo.BuildTime, gitInfo.Commit)
}
return fmt.Sprintf(`%s
Non-release build based on tag %s
Build time: %s
Commit: %s`, name, Version, gitInfo.BuildTime, gitInfo.Commit)
}
func vcsInfo(settings []debug.BuildSetting) *gitInfo {
info := new(gitInfo)
info.BuildTime = "unknown"
info.Commit = "unknown"
info.Dirty = false
for _, v := range settings {
switch v.Key {
case "vcs.revision":
info.Commit = v.Value
case "vcs.modified":
info.Dirty = v.Value == "true"
case "vcs.time":
info.BuildTime = v.Value
}
}
return info
}