File tree Expand file tree Collapse file tree 6 files changed +56
-27
lines changed
Expand file tree Collapse file tree 6 files changed +56
-27
lines changed Original file line number Diff line number Diff line change 1+ /yukid
2+ /yukictl
Original file line number Diff line number Diff line change @@ -12,25 +12,39 @@ concurrency:
1212
1313permissions :
1414 contents : write
15- # packages: write
16- # issues: write
15+ packages : write
1716
1817jobs :
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 :
Original file line number Diff line number Diff line change 11before :
22 hooks :
33 - go mod tidy
4- # TODO: publish docker images
5- # https://goreleaser.com/customization/docker/#how-it-works
64builds :
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}}
3621archives :
3722 - format : binary
3823checksum :
Original file line number Diff line number Diff line change 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" ]
Original file line number Diff line number Diff line change @@ -10,13 +10,25 @@ unit-test:
1010integration-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
1420yukid :
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
1827yukictl :
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
2133BUILD_IMAGE ?= golang:1.21-bookworm
2234
Original file line number Diff line number Diff line change @@ -7,14 +7,17 @@ import (
77var (
88 Version string
99 BuildDate string
10+ GitCommit string
1011)
1112
1213var 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}
You can’t perform that action at this time.
0 commit comments