Skip to content

Commit b3a22ed

Browse files
committed
take version number from VCS info
1 parent 59dead2 commit b3a22ed

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

.github/workflows/build.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ name: build
22

33
on:
44
workflow_call:
5-
inputs:
6-
version:
7-
type: string
85

96
jobs:
107
static:
@@ -13,6 +10,9 @@ jobs:
1310
image: debian:bookworm-slim
1411
steps:
1512
- uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0
15+
fetch-tags: true
1616
- run: |
1717
apt-get update -qq
1818
apt-get install -y --no-install-recommends ca-certificates gcc libc6-dev
@@ -26,18 +26,18 @@ jobs:
2626
~/go/bin/staticcheck ./...
2727
go test ./... -failfast -vet off -tags netgo,sqlite_omit_load_extension,fts5 -race
2828
- run: |
29-
CGO_CFLAGS="-O2 -fomit-frame-pointer -ffunction-sections -fdata-sections -fmerge-all-constants" go build -tags netgo,sqlite_omit_load_extension,fts5 -ldflags "-w -s -linkmode external -extldflags '-static -Wl,--gc-sections' -X github.com/dimkr/tootik/buildinfo.Version=${{ inputs.version }}" -trimpath -o tootik-amd64 ./cmd/tootik
29+
CGO_CFLAGS="-O2 -fomit-frame-pointer -ffunction-sections -fdata-sections -fmerge-all-constants" go build -tags netgo,sqlite_omit_load_extension,fts5 -ldflags "-w -s -linkmode external -extldflags '-static -Wl,--gc-sections'" -trimpath -o tootik-amd64 ./cmd/tootik
3030
- run: |
3131
apt-get install -y gcc-aarch64-linux-gnu
32-
CGO_CFLAGS="-O2 -fomit-frame-pointer -ffunction-sections -fdata-sections -fmerge-all-constants" GOARCH=arm64 CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 go build -tags netgo,sqlite_omit_load_extension,fts5 -ldflags "-w -s -linkmode external -extldflags '-static -Wl,--gc-sections' -X github.com/dimkr/tootik/buildinfo.Version=${{ inputs.version }}" -trimpath -o tootik-arm64 ./cmd/tootik
32+
CGO_CFLAGS="-O2 -fomit-frame-pointer -ffunction-sections -fdata-sections -fmerge-all-constants" GOARCH=arm64 CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 go build -tags netgo,sqlite_omit_load_extension,fts5 -ldflags "-w -s -linkmode external -extldflags '-static -Wl,--gc-sections'" -trimpath -o tootik-arm64 ./cmd/tootik
3333
- run: |
3434
apt-get install -y gcc-arm-linux-gnueabihf
35-
CGO_CFLAGS="-O2 -fomit-frame-pointer -ffunction-sections -fdata-sections -fmerge-all-constants" GOARCH=arm CC=arm-linux-gnueabihf-gcc CGO_ENABLED=1 go build -tags netgo,sqlite_omit_load_extension,fts5 -ldflags "-w -s -linkmode external -extldflags '-static -Wl,--gc-sections' -X github.com/dimkr/tootik/buildinfo.Version=${{ inputs.version }}" -trimpath -o tootik-arm ./cmd/tootik
35+
CGO_CFLAGS="-O2 -fomit-frame-pointer -ffunction-sections -fdata-sections -fmerge-all-constants" GOARCH=arm CC=arm-linux-gnueabihf-gcc CGO_ENABLED=1 go build -tags netgo,sqlite_omit_load_extension,fts5 -ldflags "-w -s -linkmode external -extldflags '-static -Wl,--gc-sections'" -trimpath -o tootik-arm ./cmd/tootik
3636
- run: |
3737
apt-get install -y gcc-multilib
38-
CGO_CFLAGS="-O2 -fomit-frame-pointer -ffunction-sections -fdata-sections -fmerge-all-constants" GOARCH=386 CGO_ENABLED=1 go build -tags netgo,sqlite_omit_load_extension,fts5 -ldflags "-w -s -linkmode external -extldflags '-static -Wl,--gc-sections' -X github.com/dimkr/tootik/buildinfo.Version=${{ inputs.version }}" -trimpath -o tootik-386 ./cmd/tootik
38+
CGO_CFLAGS="-O2 -fomit-frame-pointer -ffunction-sections -fdata-sections -fmerge-all-constants" GOARCH=386 CGO_ENABLED=1 go build -tags netgo,sqlite_omit_load_extension,fts5 -ldflags "-w -s -linkmode external -extldflags '-static -Wl,--gc-sections'" -trimpath -o tootik-386 ./cmd/tootik
3939
- uses: actions/upload-artifact@v4
4040
with:
41-
name: tootik-${{ inputs.version }}
41+
name: tootik-${{ github.ref_name }}
4242
path: tootik-*
4343
retention-days: 1

.github/workflows/ci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,3 @@ on:
1010
jobs:
1111
build:
1212
uses: ./.github/workflows/build.yml
13-
with:
14-
version: 99.99.${{ github.run_number }}

.github/workflows/release.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ on:
88
jobs:
99
build:
1010
uses: ./.github/workflows/build.yml
11-
with:
12-
version: ${{ github.ref_name }}
1311
upload:
1412
needs: build
1513
runs-on: ubuntu-latest

Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ RUN go generate ./migrations
2323
COPY . /src
2424
RUN go vet ./...
2525
RUN go test ./... -failfast -vet off -tags fts5
26-
ARG TOOTIK_VERSION=?
27-
RUN go build -ldflags "-X github.com/dimkr/tootik/buildinfo.Version=$TOOTIK_VERSION" -tags fts5 ./cmd/tootik
26+
RUN go build -tags fts5 ./cmd/tootik
2827

2928
FROM alpine
3029
RUN apk add --no-cache ca-certificates openssl

buildinfo/version.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2023 Dima Krasner
2+
Copyright 2023 - 2025 Dima Krasner
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -16,4 +16,17 @@ limitations under the License.
1616

1717
package buildinfo
1818

19+
import (
20+
"regexp"
21+
"runtime/debug"
22+
)
23+
1924
var Version = "?"
25+
26+
func init() {
27+
if info, ok := debug.ReadBuildInfo(); ok {
28+
if ver := regexp.MustCompile(`^v(\d+\.\d+\.\d+).*`).FindStringSubmatch(info.Main.Version); ver != nil {
29+
Version = ver[1]
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)