Skip to content

Commit 30d6cbe

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

File tree

3 files changed

+155
-4
lines changed

3 files changed

+155
-4
lines changed

.github/workflows/release-v2.yaml

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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-latest
19+
- goos: darwin
20+
goarch: amd64
21+
runner: macos-latest
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+
- name: Install CGO dependencies for Linux
43+
if: matrix.goos == 'linux'
44+
run: |
45+
sudo apt-get update
46+
sudo apt-get install -y pkg-config
47+
sudo apt update && \
48+
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 && \
49+
wget https://github.com/libgit2/libgit2/archive/refs/tags/v1.5.1.tar.gz -O libgit2-v1.5.1.tar.gz && \
50+
tar -xzf libgit2-v1.5.1.tar.gz && \
51+
cd libgit2-1.5.1 && \
52+
mkdir build && \
53+
cd build && \
54+
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF && \
55+
make -j$(nproc) && \
56+
sudo make install && \
57+
sudo ldconfig
58+
59+
- name: Install CGO dependencies for macOS
60+
if: matrix.goos == 'darwin'
61+
run: |
62+
brew install libgit2
63+
# Ensure Xcode command line tools are installed
64+
xcode-select --install || true
65+
66+
- name: Build binary
67+
env:
68+
CGO_ENABLED: 1
69+
GOOS: ${{ matrix.goos }}
70+
GOARCH: ${{ matrix.goarch }}
71+
run: |
72+
go build \
73+
-tags "static system_libgit2" \
74+
-ldflags "-X github.com/CloudNativeAI/modctl/pkg/version.GitVersion=${{ github.ref_name }} \
75+
-X github.com/CloudNativeAI/modctl/pkg/version.GitCommit=$(git rev-parse --short HEAD) \
76+
-X github.com/CloudNativeAI/modctl/pkg/version.BuildTime=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
77+
-extldflags '-static'" \
78+
-o build/modctl-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }} \
79+
main.go
80+
81+
- name: Create archive
82+
run: |
83+
mkdir -p dist
84+
tar -czf dist/modctl-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz \
85+
-C build modctl-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }} \
86+
LICENSE README.md
87+
88+
- name: Build deb/rpm packages
89+
if: matrix.goos == 'linux'
90+
uses: actions/setup-go@v5
91+
with:
92+
args: |
93+
pack \
94+
--packager nfpms \
95+
--config <(echo '
96+
name: modctl
97+
arch: ${{ matrix.goarch }}
98+
version: ${{ github.ref_name }}
99+
maintainer: "Model Spec Maintainers <[email protected]>"
100+
description: "A command line tool for managing artifact bundled based on the Model Format Specification"
101+
license: "Apache 2.0"
102+
formats:
103+
- deb
104+
- rpm
105+
bindir: /usr/bin
106+
files:
107+
build/modctl-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }}: /usr/bin/modctl
108+
build/package/docs/modctl.1: /usr/share/man/man1/modctl.1
109+
LICENSE: /usr/share/doc/modctl/License
110+
') \
111+
--output dist/
112+
113+
- name: Generate checksums
114+
run: |
115+
cd dist
116+
shasum -a 256 *.tar.gz *.deb *.rpm > checksums.txt
117+
continue-on-error: true # In case no deb/rpm files exist for macOS
118+
119+
- name: Upload artifacts
120+
uses: actions/upload-artifact@v4
121+
with:
122+
name: modctl-${{ matrix.goos }}-${{ matrix.goarch }}
123+
path: dist/
124+
125+
create-release:
126+
needs: release
127+
runs-on: ubuntu-latest
128+
steps:
129+
- name: Download all artifacts
130+
uses: actions/download-artifact@v4
131+
with:
132+
path: artifacts
133+
134+
- name: Create draft release
135+
uses: softprops/action-gh-release@v2
136+
with:
137+
draft: true
138+
files: |
139+
artifacts/**/modctl-*.tar.gz
140+
artifacts/**/modctl-*.deb
141+
artifacts/**/modctl-*.rpm
142+
artifacts/**/checksums.txt
143+
generate_release_notes: true
144+
env:
145+
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)