Skip to content

Commit

Permalink
chore: include version information
Browse files Browse the repository at this point in the history
  • Loading branch information
damonto committed Apr 2, 2024
1 parent 556ab16 commit 16f0733
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ on:

jobs:
build:
name: Build for ${{ matrix.build.name }}
name: Build for ${{ matrix.target.name }}
runs-on: ubuntu-latest
strategy:
matrix:
build:
target:
- { os: linux, arch: amd64, name: Linux AMD64 }
- { os: linux, arch: arm64, name: Linux ARM64 }
- { os: darwin, arch: amd64, name: macOS AMD64 }
Expand All @@ -30,14 +30,15 @@ jobs:
with:
go-version: 1.22
id: go
- name: Build for ${{ matrix.build.name }}
- name: Build for ${{ matrix.target.name }}
run: |
CGO_ENABLED=0 GOOS=${{ matrix.build.os }} GOARCH=${{ matrix.build.arch }} go build -trimpath -ldflags="-w -s" -o estkme-cloud-${{ matrix.build.os }}-${{ matrix.build.arch }}
- name: Upload ${{ matrix.build.name }} to Artifact
VERSION=$(git describe --always --tags --match "v*" --dirty="-dev")
CGO_ENABLED=0 GOOS=${{ matrix.target.os }} GOARCH=${{ matrix.target.arch }} go build -trimpath -ldflags="-w -s -X main.Version=${VERSION}" -o estkme-cloud-${{ matrix.target.os }}-${{ matrix.target.arch }}
- name: Upload ${{ matrix.target.name }} to Artifact
uses: actions/upload-artifact@v4
with:
name: estkme-cloud-${{ matrix.build.os }}-${{ matrix.build.arch }}
path: estkme-cloud-${{ matrix.build.os }}-${{ matrix.build.arch }}
name: estkme-cloud-${{ matrix.target.os }}-${{ matrix.target.arch }}
path: estkme-cloud-${{ matrix.target.os }}-${{ matrix.target.arch }}

release:
name: Release
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ WORKDIR /app
COPY . .

RUN set -ex \
&& apk add --no-cache git \
&& go mod download \
&& go build -trimpath -ldflags="-w -s" -o estkme-cloud main.go
&& VERSION=$(git describe --always --tags --match "v*" --dirty="-dev") \
&& go build -trimpath -ldflags="-w -s -X main.Version=${VERSION}" -o estkme-cloud main.go

FROM alpine:latest

Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/damonto/estkme-cloud/internal/lpac"
)

var Version string

func init() {
cwd, _ := os.Getwd()
flag.StringVar(&config.C.ListenAddress, "listen-address", ":1888", "eSTK.me cloud server listen address")
Expand All @@ -22,6 +24,7 @@ func init() {
}

func main() {
slog.Info("eSTK.me cloud server", "version", Version)
if err := config.C.IsValid(); err != nil {
slog.Error("invalid configuration", "error", err)
os.Exit(1)
Expand Down

0 comments on commit 16f0733

Please sign in to comment.