Skip to content

Commit a343ce4

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

File tree

3 files changed

+185
-4
lines changed

3 files changed

+185
-4
lines changed

.github/workflows/release-v2.yaml

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
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.0.tar.gz -O libgit2-v1.5.0.tar.gz && \
65+
tar -xzf libgit2-v1.5.0.tar.gz && \
66+
cd libgit2-1.5.0 && \
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+
92+
- name: Build binary for macOS
93+
if: matrix.goos == 'darwin'
94+
env:
95+
CGO_ENABLED: 1
96+
GOOS: ${{ matrix.goos }}
97+
GOARCH: ${{ matrix.goarch }}
98+
# CGO_LDFLAGS: -Wl,-rpath,/Users/runner/work/modctl/modctl/libgit2-1.5.1/build
99+
LDFLAGS: "-L/opt/homebrew/opt/zlib/lib -L/opt/homebrew/opt/libiconv/lib"
100+
CPPFLAGS: "-I/opt/homebrew/opt/zlib/include -I/opt/homebrew/opt/libiconv/include"
101+
PKG_CONFIG_PATH: "/opt/homebrew/opt/zlib/lib/pkgconfig"
102+
run: |
103+
go build \
104+
-tags "libgit2_static netgo osusergo" \
105+
-ldflags "-X github.com/CloudNativeAI/modctl/pkg/version.GitVersion=${{ github.ref_name }} \
106+
-X github.com/CloudNativeAI/modctl/pkg/version.GitCommit=$(git rev-parse --short HEAD) \
107+
-X github.com/CloudNativeAI/modctl/pkg/version.BuildTime=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
108+
-o build/modctl-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }} \
109+
main.go
110+
111+
# - name: Create archive
112+
# run: |
113+
# mkdir -p dist
114+
# tar -czf dist/modctl-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz \
115+
# -C build modctl-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }} \
116+
# LICENSE README.md
117+
118+
# - name: Build deb/rpm packages
119+
# if: matrix.goos == 'linux'
120+
# uses: actions/setup-go@v5
121+
# with:
122+
# args: |
123+
# pack \
124+
# --packager nfpms \
125+
# --config <(echo '
126+
# name: modctl
127+
# arch: ${{ matrix.goarch }}
128+
# version: ${{ github.ref_name }}
129+
# maintainer: "Model Spec Maintainers <[email protected]>"
130+
# description: "A command line tool for managing artifact bundled based on the Model Format Specification"
131+
# license: "Apache 2.0"
132+
# formats:
133+
# - deb
134+
# - rpm
135+
# bindir: /usr/bin
136+
# files:
137+
# build/modctl-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }}: /usr/bin/modctl
138+
# build/package/docs/modctl.1: /usr/share/man/man1/modctl.1
139+
# LICENSE: /usr/share/doc/modctl/License
140+
# ') \
141+
# --output dist/
142+
143+
# - name: Generate checksums
144+
# run: |
145+
# cd dist
146+
# shasum -a 256 *.tar.gz *.deb *.rpm > checksums.txt
147+
# continue-on-error: true # In case no deb/rpm files exist for macOS
148+
149+
# - name: Upload artifacts
150+
# uses: actions/upload-artifact@v4
151+
# with:
152+
# name: modctl-${{ matrix.goos }}-${{ matrix.goarch }}
153+
# path: dist/
154+
155+
# create-release:
156+
# needs: release
157+
# runs-on: ubuntu-latest
158+
# steps:
159+
# - name: Download all artifacts
160+
# uses: actions/download-artifact@v4
161+
# with:
162+
# path: artifacts
163+
164+
# - name: Create draft release
165+
# uses: softprops/action-gh-release@v2
166+
# with:
167+
# draft: true
168+
# files: |
169+
# artifacts/**/modctl-*.tar.gz
170+
# artifacts/**/modctl-*.deb
171+
# artifacts/**/modctl-*.rpm
172+
# artifacts/**/checksums.txt
173+
# generate_release_notes: true
174+
# env:
175+
# 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)