Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
Trying to get some version info
Browse files Browse the repository at this point in the history
  • Loading branch information
jadudm committed Mar 2, 2024
1 parent 8604b9f commit 1c16024
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 17 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/build_go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
name: Build gov.gsa.fac.backups

env:
GO_VERSION: '1.20'
GO_VERSION: '1.22'

on:
push:
Expand Down Expand Up @@ -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 ./...
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: linux
goarch: amd64
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
21 changes: 9 additions & 12 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Copyright © 2024 NAME HERE <EMAIL ADDRESS>
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
Expand All @@ -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)
}
},
}
)

Expand All @@ -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")
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down

0 comments on commit 1c16024

Please sign in to comment.