Skip to content

Commit

Permalink
Merge pull request #8 from eolinker/feature/add-version
Browse files Browse the repository at this point in the history
新增apinto-dashboard版本显示
  • Loading branch information
Dot-Liu authored Nov 24, 2022
2 parents ff4c5f8 + 4a50541 commit 162e492
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ jobs:
- name: Checkout #Checkout代码
uses: actions/checkout@v3
- name: GoTidy
run: go mod tidy -compat=1.17
run: |
go mod tidy -compat=1.17
echo "GOVERSION=$(go version)" >> $GITHUB_ENV
- name: Create archives on Release #创建各种系统架构下的二进制包并上传至release assets
uses: goreleaser/[email protected]
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
/out/
/builds/sqlite.db
*.DS_Store
/dist/
13 changes: 9 additions & 4 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ builds:
builder: go
gobinary: go
ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser
- -s -w
- -X "github.com/eolinker/apinto-dashboard/app/apinto-dashboard/version.Version={{.Version}}"
- -X "github.com/eolinker/apinto-dashboard/app/apinto-dashboard/version.gitCommit={{.Commit}}"
- -X "github.com/eolinker/apinto-dashboard/app/apinto-dashboard/version.buildTime={{.Date}}"
- -X "github.com/eolinker/apinto-dashboard/app/apinto-dashboard/version.buildUser=goreleaser"
- -X "github.com/eolinker/apinto-dashboard/app/apinto-dashboard/version.goVersion={{.Env.GOVERSION}}"
archives:
- id: default
format: tar.gz
Expand All @@ -35,16 +40,16 @@ archives:
files:
- src: 'builds/account.yml'
dst: /
strip_parent: true
- src: 'builds/config.yml'
dst: /
strip_parent: true
- src: 'builds/Dockerfile'
dst: /
strip_parent: true
- src: 'builds/static/*'
dst: /static
strip_parent: true
- src: 'builds/tpl/*'
dst: /tpl
strip_parent: true
release:
name_template: "{{ .Tag }}"
mode: append
3 changes: 3 additions & 0 deletions app/apinto-dashboard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"os"

"github.com/eolinker/apinto-dashboard/app/apinto-dashboard/version"

"github.com/eolinker/apinto-dashboard/modules/apps"

apinto "github.com/eolinker/apinto-dashboard"
Expand Down Expand Up @@ -160,6 +162,7 @@ func main() {
log.Panic(err)
return
}
version.Println()
err = http.ListenAndServe(fmt.Sprintf(":%s", cf.Port), service)
if err != nil {
log.Panic(err)
Expand Down
29 changes: 29 additions & 0 deletions app/apinto-dashboard/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package version

import (
"bytes"
"fmt"
)

// These should be set via go build -ldflags -X 'xxxx'.
var Version = "unknown"
var goVersion = "unknown"
var gitCommit = "unknown"
var buildTime = "unknown"
var buildUser = "unknown"

var profileInfo []byte

func init() {
buffer := &bytes.Buffer{}
fmt.Fprintf(buffer, "Apinto version: %s\n", Version)
fmt.Fprintf(buffer, "Golang version: %s\n", goVersion)
fmt.Fprintf(buffer, "Git commit hash: %s\n", gitCommit)
fmt.Fprintf(buffer, "Built on: %s\n", buildTime)
fmt.Fprintf(buffer, "Built by: %s\n", buildUser)
profileInfo = buffer.Bytes()
}

func Println() {
fmt.Print(string(profileInfo))
}

0 comments on commit 162e492

Please sign in to comment.