diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a79df29..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 + - 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 }} 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 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 {