diff --git a/.github/workflows/build_go.yaml b/.github/workflows/build_go.yaml index 2eb8104..ab6503b 100644 --- a/.github/workflows/build_go.yaml +++ b/.github/workflows/build_go.yaml @@ -4,7 +4,7 @@ name: Build gov.gsa.fac.backups env: - GO_VERSION: '1.20' + GO_VERSION: '1.22' on: push: @@ -32,9 +32,16 @@ jobs: go get github.com/spf13/cobra go get github.com/spf13/viper go get github.com/tidwall/gjson - + + - name: Set outputs + id: vars + run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + + - name: Check outputs + run: echo ${{ steps.vars.outputs.sha_short }} + - name: Build - run: go build -v ./... + run: go build -ldflags "-X main.sha=${{steps.vars.outputs.sha_short}}" -v ./... - name: Test run: go test -v ./... diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 9e9b361..4c03123 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -20,4 +20,7 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} goos: linux - goarch: amd64 \ No newline at end of file + goarch: amd64 + goversion: "https://go.dev/dl/go1.22.0.linux-amd64.tar.gz" + binary_name: "gov.gsa.fac.backups" + extra_files: LICENSE README.md \ No newline at end of file diff --git a/cmd/root.go b/cmd/root.go index 17b1d11..228578f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -4,6 +4,7 @@ Copyright © 2024 NAME HERE package cmd import ( + "fmt" "os" "github.com/spf13/cobra" @@ -13,15 +14,19 @@ var ( SourceDB string DestinationDB string DestinationBucket string + SHA1 string // rootCmd represents the base command when called without any subcommands rootCmd = &cobra.Command{ Use: "backups", Short: "A tool for backing up, testing, and restoring", Long: ``, - // Uncomment the following line if your bare application - // has an action associated with it: - // Run: func(cmd *cobra.Command, args []string) { }, + Run: func(cmd *cobra.Command, args []string) { + ver, _ := cmd.Flags().GetBool("sha") + if ver { + fmt.Println(SHA1) + } + }, } ) @@ -35,13 +40,5 @@ func Execute() { } func init() { - // Here you will define your flags and configuration settings. - // Cobra supports persistent flags, which, if defined here, - // will be global for your application. - - // rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.gov.gsa.fac.backups.yaml)") - - // Cobra also supports local flags, which will only run - // when this action is called directly. - rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + rootCmd.Flags().BoolP("sha", "s", false, "Print short build SHA") } diff --git a/go.mod b/go.mod index 8a7b047..2091d3f 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.20 require github.com/bitfield/script v0.22.0 require ( + github.com/carlmjohnson/versioninfo v0.22.5 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect diff --git a/go.sum b/go.sum index f42d2f7..79271df 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/bitfield/script v0.22.0 h1:LA7QHuEsXMPD52YLtxWrlqCCy+9FOpzNYfsRHC5Gsrc= github.com/bitfield/script v0.22.0/go.mod h1:ms4w+9B8f2/W0mbsgWDVTtl7K94bYuZc3AunnJC4Ebs= +github.com/carlmjohnson/versioninfo v0.22.5 h1:O00sjOLUAFxYQjlN/bzYTuZiS0y6fWDQjMRvwtKgwwc= +github.com/carlmjohnson/versioninfo v0.22.5/go.mod h1:QT9mph3wcVfISUKd0i9sZfVrPviHuSF+cUtLjm2WSf8= github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= diff --git a/main.go b/main.go index ac14190..3377865 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,8 @@ import ( "gov.gsa.fac.backups/internal/vcap" ) +var SHA1 string + // Useful documentation for people new to Go, and // related to modules in this command. // https://www.digitalocean.com/community/tutorials/how-to-use-the-cobra-package-in-go @@ -26,7 +28,9 @@ import ( // Looks for config.yaml in the same directory as the app. // Optionally, the config can be in `$HOME/.fac/config.yaml` func readConfig() { - + // Pass down the SHA + cmd.SHA1 = SHA1 + // Do the right thing in the right env. if slices.Contains([]string{"LOCAL", "TESTING"}, os.Getenv("ENV")) { // Locally, load the file from one of two places. viper.SetConfigName("config")