Skip to content

Commit 5fe4afd

Browse files
author
Poby Zaarifwandono
committed
versioning app
1 parent 8a67d31 commit 5fe4afd

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

.github/workflows/release.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
on:
22
release:
3-
types: [created]
3+
types: [published]
44

55
jobs:
66
releases-matrix:
@@ -18,11 +18,20 @@ jobs:
1818
goos: windows
1919
steps:
2020
- uses: actions/checkout@v3
21+
22+
- name: Set APP_VERSION env
23+
run: echo APP_VERSION=$(basename ${GITHUB_REF}) >> ${GITHUB_ENV}
24+
- name: Set BUILD_TIME env
25+
run: echo BUILD_TIME=$(date --iso-8601=seconds) >> ${GITHUB_ENV}
26+
- name: Environment Printer
27+
uses: managedkaos/print-env@v1.0
28+
2129
- uses: wangyoucao577/go-release-action@v1
2230
with:
2331
github_token: ${{ secrets.GITHUB_TOKEN }}
2432
goos: ${{ matrix.goos }}
2533
goarch: ${{ matrix.goarch }}
2634
project_path: "./app/main"
2735
binary_name: "git-webhook-receiver"
28-
extra_files: LICENSE README.md
36+
extra_files: config.json.example LICENSE README.md
37+
ldflags: -X "main.version=${{ env.APP_VERSION }}" -X "main.buildTime=${{ env.BUILD_TIME }}" -X main.gitCommit=${{ github.sha }}

app/main/main.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"flag"
56
"fmt"
67
"net/http"
78
"os"
@@ -21,9 +22,25 @@ import (
2122
goLoggerEchoMiddlerware "github.com/pobyzaarif/go-logger/rest/framework/echo/v4/middleware"
2223
)
2324

24-
var logger = goLogger.NewLog("MAIN")
25+
var (
26+
logger = goLogger.NewLog("MAIN")
27+
28+
version string
29+
buildTime string
30+
gitCommit string
31+
)
2532

2633
func main() {
34+
v := flag.Bool("v", false, "print version info")
35+
flag.Parse()
36+
37+
if *v {
38+
fmt.Println("Version: " + version)
39+
fmt.Println("Build time: " + buildTime)
40+
fmt.Println("Git commit: " + gitCommit)
41+
return
42+
}
43+
2744
conf := config.LoadConfig("./config.json")
2845

2946
e := echo.New()

0 commit comments

Comments
 (0)