Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
liewstar committed Jan 11, 2025
1 parent 2e3fcb6 commit 279ea38
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5

- name: Get Casbin version from go.mod
id: go-mod-version
run: |
version=$(go list -m -json github.com/casbin/casbin/v2 | jq -r .Version)
echo "version=$version" >> $GITHUB_OUTPUT
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
Expand All @@ -52,3 +58,4 @@ jobs:
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CASBIN_VERSION: ${{ steps.go-mod-version.outputs.version }}
1 change: 1 addition & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ builds:
- -X {{ .ModulePath }}/cmd.BuildTime={{.Date}}
- -X {{ .ModulePath }}/cmd.GitHash={{.FullCommit}}
- -X {{ .ModulePath }}/cmd.GitTag={{.Tag}}
- -X {{ .ModulePath }}/cmd.CasbinVersion={{.Env.CASBIN_VERSION}}

archives:
- format: tar.gz
Expand Down
24 changes: 3 additions & 21 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,23 @@ package cmd

import (
"fmt"
"os"
"strings"

"github.com/spf13/cobra"
)

var (
Version = "dev"
Version = "dev"
CasbinVersion = "dev"
)

func getCasbinVersion() string {
data, err := os.ReadFile("go.mod")
if err != nil {
return "dev"
}

for _, line := range strings.Split(string(data), "\n") {
if strings.Contains(line, "github.com/casbin/casbin/v2") {
parts := strings.Fields(line)
if len(parts) > 1 {
return parts[1]
}
}
}
return "dev"
}

func init() {
rootCmd.Flags().BoolP("version", "v", false, "Print version information")

oldRun := rootCmd.Run
rootCmd.Run = func(cmd *cobra.Command, args []string) {
if v, _ := cmd.Flags().GetBool("version"); v {
fmt.Printf("casbin-go-cli version: %s\n", Version)
fmt.Printf("casbin version: %s\n", getCasbinVersion())
fmt.Printf("casbin version: %s\n", CasbinVersion)
return
}
if oldRun != nil {
Expand Down

0 comments on commit 279ea38

Please sign in to comment.