-
Notifications
You must be signed in to change notification settings - Fork 2k
243 lines (217 loc) · 7.83 KB
/
Copy pathrust-cli.yml
File metadata and controls
243 lines (217 loc) · 7.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
name: Rust CLI Build
on:
workflow_call:
push:
branches: [ main, feat/rust-cli ]
paths:
- 'crates/**'
- 'Cargo.toml'
- '.github/workflows/rust-cli.yml'
tags:
- 'cli@*'
pull_request:
branches: [ main ]
paths:
- 'crates/**'
- 'Cargo.toml'
- '.github/workflows/rust-cli.yml'
permissions:
contents: read
jobs:
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-24.04
target: x86_64-unknown-linux-musl
artifact_name: ov-linux-x86_64
npm_pkg: cli-linux-x64
npm_os: linux
npm_cpu: x64
- os: ubuntu-24.04
target: aarch64-unknown-linux-musl
artifact_name: ov-linux-aarch64
npm_pkg: cli-linux-arm64
npm_os: linux
npm_cpu: arm64
- os: macos-15-intel
target: x86_64-apple-darwin
artifact_name: ov-macos-x86_64
npm_pkg: cli-darwin-x64
npm_os: darwin
npm_cpu: x64
- os: macos-14
target: aarch64-apple-darwin
artifact_name: ov-macos-aarch64
npm_pkg: cli-darwin-arm64
npm_os: darwin
npm_cpu: arm64
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact_name: ov-windows-x86_64.exe
npm_pkg: cli-win32-x64
npm_os: win32
npm_cpu: x64
steps:
- uses: actions/checkout@v6
- name: Install Rust
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
targets: ${{ matrix.target }}
# Linux artifacts are produced as fully static musl binaries so they run on
# any glibc-flavored distro (CentOS 7/8/Stream 9, RHEL 8/9, Amazon Linux,
# Alpine, etc.) — the ubuntu-24.04 runner's glibc 2.39 is newer than
# CentOS 7 (2.17) / RHEL 8 (2.28) / RHEL 9 (2.34), so a gnu-linked binary
# fails with `version 'GLIBC_2.X' not found`. cargo-zigbuild + zig handle
# both x86_64 and aarch64 musl cross-compilation with one toolchain;
# ov_cli uses reqwest+rustls-tls so libssl-dev is no longer needed.
# Zig is installed via shell to avoid depending on a third-party action
# not on the org's allowed-actions list.
- name: Install Zig + cargo-zigbuild (Linux musl cross-build)
if: runner.os == 'Linux'
shell: bash
run: |
set -euo pipefail
ZIG_VERSION=0.13.0
ZIG_DIR="$RUNNER_TEMP/zig-$ZIG_VERSION"
mkdir -p "$ZIG_DIR"
curl -fsSL "https://ziglang.org/download/$ZIG_VERSION/zig-linux-x86_64-$ZIG_VERSION.tar.xz" \
| tar -xJ --strip-components=1 -C "$ZIG_DIR"
echo "$ZIG_DIR" >> "$GITHUB_PATH"
cargo install --locked cargo-zigbuild
- name: Cache Cargo registry and index
uses: actions/cache@v5
with:
path: |
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
key: ${{ runner.os }}-cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-${{ matrix.target }}-
${{ runner.os }}-cargo-
- name: Cache build artifacts
uses: actions/cache@v5
with:
path: target
key: ${{ runner.os }}-target-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}-${{ hashFiles('crates/**/*.rs') }}
restore-keys: |
${{ runner.os }}-target-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}-
${{ runner.os }}-target-${{ matrix.target }}-
- name: Inject version from tag
shell: bash
run: |
VERSION="${GITHUB_REF#refs/tags/cli@}"
if [[ "$VERSION" != "$GITHUB_REF" ]]; then
sed -i.bak "s/^version = \"0.0.0\"/version = \"$VERSION\"/" crates/ov_cli/Cargo.toml
rm -f crates/ov_cli/Cargo.toml.bak
echo "Injected version $VERSION into Cargo.toml"
fi
- name: Build CLI
shell: bash
run: |
if [[ "${{ runner.os }}" == "Linux" ]]; then
cargo zigbuild --release --target ${{ matrix.target }} -p ov_cli
else
cargo build --release --target ${{ matrix.target }} -p ov_cli
fi
- name: Package platform npm package
shell: bash
run: |
VERSION="${GITHUB_REF#refs/tags/cli@}"
# For non-tag builds, use 0.0.0-dev
if [[ "$VERSION" == "$GITHUB_REF" ]]; then
VERSION="0.0.0-dev"
fi
PKG_DIR="npm-pkg"
mkdir -p "$PKG_DIR/bin"
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
cp "target/${{ matrix.target }}/release/ov.exe" "$PKG_DIR/bin/ov.exe"
else
cp "target/${{ matrix.target }}/release/ov" "$PKG_DIR/bin/ov"
chmod +x "$PKG_DIR/bin/ov"
fi
node -e "
const pkg = {
name: '@openviking/${{ matrix.npm_pkg }}',
version: '$VERSION',
description: 'OpenViking CLI native binary for ${{ matrix.npm_os }}-${{ matrix.npm_cpu }}',
os: ['${{ matrix.npm_os }}'],
cpu: ['${{ matrix.npm_cpu }}'],
files: ['bin'],
license: 'Apache-2.0',
repository: { type: 'git', url: 'git+https://github.com/volcengine/openviking.git' },
publishConfig: { access: 'public' }
};
require('fs').writeFileSync('$PKG_DIR/package.json', JSON.stringify(pkg, null, 2) + '\n');
"
- name: Upload npm package artifact
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.npm_pkg }}
path: npm-pkg/
npm-publish:
name: Publish to npm
runs-on: ubuntu-24.04
needs: build
if: startsWith(github.ref, 'refs/tags/cli@')
permissions:
contents: read
actions: read
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '24'
registry-url: 'https://registry.npmjs.org'
- name: Get version from tag
id: get_version
run: echo "version=${GITHUB_REF#refs/tags/cli@}" >> $GITHUB_OUTPUT
- name: Download all platform artifacts
uses: actions/download-artifact@v8
with:
path: artifacts
- name: Display artifact structure
run: ls -R artifacts/
- name: Publish platform packages
run: |
VERSION="${{ steps.get_version.outputs.version }}"
for pkg_dir in artifacts/cli-*/; do
pkg_name=$(basename "$pkg_dir")
package="@openviking/$pkg_name"
if npm view "$package@$VERSION" version --registry=https://registry.npmjs.org >/dev/null 2>&1; then
echo "Skipping $package@$VERSION; already published."
continue
fi
echo "Publishing $package@$VERSION..."
chmod +x "$pkg_dir/bin/ov" 2>/dev/null || true
cd "$pkg_dir"
npm publish --access public
cd "$GITHUB_WORKSPACE"
done
- name: Publish wrapper package
run: |
VERSION="${{ steps.get_version.outputs.version }}"
cd npm/cli
# Inject version into package.json
node -e "
const pkg = JSON.parse(require('fs').readFileSync('package.json', 'utf8'));
pkg.version = '$VERSION';
for (const dep of Object.keys(pkg.optionalDependencies || {})) {
pkg.optionalDependencies[dep] = '$VERSION';
}
require('fs').writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
"
if npm view "@openviking/cli@$VERSION" version --registry=https://registry.npmjs.org >/dev/null 2>&1; then
echo "Skipping @openviking/cli@$VERSION; already published."
exit 0
fi
echo "Publishing @openviking/cli@$VERSION..."
npm publish --access public