Skip to content

Commit

Permalink
Fix version linking for build
Browse files Browse the repository at this point in the history
  • Loading branch information
mass8326 committed Jul 26, 2024
1 parent e22f177 commit 27bd01d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ jobs:
run: |
version=$(echo ${{ github.ref_name }} | cut -dv -f2)
echo "version=$version" >> $GITHUB_OUTPUT
- run: go build -ldflags "-X main.version=${{ steps.version.outputs.version }}" -o "./build/${{ matrix.target.output }}"
- run: go build -ldflags "-X github.com/mass8326/imgchop/cmd.version=${{ steps.version.outputs.version }}" -o "./build/${{ matrix.target.output }}"
env:
GOOS: ${{ matrix.target.os }}
GOARCH: ${{ matrix.target.arch }}
- if: matrix.target.os == 'linux'
run: "[[ $(./build/imgchop --version) == '${{ steps.version.outputs.version }}' ]]"
- uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
Expand Down
6 changes: 3 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null || exit 1

version="v0.1.0"
version="0.0.0-dev"

echo "Building linux executable"
GOOS="linux" GOARCH="amd64" go build -ldflags "-X main.version=$version" -o "build/imgchop"
GOOS="linux" GOARCH="amd64" go build -ldflags "-X github.com/mass8326/imgchop/cmd.version=$version" -o "build/imgchop"

echo "Building windows executable"
GOOS="windows" GOARCH="amd64" go build -ldflags "-X main.version=$version" -o "build/imgchop.exe"
GOOS="windows" GOARCH="amd64" go build -ldflags "-X github.com/mass8326/imgchop/cmd.version=$version" -o "build/imgchop.exe"
3 changes: 2 additions & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (
"github.com/spf13/cobra"
)

var version = "[N/A]"
// This should be defined at build time using ldflags
var version = "0.0.0-invalid"

func Execute() {
var flags RootFlags
Expand Down

0 comments on commit 27bd01d

Please sign in to comment.