Skip to content

Commit 720d2e7

Browse files
committed
chore: fix the release config for static build
Signed-off-by: chlins <[email protected]>
1 parent ce0219d commit 720d2e7

File tree

3 files changed

+184
-4
lines changed

3 files changed

+184
-4
lines changed

.github/workflows/release-v2.yaml

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
release:
10+
strategy:
11+
matrix:
12+
include:
13+
# - goos: linux
14+
# goarch: amd64
15+
# runner: ubuntu-latest
16+
# - goos: linux
17+
# goarch: arm64
18+
# runner: ubuntu-24.04-arm
19+
- goos: darwin
20+
goarch: amd64
21+
runner: macos-13
22+
- goos: darwin
23+
goarch: arm64
24+
runner: macos-latest
25+
26+
runs-on: ${{ matrix.runner }}
27+
28+
steps:
29+
- name: Checkout code
30+
uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0
33+
34+
- name: Set up Go
35+
uses: actions/setup-go@v5
36+
with:
37+
go-version: '1.24' # Adjust to your Go version
38+
39+
- name: Install dependencies
40+
run: go mod download
41+
42+
43+
- name: Install CGO dependencies for Linux
44+
if: matrix.goos == 'linux'
45+
run: |
46+
sudo apt-get update
47+
sudo apt-get install -y pkg-config
48+
sudo apt update && \
49+
sudo DEBIAN_FRONTEND=noninteractive apt install -y build-essential cmake pkg-config libssl-dev libssh2-1-dev zlib1g-dev libhttp-parser-dev python3 wget tar git && \
50+
wget https://github.com/libgit2/libgit2/archive/refs/tags/v1.5.1.tar.gz -O libgit2-v1.5.1.tar.gz && \
51+
tar -xzf libgit2-v1.5.1.tar.gz && \
52+
cd libgit2-1.5.1 && \
53+
mkdir build && \
54+
cd build && \
55+
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF && \
56+
make -j$(nproc) && \
57+
sudo make install && \
58+
sudo ldconfig
59+
60+
- name: Install CGO dependencies for macOS
61+
if: matrix.goos == 'darwin'
62+
run: |
63+
brew install cmake wget zlib libiconv && \
64+
wget https://github.com/libgit2/libgit2/archive/refs/tags/v1.5.1.tar.gz -O libgit2-v1.5.1.tar.gz && \
65+
tar -xzf libgit2-v1.5.1.tar.gz && \
66+
cd libgit2-1.5.1 && \
67+
mkdir build && \
68+
cd build && \
69+
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF && \
70+
make -j$(nproc) && \
71+
sudo make install
72+
73+
- name: Build binary for linux
74+
if: matrix.goos == 'linux'
75+
env:
76+
CGO_ENABLED: 1
77+
GOOS: ${{ matrix.goos }}
78+
GOARCH: ${{ matrix.goarch }}
79+
run: |
80+
go build \
81+
-tags "static system_libgit2" \
82+
-ldflags "-X github.com/CloudNativeAI/modctl/pkg/version.GitVersion=${{ github.ref_name }} \
83+
-X github.com/CloudNativeAI/modctl/pkg/version.GitCommit=$(git rev-parse --short HEAD) \
84+
-X github.com/CloudNativeAI/modctl/pkg/version.BuildTime=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
85+
-extldflags '-static'" \
86+
-o build/modctl-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }} \
87+
main.go
88+
89+
# - name: Setup tmate session
90+
# uses: mxschmitt/action-tmate@v3
91+
# with:
92+
# limit-access-to-actor: false
93+
94+
- name: Build binary for macOS
95+
if: matrix.goos == 'darwin'
96+
env:
97+
CGO_ENABLED: 1
98+
GOOS: ${{ matrix.goos }}
99+
GOARCH: ${{ matrix.goarch }}
100+
CGO_LDFLAGS: "-lgit2 -lz -liconv -Wl,-rpath,/Users/runner/work/modctl/modctl/libgit2-1.5.1/build"
101+
run: |
102+
go build \
103+
-tags "static system_libgit2" \
104+
-ldflags "-X github.com/CloudNativeAI/modctl/pkg/version.GitVersion=${{ github.ref_name }} \
105+
-X github.com/CloudNativeAI/modctl/pkg/version.GitCommit=$(git rev-parse --short HEAD) \
106+
-X github.com/CloudNativeAI/modctl/pkg/version.BuildTime=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
107+
-o build/modctl-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }} \
108+
main.go
109+
110+
- name: Create archive
111+
run: |
112+
mkdir -p dist
113+
tar -czf dist/modctl-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz \
114+
-C build modctl-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }} \
115+
LICENSE README.md
116+
117+
# - name: Build deb/rpm packages
118+
# if: matrix.goos == 'linux'
119+
# uses: actions/setup-go@v5
120+
# with:
121+
# args: |
122+
# pack \
123+
# --packager nfpms \
124+
# --config <(echo '
125+
# name: modctl
126+
# arch: ${{ matrix.goarch }}
127+
# version: ${{ github.ref_name }}
128+
# maintainer: "Model Spec Maintainers <[email protected]>"
129+
# description: "A command line tool for managing artifact bundled based on the Model Format Specification"
130+
# license: "Apache 2.0"
131+
# formats:
132+
# - deb
133+
# - rpm
134+
# bindir: /usr/bin
135+
# files:
136+
# build/modctl-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }}: /usr/bin/modctl
137+
# build/package/docs/modctl.1: /usr/share/man/man1/modctl.1
138+
# LICENSE: /usr/share/doc/modctl/License
139+
# ') \
140+
# --output dist/
141+
142+
- name: Generate checksums
143+
run: |
144+
cd dist
145+
shasum -a 256 *.tar.gz *.deb *.rpm > checksums.txt
146+
continue-on-error: true # In case no deb/rpm files exist for macOS
147+
148+
- name: Upload artifacts
149+
uses: actions/upload-artifact@v4
150+
with:
151+
name: modctl-${{ matrix.goos }}-${{ matrix.goarch }}
152+
path: dist/
153+
154+
create-release:
155+
needs: release
156+
runs-on: ubuntu-latest
157+
steps:
158+
- name: Download all artifacts
159+
uses: actions/download-artifact@v4
160+
with:
161+
path: artifacts
162+
163+
- name: Create draft release
164+
uses: softprops/action-gh-release@v2
165+
with:
166+
draft: true
167+
files: |
168+
artifacts/**/modctl-*.tar.gz
169+
artifacts/**/modctl-*.deb
170+
artifacts/**/modctl-*.rpm
171+
artifacts/**/checksums.txt
172+
generate_release_notes: true
173+
env:
174+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ jobs:
3333
sudo apt-get update
3434
sudo apt-get install -y pkg-config
3535
sudo apt update && \
36-
sudo DEBIAN_FRONTEND=noninteractive apt install -y build-essential cmake pkg-config libssl-dev libssh2-1-dev zlib1g-dev libhttp-parser-dev python3 wget tar git && \
36+
sudo DEBIAN_FRONTEND=noninteractive apt install -y build-essential cmake pkg-config libssl-dev libssh2-1-dev zlib1g-dev libhttp-parser-dev python3 wget tar git && \
37+
ORIGINAL_DIR=$(pwd) && \
38+
TEMP_BUILD_DIR="/tmp/libgit2_build_$$" && \
39+
mkdir -p "$TEMP_BUILD_DIR" && \
40+
cd "$TEMP_BUILD_DIR" && \
3741
wget https://github.com/libgit2/libgit2/archive/refs/tags/v1.5.1.tar.gz -O libgit2-v1.5.1.tar.gz && \
3842
tar -xzf libgit2-v1.5.1.tar.gz && \
3943
cd libgit2-1.5.1 && \
@@ -42,7 +46,8 @@ jobs:
4246
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF && \
4347
make -j$(nproc) && \
4448
sudo make install && \
45-
sudo ldconfig
49+
sudo ldconfig && \
50+
cd "$ORIGINAL_DIR"
4651
env:
4752
LIBGIT2_SYS_USE_PKG_CONFIG: "1"
4853

.goreleaser.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ before:
66
hooks:
77
- go mod download
88

9+
910
builds:
1011
- main: main.go
1112
id: modctl
1213
binary: modctl
1314
goos:
1415
- linux
15-
- darwin
16+
# - darwin
1617
goarch:
1718
- amd64
18-
- arm64
19+
# - arm64
1920
env:
2021
- CGO_ENABLED=1
2122
ldflags:

0 commit comments

Comments
 (0)