Skip to content

Commit

Permalink
Merge pull request #483 from twhiston/version_generator
Browse files Browse the repository at this point in the history
add version code generator
  • Loading branch information
twhiston authored Mar 11, 2018
2 parents 6a9e815 + 3f24105 commit 8cd859f
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ node_modules
caddyfile
cli/semaphore_*
*-packr.go
util/version.go
23 changes: 12 additions & 11 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -122,13 +130,6 @@ tasks:

release:
cmds:
- |
cat <<HEREDOC > util/version.go
package util
var Version string = "{{ .VERSION }}"
HEREDOC
- echo "Updating changelog:"
- set +e
- git changelog -t "v$VERSION"
Expand Down
4 changes: 2 additions & 2 deletions public/html/admin.pug
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion public/html/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ html(lang="en" ng-app="semaphore")
| &nbsp;
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
Expand Down
8 changes: 8 additions & 0 deletions util/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 0 additions & 4 deletions util/version.go

This file was deleted.

44 changes: 44 additions & 0 deletions util/version_gen/generator.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 8cd859f

Please sign in to comment.