From ec3f06337085a75ce05c58360929119fa9d9c282 Mon Sep 17 00:00:00 2001 From: Thomas Biesaart Date: Sat, 23 Apr 2022 09:13:40 +0200 Subject: [PATCH 1/5] Add --version flag --- cmd/git-backup/main.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmd/git-backup/main.go b/cmd/git-backup/main.go index 037147e..7130ba4 100644 --- a/cmd/git-backup/main.go +++ b/cmd/git-backup/main.go @@ -6,6 +6,7 @@ import ( "log" "os" "path/filepath" + "runtime" "time" ) @@ -13,10 +14,21 @@ var configFilePath = flag.String("config.file", "git-backup.yml", "The path to y var targetPath = flag.String("backup.path", "backup", "The target path to the backup folder.") var failAtEnd = flag.Bool("backup.fail-at-end", false, "Fail at the end of backing up repositories, rather than right away.") var bareClone = flag.Bool("backup.bare-clone", false, "Make bare clones without checking out the main branch.") +var printVersion = flag.Bool("version", false, "Show the version number and exit.") + +var Version = "dev" +var CommitHash = "n/a" +var BuildTimestamp = "n/a" func main() { flag.Parse() + if *printVersion { + log.Printf("git-backup, version %s (%s-%s)", Version, runtime.GOOS, runtime.GOARCH) + log.Printf("Built %s (%s)", CommitHash, BuildTimestamp) + os.Exit(0) + } + config := loadConfig() sources := config.GetSources() if len(sources) == 0 { From ce921b91079755a6673ae5381151d9cbedb6101a Mon Sep 17 00:00:00 2001 From: Thomas Biesaart Date: Sat, 23 Apr 2022 09:18:24 +0200 Subject: [PATCH 2/5] Add build time parameters --- .github/workflows/build.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a79df29..da475c9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,7 +42,15 @@ jobs: - uses: actions/setup-go@v2 with: go-version: '^1.17.8' - - run: ${{ matrix.goopts }} go build -o ${{ matrix.filename }} ./cmd/git-backup + - run: > + ${{ matrix.goopts }} go build + -o ${{ matrix.filename }} + ./cmd/git-backup + -ldflags=" + -X 'main.Version=${GITHUB_REF##*/}' + -X 'main.CommitHash=${GITHUB_SHA}' + -X 'main.BuildTimestamp=$(date)' + " env: GOOS: ${{ matrix.goos }} GOARCH: ${{ matrix.goarch }} From a322e338ff1ce1cbc40163c6d1ebb64314046811 Mon Sep 17 00:00:00 2001 From: Thomas Biesaart Date: Sat, 23 Apr 2022 09:20:40 +0200 Subject: [PATCH 3/5] All options on one line --- .github/workflows/build.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index da475c9..ab952c6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,15 +42,7 @@ jobs: - uses: actions/setup-go@v2 with: go-version: '^1.17.8' - - run: > - ${{ matrix.goopts }} go build - -o ${{ matrix.filename }} - ./cmd/git-backup - -ldflags=" - -X 'main.Version=${GITHUB_REF##*/}' - -X 'main.CommitHash=${GITHUB_SHA}' - -X 'main.BuildTimestamp=$(date)' - " + - run: ${{ matrix.goopts }} go build -o ${{ matrix.filename }} ./cmd/git-backup -ldflags="-X 'main.Version=${GITHUB_REF##*/}' -X 'main.CommitHash=${GITHUB_SHA}' -X 'main.BuildTimestamp=$(date)'" env: GOOS: ${{ matrix.goos }} GOARCH: ${{ matrix.goarch }} From 4b190ac17aacb84f3c30f0f3d8ebefc05c3712bb Mon Sep 17 00:00:00 2001 From: Thomas Biesaart Date: Sat, 23 Apr 2022 09:22:08 +0200 Subject: [PATCH 4/5] Reorder build args --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ab952c6..c5c6070 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,7 +42,7 @@ jobs: - uses: actions/setup-go@v2 with: go-version: '^1.17.8' - - run: ${{ matrix.goopts }} go build -o ${{ matrix.filename }} ./cmd/git-backup -ldflags="-X 'main.Version=${GITHUB_REF##*/}' -X 'main.CommitHash=${GITHUB_SHA}' -X 'main.BuildTimestamp=$(date)'" + - 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 env: GOOS: ${{ matrix.goos }} GOARCH: ${{ matrix.goarch }} From 6d1c114c803871470b3c2066987df7c0189943e6 Mon Sep 17 00:00:00 2001 From: Thomas Biesaart Date: Sat, 23 Apr 2022 09:27:43 +0200 Subject: [PATCH 5/5] Document version flag --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0870214..ce4eab7 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,9 @@ Options: -backup.fail-at-end Fail at the end of backing up repositories, rather than right away. -backup.bare-clone - Make bare clones without checking out the main branch. + Make bare clones without checking out the main branch. + -version + Show the version number and exit. ``` ## Usage: Docker