Skip to content

Commit

Permalink
GoReleaser (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark authored Mar 20, 2023
1 parent 8bcb7e5 commit d93724f
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
5 changes: 5 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -53,6 +54,10 @@ var rootCmd = &cobra.Command{
Short: "OneLogin authentication CLI",
}

func SetVersion(v string) {
version = v
}

func Execute() {
cobra.CheckErr(rootCmd.Execute())
}
Expand Down
19 changes: 19 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -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)
}
13 changes: 13 additions & 0 deletions goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
project_name: onelogin-auth-cli

release:
prerelease: auto

builds:
- binary: onelogin-auth
goos:
- darwin
- linux
goarch:
- amd64
- arm64
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

0 comments on commit d93724f

Please sign in to comment.