diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..48f125b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,39 @@ +name: Test And Release + +on: + push: + +jobs: + # -------- Test job -------- # + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v4 + + - name: Test + run: go test -v ./... + + # -------- Release job -------- # + release: + runs-on: ubuntu-latest + # Runs only if the event is a tag push. + # Tag name must start with "v" + if: startsWith(github.ref, 'refs/tags/v') + needs: test + steps: + - uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v4 + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v4.2.0 + with: + distribution: goreleaser + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GH_PAT }} diff --git a/cmd/root.go b/cmd/root.go index 38e5194..64d3228 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -45,6 +45,7 @@ func (a *Account) GetAppID(role string) string { return a.AppID } +var version string var config Config // rootCmd represents the base command when called without any subcommands @@ -53,6 +54,10 @@ var rootCmd = &cobra.Command{ Short: "OneLogin authentication CLI", } +func SetVersion(v string) { + version = v +} + func Execute() { cobra.CheckErr(rootCmd.Execute()) } diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..81c18d9 --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,19 @@ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Print the version number", + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("Version:", version) + }, +} + +func init() { + rootCmd.AddCommand(versionCmd) +} diff --git a/goreleaser.yml b/goreleaser.yml new file mode 100644 index 0000000..f62b875 --- /dev/null +++ b/goreleaser.yml @@ -0,0 +1,13 @@ +project_name: onelogin-auth-cli + +release: + prerelease: auto + +builds: + - binary: onelogin-auth + goos: + - darwin + - linux + goarch: + - amd64 + - arm64 diff --git a/main.go b/main.go index a1ddcbf..620d513 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,10 @@ import ( "onelogin-auth-cli/cmd" ) +// GoReleaser will set this value at build time +var version = "development" + func main() { + cmd.SetVersion(version) cmd.Execute() }