Skip to content

Commit d5f8075

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

File tree

4 files changed

+185
-4
lines changed

4 files changed

+185
-4
lines changed

.github/workflows/release-v2.yaml

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
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+
LICENSE README.md build/modctl-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }}
115+
116+
- name: Build deb/rpm packages
117+
if: matrix.goos == 'linux'
118+
run: |
119+
echo 'deb [trusted=yes] https://repo.goreleaser.com/apt/ /' | sudo tee /etc/apt/sources.list.d/goreleaser.list
120+
sudo apt update
121+
sudo apt install nfpm
122+
export VERSION=${{ github.ref_name }}
123+
nfpm pkg \
124+
--config hack/nfpm.yaml \
125+
--target dist/
126+
127+
- name: Generate checksums
128+
run: |
129+
cd dist
130+
shasum -a 256 *.tar.gz *.deb *.rpm > checksums.txt
131+
continue-on-error: true # In case no deb/rpm files exist for macOS
132+
133+
- name: Upload artifacts
134+
uses: actions/upload-artifact@v4
135+
with:
136+
name: modctl-${{ matrix.goos }}-${{ matrix.goarch }}
137+
path: dist/
138+
139+
create-release:
140+
needs: release
141+
runs-on: ubuntu-latest
142+
steps:
143+
- name: Download all artifacts
144+
uses: actions/download-artifact@v4
145+
with:
146+
path: artifacts
147+
148+
- name: Create draft release
149+
uses: softprops/action-gh-release@v2
150+
with:
151+
draft: true
152+
files: |
153+
artifacts/**/modctl-*.tar.gz
154+
artifacts/**/modctl-*.deb
155+
artifacts/**/modctl-*.rpm
156+
artifacts/**/checksums.txt
157+
generate_release_notes: true
158+
env:
159+
GITHUB_TOKEN: ${{ secrets.RELEASE_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:

hack/nfpm.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
arch: ${GOARCH}
2+
platform: ${GOOS}
3+
name: modctl
4+
version: ${VERSION}
5+
maintainer: "Model Spec Maintainers <[email protected]>"
6+
description: "A command line tool for managing artifact bundled based on the Model Format Specification"
7+
license: "Apache 2.0"
8+
contents:
9+
- src: build/modctl-${VERSION}-${GOOS}-${GOARCH}
10+
dst: /usr/bin/modctl
11+
12+
- src: build/package/docs/modctl.1
13+
dst: /usr/share/man/man1/modctl.1
14+
15+
- src: LICENSE
16+
dst: /usr/share/doc/modctl/License

0 commit comments

Comments
 (0)