From 9cf42af251bf1ca368c6f7c6f47e51d20aac69a2 Mon Sep 17 00:00:00 2001 From: Emmm Monster <58943012+emmmx@users.noreply.github.com> Date: Sun, 16 May 2021 12:30:48 +0800 Subject: [PATCH] Use git tag as version --- .github/workflows/build.yml | 12 +++++++----- cmd/um/main.go | 4 +++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5c2eafe..56b0eec 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,11 +22,11 @@ jobs: os: [ windows-latest, ubuntu-latest, macos-latest ] include: - os: ubuntu-latest - BIN_SUFFIX: + BIN_SUFFIX: "" - os: macos-latest - BIN_SUFFIX: + BIN_SUFFIX: "" - os: windows-latest - BIN_SUFFIX: .exe + BIN_SUFFIX: ".exe" steps: - name: Checkout codebase uses: actions/checkout@v2 @@ -38,12 +38,14 @@ jobs: - name: Setup vars id: vars - run: echo "::set-output name=short_sha::$(git rev-parse --short HEAD)" + run: | + echo "::set-output name=short_sha::$(git rev-parse --short HEAD)" + echo "::set-output name=git_tag::$(git describe --tags)" - name: Build env: CGO_ENABLED: 0 - run: go build -trimpath -ldflags="-w -s" -v -o um-${{ runner.os }}${{ matrix.BIN_SUFFIX }} ./cmd/um + run: go build -trimpath -ldflags="-w -s -X main.AppVersion=${{ steps.vars.outputs.git_tag }}" -v -o um-${{ runner.os }}${{ matrix.BIN_SUFFIX }} ./cmd/um - name: Publish artifact uses: actions/upload-artifact@v2 diff --git a/cmd/um/main.go b/cmd/um/main.go index efedbe4..d8219b9 100644 --- a/cmd/um/main.go +++ b/cmd/um/main.go @@ -18,12 +18,14 @@ import ( "strings" ) +var AppVersion = "0.0.3" + func main() { app := cli.App{ Name: "Unlock Music CLI", HelpName: "um", Usage: "Unlock your encrypted music file https://github.com/unlock-music/cli", - Version: "v0.0.1", + Version: AppVersion, Flags: []cli.Flag{ &cli.StringFlag{Name: "input", Aliases: []string{"i"}, Usage: "path to input file or dir", Required: true}, &cli.StringFlag{Name: "output", Aliases: []string{"o"}, Usage: "path to output dir", Required: true},