Skip to content

Commit

Permalink
Generate build version for non-release builds too
Browse files Browse the repository at this point in the history
  • Loading branch information
samuong committed Jul 22, 2024
1 parent a2ba335 commit 3d1868d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ jobs:
echo SDKROOT=$(xcrun --sdk macosx --show-sdk-path) >> $GITHUB_ENV
- run: |
go generate
go build -v .
env:
GOOS: ${{ matrix.target.goos }}
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ jobs:
runs-on: ubuntu-latest

outputs:
version: ${{ steps.get_version.outputs.version }}
upload_url: ${{ steps.create_release.outputs.upload_url }}

steps:
Expand All @@ -25,9 +24,6 @@ jobs:
prerelease: false
id: create_release

- id: get_version
run: echo ::set-output name=version::${GITHUB_REF/refs\/tags\//}

build:
strategy:
matrix:
Expand Down Expand Up @@ -62,7 +58,9 @@ jobs:
run: |
echo SDKROOT=$(xcrun --sdk macosx --show-sdk-path) >> $GITHUB_ENV
- run: go build -v -o ${{ matrix.target.goos }}-${{ matrix.target.goarch }} -ldflags="-X 'main.BuildVersion=${{ needs.release.outputs.version }}'" .
- run: |
go generate
go build -v -o ${{ matrix.target.goos }}-${{ matrix.target.goarch }} .
env:
GOOS: ${{ matrix.target.goos }}
GOARCH: ${{ matrix.target.goarch }}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/alpaca
.idea
.idea
version.txt
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package main

import (
"crypto/tls"
_ "embed"
"flag"
"fmt"
"log"
Expand All @@ -26,6 +27,8 @@ import (
"strconv"
)

//go:generate sh -c "echo -n $(git describe --tags) >version.txt"
//go:embed version.txt

Check failure on line 31 in main.go

View workflow job for this annotation

GitHub Actions / lint

invalid go:embed: build system did not supply embed configuration (typecheck)

Check failure on line 31 in main.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-20.04, 1.22)

pattern version.txt: no matching files found
var BuildVersion string

func whoAmI() string {
Expand Down

0 comments on commit 3d1868d

Please sign in to comment.