Skip to content

Commit 947c4f0

Browse files
authored
chore: fix the release config for static build (#174)
Signed-off-by: chlins <[email protected]>
1 parent ce0219d commit 947c4f0

File tree

4 files changed

+171
-160
lines changed

4 files changed

+171
-160
lines changed

.github/workflows/release.yaml

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
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+
- 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 cmake wget zlib libiconv && \
63+
wget https://github.com/libgit2/libgit2/archive/refs/tags/v1.5.1.tar.gz -O libgit2-v1.5.1.tar.gz && \
64+
tar -xzf libgit2-v1.5.1.tar.gz && \
65+
cd libgit2-1.5.1 && \
66+
mkdir build && \
67+
cd build && \
68+
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF && \
69+
make -j$(nproc) && \
70+
sudo make install
71+
72+
- name: Build binary for linux
73+
if: matrix.goos == 'linux'
74+
env:
75+
CGO_ENABLED: 1
76+
GOOS: ${{ matrix.goos }}
77+
GOARCH: ${{ matrix.goarch }}
78+
run: |
79+
go build \
80+
-tags "static system_libgit2" \
81+
-ldflags "-X github.com/CloudNativeAI/modctl/pkg/version.GitVersion=${{ github.ref_name }} \
82+
-X github.com/CloudNativeAI/modctl/pkg/version.GitCommit=$(git rev-parse --short HEAD) \
83+
-X github.com/CloudNativeAI/modctl/pkg/version.BuildTime=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
84+
-extldflags '-static'" \
85+
-o modctl \
86+
main.go
87+
88+
- name: Build binary for macOS
89+
if: matrix.goos == 'darwin'
90+
env:
91+
CGO_ENABLED: 1
92+
GOOS: ${{ matrix.goos }}
93+
GOARCH: ${{ matrix.goarch }}
94+
CGO_LDFLAGS: "-lgit2 -lz -liconv -Wl,-rpath,/Users/runner/work/modctl/modctl/libgit2-1.5.1/build"
95+
run: |
96+
go build \
97+
-tags "static system_libgit2" \
98+
-ldflags "-X github.com/CloudNativeAI/modctl/pkg/version.GitVersion=${{ github.ref_name }} \
99+
-X github.com/CloudNativeAI/modctl/pkg/version.GitCommit=$(git rev-parse --short HEAD) \
100+
-X github.com/CloudNativeAI/modctl/pkg/version.BuildTime=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
101+
-o modctl \
102+
main.go
103+
104+
- name: Create archive
105+
run: |
106+
mkdir -p dist
107+
tar -czf dist/modctl-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz \
108+
LICENSE README.md modctl
109+
110+
- name: Build deb/rpm packages
111+
if: matrix.goos == 'linux'
112+
env:
113+
GOOS: ${{ matrix.goos }}
114+
GOARCH: ${{ matrix.goarch }}
115+
VERSION: ${{ github.ref_name }}
116+
run: |
117+
echo 'deb [trusted=yes] https://repo.goreleaser.com/apt/ /' | sudo tee /etc/apt/sources.list.d/goreleaser.list
118+
sudo apt update
119+
sudo apt install nfpm
120+
nfpm pkg --packager deb --config hack/nfpm.yaml --target dist/modctl-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }}.deb
121+
nfpm pkg --packager rpm --config hack/nfpm.yaml --target dist/modctl-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }}.rpm
122+
123+
- name: Upload artifacts
124+
uses: actions/upload-artifact@v4
125+
with:
126+
name: modctl-${{ matrix.goos }}-${{ matrix.goarch }}
127+
path: dist/
128+
129+
create-release:
130+
needs: release
131+
runs-on: ubuntu-latest
132+
steps:
133+
- name: Download all artifacts
134+
uses: actions/download-artifact@v4
135+
with:
136+
path: artifacts
137+
138+
- name: Generate unified checksums
139+
run: |
140+
cd artifacts
141+
find . -type f \( -name "modctl-*.tar.gz" -o -name "modctl-*.deb" -o -name "modctl-*.rpm" \) -exec shasum -a 256 {} \; > ../checksums.txt
142+
143+
- name: Create draft release
144+
uses: softprops/action-gh-release@v2
145+
with:
146+
draft: true
147+
files: |
148+
artifacts/**/modctl-*.tar.gz
149+
artifacts/**/modctl-*.deb
150+
artifacts/**/modctl-*.rpm
151+
checksums.txt
152+
generate_release_notes: true
153+
env:
154+
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}

.github/workflows/release.yml

Lines changed: 0 additions & 92 deletions
This file was deleted.

.goreleaser.yml

Lines changed: 0 additions & 68 deletions
This file was deleted.

hack/nfpm.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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: modctl
10+
dst: /usr/bin/modctl
11+
expand: true
12+
13+
- src: build/package/docs/modctl.1
14+
dst: /usr/share/man/man1/modctl.1
15+
16+
- src: LICENSE
17+
dst: /usr/share/doc/modctl/License

0 commit comments

Comments
 (0)