Skip to content

Commit 4f10693

Browse files
authored
Add --version flag to get version and build information (#11)
1 parent 290a124 commit 4f10693

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
- uses: actions/setup-go@v2
4343
with:
4444
go-version: '^1.17.8'
45-
- run: ${{ matrix.goopts }} go build -o ${{ matrix.filename }} ./cmd/git-backup
45+
- run: ${{ matrix.goopts }} go build -o ${{ matrix.filename }} -ldflags="-X 'main.Version=${GITHUB_REF##*/}' -X 'main.CommitHash=${GITHUB_SHA}' -X 'main.BuildTimestamp=$(date)'" ./cmd/git-backup
4646
env:
4747
GOOS: ${{ matrix.goos }}
4848
GOARCH: ${{ matrix.goarch }}

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ Options:
7979
-backup.fail-at-end
8080
Fail at the end of backing up repositories, rather than right away.
8181
-backup.bare-clone
82-
Make bare clones without checking out the main branch.
82+
Make bare clones without checking out the main branch.
83+
-version
84+
Show the version number and exit.
8385
```
8486

8587
## Usage: Docker

cmd/git-backup/main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,29 @@ import (
66
"log"
77
"os"
88
"path/filepath"
9+
"runtime"
910
"time"
1011
)
1112

1213
var configFilePath = flag.String("config.file", "git-backup.yml", "The path to your config file.")
1314
var targetPath = flag.String("backup.path", "backup", "The target path to the backup folder.")
1415
var failAtEnd = flag.Bool("backup.fail-at-end", false, "Fail at the end of backing up repositories, rather than right away.")
1516
var bareClone = flag.Bool("backup.bare-clone", false, "Make bare clones without checking out the main branch.")
17+
var printVersion = flag.Bool("version", false, "Show the version number and exit.")
18+
19+
var Version = "dev"
20+
var CommitHash = "n/a"
21+
var BuildTimestamp = "n/a"
1622

1723
func main() {
1824
flag.Parse()
1925

26+
if *printVersion {
27+
log.Printf("git-backup, version %s (%s-%s)", Version, runtime.GOOS, runtime.GOARCH)
28+
log.Printf("Built %s (%s)", CommitHash, BuildTimestamp)
29+
os.Exit(0)
30+
}
31+
2032
config := loadConfig()
2133
sources := config.GetSources()
2234
if len(sources) == 0 {

0 commit comments

Comments
 (0)