Skip to content

Commit

Permalink
chore: add tag version to the binary
Browse files Browse the repository at this point in the history
go build -v -ldflags="-X main.version="
  • Loading branch information
bjarneo committed Nov 15, 2024
1 parent 6956d27 commit 38ea3dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
15 changes: 2 additions & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
name: Release Binaries

on:
push:
tags:
- 'v*'

permissions:
contents: write
packages: write

jobs:
build:
name: Build Binaries
Expand All @@ -32,29 +29,25 @@ jobs:
arch: arm64
goos: darwin
goarch: arm64

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
cache: true

- name: Build binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
go build -v -o copepod-${{ matrix.os }}-${{ matrix.arch }}
VERSION=${GITHUB_REF#refs/tags/}
go build -v -ldflags="-X main.version=${VERSION}" -o copepod-${{ matrix.os }}-${{ matrix.arch }}
chmod +x copepod-${{ matrix.os }}-${{ matrix.arch }}
- name: Generate SHA-256
run: |
sha256sum copepod-${{ matrix.os }}-${{ matrix.arch }} > copepod-${{ matrix.os }}-${{ matrix.arch }}.sha256
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
Expand All @@ -63,7 +56,6 @@ jobs:
copepod-${{ matrix.os }}-${{ matrix.arch }}
copepod-${{ matrix.os }}-${{ matrix.arch }}.sha256
retention-days: 1

release:
name: Create Release
needs: build
Expand All @@ -73,13 +65,11 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download all artifacts
uses: actions/download-artifact@v4
with:
pattern: binaries-*
merge-multiple: true

- name: Create Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -93,7 +83,6 @@ jobs:
echo '```' >> release_notes.md
cat *.sha256 >> release_notes.md
echo '```' >> release_notes.md
# Create release using gh cli
gh release create "$VERSION" \
--repo "$GITHUB_REPOSITORY" \
Expand Down
10 changes: 10 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import (
"time"
)

// This will be defined on build time
var version string

// Config holds the deployment configuration
type Config struct {
Host string `json:"host"`
Expand Down Expand Up @@ -144,6 +147,7 @@ func (i *arrayFlags) Set(value string) error {
func LoadConfig() Config {
var config Config
var showHelp bool
var showVersion bool
var buildArgs arrayFlags

// Initialize BuildArgs map
Expand All @@ -164,6 +168,7 @@ func LoadConfig() Config {
flag.Var(&buildArgs, "build-arg", "Build argument in KEY=VALUE format (can be specified multiple times)")
flag.BoolVar(&showHelp, "help", false, "Show help message")
flag.BoolVar(&config.Rollback, "rollback", false, "Rollback to previous version")
flag.BoolVar(&showVersion, "version", false, "Show version information")

// Custom usage message
flag.Usage = func() {
Expand All @@ -179,6 +184,11 @@ func LoadConfig() Config {
os.Exit(0)
}

if showVersion {
fmt.Printf("Copepod version %s\n", version)
os.Exit(0)
}

// Process build arguments from command line
for _, arg := range buildArgs {
parts := strings.SplitN(arg, "=", 2)
Expand Down

0 comments on commit 38ea3dc

Please sign in to comment.