Skip to content

Commit

Permalink
VERSION ファイルを導入して Makefile を整理する
Browse files Browse the repository at this point in the history
  • Loading branch information
voluntas committed Sep 8, 2023
1 parent 9e8420d commit 1f251be
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 38 deletions.
21 changes: 4 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
VERSION := 2023.1.0
REVISION := $(shell git rev-parse --short HEAD)
BUILD_DATE := $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
LDFLAGS := "-X main.version=$(VERSION) -X main.revision=$(REVISION) -X main.buildDate=$(BUILD_DATE)"
LDFLAGS_PROD := "-s -w -X main.version=$(VERSION) -X main.revision=$(REVISION)"
.PHONY: all test

export GO1111MODULE=on
export CWD=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))

.PHONY: all sora-archive-uploader-dev sora-archive-uploader-prod
all: sora-archive-uploader-dev

sora-archive-uploader-dev: cmd/sora-archive-uploader/main.go
go build -race -ldflags $(LDFLAGS) -o bin/$@ $<

sora-archive-uploader-prod: cmd/sora-archive-uploader/main.go
go build -ldflags $(LDFLAGS_PROD) -o bin/$@ $<
all:
go build -o bin/sora-archive-uploader cmd/sora-archive-uploader/main.go

test:
go test -v ./s3
go test -race -v ./s3
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023.1.0
28 changes: 8 additions & 20 deletions cmd/sora-archive-uploader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,23 @@ import (
"flag"
"fmt"
"log"
"os"

archive "github.com/shiguredo/sora-archive-uploader"
)

var (
version string
revision string
buildDate string

versionText = `sora-archive-uploader build info.
version: %s
revision: %s
build date: %s
`
)

func main() {
configFilePath := flag.String("C", "config.ini", "Config file path")
var v bool
flag.BoolVar(&v, "version", false, "Show version")
// /bin/sora-archive-uploader -V
showVersion := flag.Bool("V", false, "バージョン")

// /bin/sora-archive-uploader -C ./config.ini
configFilePath := flag.String("C", "./config.ini", "Config file path")
flag.Parse()

if v {
fmt.Printf(versionText, version, revision, buildDate)
os.Exit(0)
if *showVersion {
fmt.Printf("Sora Archive Uploader version %s\n", archive.Version)
return
}

log.Printf("sora-archive-uploader version:%s revision:%s build_date:%s", version, revision, buildDate)
log.Printf("config file path: %s", *configFilePath)
archive.Run(configFilePath)
}
9 changes: 8 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package archive

import "gopkg.in/ini.v1"
import (
_ "embed"

"gopkg.in/ini.v1"
)

//go:embed VERSION
var Version string

const (
DefaultLogDir = "."
Expand Down

0 comments on commit 1f251be

Please sign in to comment.