Skip to content

Commit

Permalink
feat: add version to release asset names
Browse files Browse the repository at this point in the history
  • Loading branch information
suxb201 committed Dec 12, 2024
1 parent 770fe60 commit d12f61f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 12 deletions.
25 changes: 17 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ name: Release
on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Allows the workflow to be triggered by a tag
push:
tags:
- 'v*.*.*'

jobs:
build:
Expand All @@ -18,21 +22,26 @@ jobs:
with:
go-version-file: go.mod

- name: Build
run: bash build.sh dist

- name: "Draft release"
id: "release"
uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build
run: |
VERSION=${{ steps.release.outputs.tag_name }}
COMMIT=${GITHUB_SHA::8}
export VERSION COMMIT
bash build.sh dist
- name: "Upload release linux-amd64"
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.release.outputs.upload_url }}
asset_path: ./bin/redis-shake-linux-amd64.tar.gz
asset_name: redis-shake-linux-amd64.tar.gz
asset_name: redis-shake-${{ steps.release.outputs.tag_name }}-linux-amd64.tar.gz
asset_content_type: application/gzip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -42,7 +51,7 @@ jobs:
with:
upload_url: ${{ steps.release.outputs.upload_url }}
asset_path: ./bin/redis-shake-linux-arm64.tar.gz
asset_name: redis-shake-linux-arm64.tar.gz
asset_name: redis-shake-${{ steps.release.outputs.tag_name }}-linux-arm64.tar.gz
asset_content_type: application/gzip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -52,7 +61,7 @@ jobs:
with:
upload_url: ${{ steps.release.outputs.upload_url }}
asset_path: ./bin/redis-shake-darwin-amd64.tar.gz
asset_name: redis-shake-darwin-amd64.tar.gz
asset_name: redis-shake-${{ steps.release.outputs.tag_name }}-darwin-amd64.tar.gz
asset_content_type: application/gzip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -62,7 +71,7 @@ jobs:
with:
upload_url: ${{ steps.release.outputs.upload_url }}
asset_path: ./bin/redis-shake-darwin-arm64.tar.gz
asset_name: redis-shake-darwin-arm64.tar.gz
asset_name: redis-shake-${{ steps.release.outputs.tag_name }}-darwin-arm64.tar.gz
asset_content_type: application/gzip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -72,7 +81,7 @@ jobs:
with:
upload_url: ${{ steps.release.outputs.upload_url }}
asset_path: ./bin/redis-shake-windows-amd64.tar.gz
asset_name: redis-shake-windows-amd64.tar.gz
asset_name: redis-shake-${{ steps.release.outputs.tag_name }}-windows-amd64.tar.gz
asset_content_type: application/gzip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -82,7 +91,7 @@ jobs:
with:
upload_url: ${{ steps.release.outputs.upload_url }}
asset_path: ./bin/redis-shake-windows-arm64.tar.gz
asset_name: redis-shake-windows-arm64.tar.gz
asset_name: redis-shake-${{ steps.release.outputs.tag_name }}-windows-arm64.tar.gz
asset_content_type: application/gzip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12 changes: 8 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ mkdir -p "$BIN_DIR"

cp shake.toml "$BIN_DIR"

VERSION=${VERSION:-"dev"}
COMMIT=${COMMIT:-$(git rev-parse --short HEAD)}
LDFLAGS=${LDFLAGS:-"-X main.Version=${VERSION} -X main.GitCommit=${COMMIT}"}

dist() {
echo "try build GOOS=$1 GOARCH=$2"
export GOOS=$g
export GOARCH=$a
export GOOS=$1
export GOARCH=$2
export CGO_ENABLED=0
go build -v -trimpath -o "$BIN_DIR/redis-shake" "./cmd/redis-shake"
go build -v -trimpath -ldflags "${LDFLAGS}" -o "$BIN_DIR/redis-shake" "./cmd/redis-shake"
unset GOOS
unset GOARCH
echo "build success GOOS=$1 GOARCH=$2"
Expand All @@ -35,5 +39,5 @@ fi

# build the current platform
echo "try build for current platform"
go build -v -trimpath -o "$BIN_DIR/redis-shake" "./cmd/redis-shake"
go build -v -trimpath -ldflags "${LDFLAGS}" -o "$BIN_DIR/redis-shake" "./cmd/redis-shake"
echo "build success"
22 changes: 22 additions & 0 deletions cmd/redis-shake/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,32 @@ import (
"RedisShake/internal/utils"
"RedisShake/internal/writer"

"fmt"
"runtime"

"github.com/mcuadros/go-defaults"
)

var (
// These variables will be set during build time
Version = "unknown"
GitCommit = "unknown"
)

func getVersionString() string {
return fmt.Sprintf("%s %s/%s (Git SHA: %s)", Version, runtime.GOOS, runtime.GOARCH, GitCommit)
}

func main() {
// Add version flag check before config loading
if len(os.Args) == 2 && (os.Args[1] == "-v" || os.Args[1] == "--version" || os.Args[1] == "version") {
fmt.Printf("redis-shake version %s\n", getVersionString())
os.Exit(0)
}

// Add version info at startup
log.Infof("redis-shake version %s", getVersionString())

v := config.LoadConfig()

log.Init(config.Opt.Advanced.LogLevel, config.Opt.Advanced.LogFile, config.Opt.Advanced.Dir)
Expand Down

0 comments on commit d12f61f

Please sign in to comment.