Skip to content

Commit 94feecd

Browse files
authored
feat: update release workflow & corresponding config files (#49)
Signed-off-by: Jian Zeng <anonymousknight96@gmail.com>
1 parent 004e8ee commit 94feecd

File tree

6 files changed

+56
-27
lines changed

6 files changed

+56
-27
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/yukid
2+
/yukictl

.github/workflows/release.yml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,39 @@ concurrency:
1212

1313
permissions:
1414
contents: write
15-
# packages: write
16-
# issues: write
15+
packages: write
1716

1817
jobs:
19-
goreleaser:
18+
releaser:
2019
runs-on: ubuntu-latest
2120
steps:
2221
- uses: actions/checkout@v4
23-
with:
24-
fetch-depth: 0
25-
- run: git fetch --force --tags
22+
2623
- uses: actions/setup-go@v5
2724
with:
2825
go-version: stable
26+
27+
- name: Set up Docker Buildx
28+
uses: docker/setup-buildx-action@v2
29+
30+
- name: Log in to the Container registry
31+
uses: docker/login-action@v2
32+
with:
33+
registry: ghcr.io
34+
username: ${{ github.actor }}
35+
password: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Build and Push Image
38+
uses: docker/build-push-action@v3
39+
with:
40+
context: .
41+
push: true
42+
tags: ghcr.io/ustclug/yukid:${{ github.ref_name }}
43+
2944
# More assembly might be required: Docker logins, GPG, etc.
3045
# It all depends on your needs.
3146
- uses: goreleaser/goreleaser-action@v5
3247
with:
33-
distribution: goreleaser
3448
version: latest
3549
args: release --clean
3650
env:

.goreleaser.yaml

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
before:
22
hooks:
33
- go mod tidy
4-
# TODO: publish docker images
5-
# https://goreleaser.com/customization/docker/#how-it-works
64
builds:
5+
# NOTE: Currently, we cannot distribute yukid as a binary, because it requires CGO.
6+
# Instead, we distribute it as a Docker image. Please refer to the release workflow for more details.
77
-
88
id: yukictl
99
binary: yukictl
@@ -17,22 +17,7 @@ builds:
1717
flags:
1818
- -trimpath
1919
ldflags:
20-
- -s -w -X github.com/ustclug/Yuki/pkg/info.Version={{.Version}} -X github.com/ustclug/Yuki/pkg/info.BuildDate={{.Date}}
21-
-
22-
id: yukid
23-
binary: yukid
24-
main: ./cmd/yukid
25-
env:
26-
# required by sqlite
27-
- CGO_ENABLED=1
28-
goos:
29-
- linux
30-
goarch:
31-
- amd64
32-
flags:
33-
- -trimpath
34-
ldflags:
35-
- -s -w -X github.com/ustclug/Yuki/pkg/info.Version={{.Version}} -X github.com/ustclug/Yuki/pkg/info.BuildDate={{.Date}}
20+
- -s -w -X github.com/ustclug/Yuki/pkg/info.Version={{.Version}} -X github.com/ustclug/Yuki/pkg/info.BuildDate={{.Date}} -X github.com/ustclug/Yuki/pkg/info.GitCommit={{.Commit}}
3621
archives:
3722
- format: binary
3823
checksum:

Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# syntax=docker/dockerfile:1
2+
3+
FROM golang:1.21-bookworm AS build
4+
WORKDIR /app
5+
RUN --mount=type=cache,target=/root/.cache/go-build \
6+
--mount=type=cache,target=/go/pkg/mod \
7+
--mount=type=bind,target=/app \
8+
OUT_DIR=/tmp make yukid
9+
10+
FROM debian:bookworm-slim
11+
RUN apt update && apt install -y sqlite3 && rm -rf /var/lib/apt/lists/*
12+
COPY --link --from=build /tmp/yukid /yukid
13+
CMD ["/yukid"]

Makefile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,25 @@ unit-test:
1010
integration-test:
1111
go test -v ./test/integration/...
1212

13+
git_commit := $(shell git rev-parse HEAD)
14+
build_date := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
15+
16+
VERSION ?= $(shell git describe --tags)
17+
OUT_DIR ?= $(PWD)
18+
1319
.PHONY: yukid
1420
yukid:
15-
go build -trimpath ./cmd/yukid
21+
go build -ldflags "-X github.com/ustclug/Yuki/pkg/info.BuildDate=$(build_date) \
22+
-X github.com/ustclug/Yuki/pkg/info.GitCommit=$(git_commit) \
23+
-X github.com/ustclug/Yuki/pkg/info.Version=$(VERSION)" \
24+
-trimpath -o $(OUT_DIR)/yukid ./cmd/yukid
1625

1726
.PHONY: yukictl
1827
yukictl:
19-
go build -trimpath ./cmd/yukictl
28+
go build -ldflags "-X github.com/ustclug/Yuki/pkg/info.BuildDate=$(build_date) \
29+
-X github.com/ustclug/Yuki/pkg/info.GitCommit=$(git_commit) \
30+
-X github.com/ustclug/Yuki/pkg/info.Version=$(version)" \
31+
-trimpath ./cmd/yukictl
2032

2133
BUILD_IMAGE ?= golang:1.21-bookworm
2234

pkg/info/info.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ import (
77
var (
88
Version string
99
BuildDate string
10+
GitCommit string
1011
)
1112

1213
var VersionInfo = struct {
1314
Version string
1415
GoVersion string
1516
BuildDate string
17+
GitCommit string
1618
}{
1719
Version: Version,
1820
BuildDate: BuildDate,
21+
GitCommit: GitCommit,
1922
GoVersion: runtime.Version(),
2023
}

0 commit comments

Comments
 (0)