diff --git a/.gitignore b/.gitignore index 7e5bd38d..71d17b41 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ node_modules caddyfile cli/semaphore_* *-packr.go +util/version.go diff --git a/Taskfile.yml b/Taskfile.yml index 2f8c7d82..48d136f0 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -5,9 +5,6 @@ # internally by other tasks and therefore are not listed when running `task` or `task -l` version: '2' -vars: - VERSION: '2.5.0-dev' - tasks: all: desc: Install, Compile, Test and Build Semaphore for local architecture @@ -78,11 +75,22 @@ tasks: - api/api-packr.go cmds: - packr + - go run util/version_gen/generator.go {{ if .TAG }}{{ .TAG }}{{ else }}{{ if .SEMAPHORE_VERSION }}{{ .SEMAPHORE_VERSION }}{{ else }}{{ .BRANCH }}-{{ .SHA }}-{{ .TIMESTAMP }}{{ if .DIRTY }}-dirty{{ end }}{{ end }}{{end}} + vars: + TAG: + sh: git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null | sed -n 's/^\([^^~]\{1,\}\)\(\^0\)\{0,1\}$/\1/p' + BRANCH: + sh: git rev-parse --abbrev-ref HEAD + DIRTY: + sh: git status --porcelain + SHA: + sh: git log --pretty=format:'%h' -n 1 + TIMESTAMP: + sh: date +%s watch: desc: Watch fe and be file changes and rebuild dir: public - deps: ['deps:watch'] cmds: - task: watch:fe - task: watch:be @@ -122,13 +130,6 @@ tasks: release: cmds: - - | - cat < util/version.go - package util - - var Version string = "{{ .VERSION }}" - - HEREDOC - echo "Updating changelog:" - set +e - git changelog -t "v$VERSION" diff --git a/public/html/admin.pug b/public/html/admin.pug index 242a5237..a71d0767 100644 --- a/public/html/admin.pug +++ b/public/html/admin.pug @@ -1,5 +1,5 @@ .container-fluid - h1.text-center.no-top-margin semaphore v{{ semaphore.version }} + h1.text-center.no-top-margin semaphore {{ semaphore.version }} hr .row .col-sm-4 @@ -11,7 +11,7 @@ li.list-group-item: a(href="https://ansible-semaphore.github.io/semaphore/" target="_blank") API Documentation .col-sm-4 div(ng-if="upgrade.updateBody") - button.btn.btn-primary.btn-block(ng-click="doUpgrade()" ng-disabled="upgrade.config.cmdPath.length == 0") upgrade to {{ upgrade.update.tag_name }} + button.btn.btn-primary.btn-block(ng-click="doUpgrade()" ng-disabled="upgrade.config.cmdPath.length == 0") latest stable {{ upgrade.update.tag_name }} p.text-center(ng-if="upgrade.config.cmdPath.length == 0") a(href="https://github.com/ansible-semaphore/semaphore/wiki/Troubleshooting#upgrades-failing" target="_blank") Upgrading isn't possible! br diff --git a/public/html/index.pug b/public/html/index.pug index 19134254..42e1675f 100644 --- a/public/html/index.pug +++ b/public/html/index.pug @@ -35,7 +35,7 @@ html(lang="en" ng-app="semaphore") |   i.fa.fa-fw.fa-cog ul(uib-dropdown-menu) - li.dropdown-header semaphore v{{ semaphore.version }} + li.dropdown-header semaphore {{ semaphore.version }} li: a(ui-sref="admin") span(ng-if="semaphore.update") i.fa.fa-fw.fa-exclamation-circle diff --git a/util/config.go b/util/config.go index 3b6c45e1..d520f87b 100644 --- a/util/config.go +++ b/util/config.go @@ -93,12 +93,20 @@ func ConfigInit() { var printConfig bool flag.BoolVar(&printConfig, "printConfig", false, "print example configuration") + var printVersion bool + flag.BoolVar(&printVersion, "version", false, "print the semaphore version") + flag.Parse() if InteractiveSetup { return } + if printVersion { + fmt.Println(Version) + os.Exit(0) + } + if printConfig { cfg := &configType{ MySQL: mySQLConfig{ diff --git a/util/version.go b/util/version.go deleted file mode 100644 index 725235dc..00000000 --- a/util/version.go +++ /dev/null @@ -1,4 +0,0 @@ -package util - -var Version string = "2.4.1" - diff --git a/util/version_gen/generator.go b/util/version_gen/generator.go new file mode 100644 index 00000000..f96618cc --- /dev/null +++ b/util/version_gen/generator.go @@ -0,0 +1,44 @@ +// +build ignore + +package main + +import ( + "log" + "os" + "text/template" +) + +var versionTmpl = `package util + +//The Semaphore build version +var Version = "{{ .VERSION }}" +` + +func main(){ + + if len(os.Args) <= 1 { + log.Fatalln("Must pass in version number") + } + + data := make(map[string]string) + data["VERSION"] = os.Args[1] + + tmpl := template.New("version") + var err error + if tmpl, err = tmpl.Parse(versionTmpl); err != nil { + log.Fatalln(err) + } + + f, err := os.Create("util/version.go") + if err != nil { + log.Fatalln(err) + } + defer func(r *os.File) { + err = r.Close() + if err != nil { + log.Fatalln(err) + } + }(f) + + tmpl.Execute(f, data) +} \ No newline at end of file