99 - ' Cargo.toml'
1010 - ' .github/workflows/rust-cli.yml'
1111 tags :
12- - ' cli@*' # Trigger release on tags starting with cli@
12+ - ' cli@*'
1313 pull_request :
1414 branches : [ main ]
1515 paths :
@@ -28,18 +28,33 @@ jobs:
2828 - os : ubuntu-24.04
2929 target : x86_64-unknown-linux-gnu
3030 artifact_name : ov-linux-x86_64
31+ npm_pkg : cli-linux-x64
32+ npm_os : linux
33+ npm_cpu : x64
3134 - os : ubuntu-24.04
3235 target : aarch64-unknown-linux-gnu
3336 artifact_name : ov-linux-aarch64
37+ npm_pkg : cli-linux-arm64
38+ npm_os : linux
39+ npm_cpu : arm64
3440 - os : macos-15-intel
3541 target : x86_64-apple-darwin
3642 artifact_name : ov-macos-x86_64
43+ npm_pkg : cli-darwin-x64
44+ npm_os : darwin
45+ npm_cpu : x64
3746 - os : macos-14
3847 target : aarch64-apple-darwin
3948 artifact_name : ov-macos-aarch64
49+ npm_pkg : cli-darwin-arm64
50+ npm_os : darwin
51+ npm_cpu : arm64
4052 - os : windows-latest
4153 target : x86_64-pc-windows-msvc
4254 artifact_name : ov-windows-x86_64.exe
55+ npm_pkg : cli-win32-x64
56+ npm_os : win32
57+ npm_cpu : x64
4358
4459 steps :
4560 - uses : actions/checkout@v6
@@ -85,109 +100,116 @@ jobs:
85100 ${{ runner.os }}-target-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}-
86101 ${{ runner.os }}-target-${{ matrix.target }}-
87102
88- - name : Build CLI
89- run : cargo build --release --target ${{ matrix.target }} -p ov_cli
90-
91- - name : Create compressed artifacts
103+ - name : Inject version from tag
92104 shell : bash
93105 run : |
94- mkdir -p artifacts
95- cd target/${{ matrix.target }}/release
96-
97- if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
98- # Windows: create zip
99- 7z a ../../../artifacts/${{ matrix.artifact_name }}.zip ov.exe
100- cd ../../../artifacts
101- # Use PowerShell to get hash in correct format
102- powershell -Command "(Get-FileHash -Algorithm SHA256 '${{ matrix.artifact_name }}.zip').Hash.ToLower() + ' ${{ matrix.artifact_name }}.zip'" > ${{ matrix.artifact_name }}.zip.sha256
103- else
104- # Unix: create tar.gz
105- tar czf ../../../artifacts/${{ matrix.artifact_name }}.tar.gz ov
106- cd ../../../artifacts
107- # shasum format: <hash> <filename>
108- shasum -a 256 ${{ matrix.artifact_name }}.tar.gz > ${{ matrix.artifact_name }}.tar.gz.sha256
106+ VERSION="${GITHUB_REF#refs/tags/cli@}"
107+ if [[ "$VERSION" != "$GITHUB_REF" ]]; then
108+ sed -i.bak "s/^version = \"0.0.0\"/version = \"$VERSION\"/" crates/ov_cli/Cargo.toml
109+ rm -f crates/ov_cli/Cargo.toml.bak
110+ echo "Injected version $VERSION into Cargo.toml"
109111 fi
110112
111- - name : Verify checksum format
113+ - name : Build CLI
114+ run : cargo build --release --target ${{ matrix.target }} -p ov_cli
115+
116+ - name : Package platform npm package
112117 shell : bash
113118 run : |
114- echo "Contents of checksum file:"
115- cat artifacts/*.sha256
116- echo ""
117- echo "Verifying checksum locally:"
118- cd artifacts
119+ VERSION="${GITHUB_REF#refs/tags/cli@}"
120+ # For non-tag builds, use 0.0.0-dev
121+ if [[ "$VERSION" == "$GITHUB_REF" ]]; then
122+ VERSION="0.0.0-dev"
123+ fi
124+
125+ PKG_DIR="npm-pkg"
126+ mkdir -p "$PKG_DIR/bin"
127+
119128 if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
120- sha256sum -c *.sha256 || shasum -a 256 -c *.sha256 || echo "Checksum verification skipped on Windows "
129+ cp "target/${{ matrix.target }}/release/ov.exe" "$PKG_DIR/bin/ov.exe "
121130 else
122- shasum -a 256 -c *.sha256
131+ cp "target/${{ matrix.target }}/release/ov" "$PKG_DIR/bin/ov"
132+ chmod +x "$PKG_DIR/bin/ov"
123133 fi
124134
125- - name : Upload artifacts
135+ node -e "
136+ const pkg = {
137+ name: '@openviking/${{ matrix.npm_pkg }}',
138+ version: '$VERSION',
139+ description: 'OpenViking CLI native binary for ${{ matrix.npm_os }}-${{ matrix.npm_cpu }}',
140+ os: ['${{ matrix.npm_os }}'],
141+ cpu: ['${{ matrix.npm_cpu }}'],
142+ files: ['bin'],
143+ license: 'Apache-2.0',
144+ repository: { type: 'git', url: 'git+https://github.com/volcengine/openviking.git' },
145+ publishConfig: { access: 'public' }
146+ };
147+ require('fs').writeFileSync('$PKG_DIR/package.json', JSON.stringify(pkg, null, 2) + '\n');
148+ "
149+
150+ - name : Upload npm package artifact
126151 uses : actions/upload-artifact@v7
127152 with :
128- name : ${{ matrix.artifact_name }}
129- path : artifacts/*
153+ name : ${{ matrix.npm_pkg }}
154+ path : npm-pkg/
130155
131- release :
132- name : Create GitHub Release
156+ npm-publish :
157+ name : Publish to npm
133158 runs-on : ubuntu-24.04
134159 needs : build
135160 if : startsWith(github.ref, 'refs/tags/cli@')
136- permissions :
137- contents : write
138161 steps :
139162 - name : Checkout code
140163 uses : actions/checkout@v6
141164
165+ - name : Setup Node.js
166+ uses : actions/setup-node@v4
167+ with :
168+ node-version : ' 22'
169+ registry-url : ' https://registry.npmjs.org'
170+
142171 - name : Get version from tag
143172 id : get_version
144173 run : echo "version=${GITHUB_REF#refs/tags/cli@}" >> $GITHUB_OUTPUT
145174
146- - name : Download all artifacts
175+ - name : Download all platform artifacts
147176 uses : actions/download-artifact@v8
148177 with :
149178 path : artifacts
150179
151180 - name : Display artifact structure
152181 run : ls -R artifacts/
153182
154- - name : Create GitHub Release
155- uses : softprops/action-gh-release@v2
156- with :
157- name : CLI v${{ steps.get_version.outputs.version }}
158- body : |
159- # OpenViking CLI v${{ steps.get_version.outputs.version }}
160-
161- ## Installation
162-
163- ### Quick Install (macOS/Linux)
164- ```bash
165- curl -fsSL https://raw.githubusercontent.com/${{ github.repository }}/refs/tags/cli@${{ steps.get_version.outputs.version }}/crates/ov_cli/install.sh | bash
166- ```
167-
168- ### Manual Installation
169- Download the appropriate binary for your platform below, extract it, and add it to your PATH.
170-
171- The CLI command is simply `ov`:
172- ```bash
173- # After extraction
174- chmod +x ov # Unix only
175- mv ov /usr/local/bin/ # or any directory in your PATH
176-
177- # Verify installation
178- ov --version
179- ```
180-
181- ### Checksums
182- SHA256 checksums are provided for each binary for verification.
183-
184- ## Changes
185- See the [commit history](https://github.com/${{ github.repository }}/commits/cli@${{ steps.get_version.outputs.version }}) for details.
186- files : |
187- artifacts/**/*.tar.gz
188- artifacts/**/*.zip
189- artifacts/**/*.sha256
190- draft : false
191- prerelease : ${{ contains(steps.get_version.outputs.version, 'alpha') || contains(steps.get_version.outputs.version, 'beta') || contains(steps.get_version.outputs.version, 'rc') }}
183+ - name : Publish platform packages
184+ env :
185+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
186+ run : |
187+ VERSION="${{ steps.get_version.outputs.version }}"
188+ for pkg_dir in artifacts/cli-*/; do
189+ pkg_name=$(basename "$pkg_dir")
190+ echo "Publishing @openviking/$pkg_name@$VERSION..."
191+ chmod +x "$pkg_dir/bin/ov" 2>/dev/null || true
192+ cd "$pkg_dir"
193+ npm publish --access public
194+ cd "$GITHUB_WORKSPACE"
195+ done
196+
197+ - name : Publish wrapper package
192198 env :
193- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
199+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
200+ run : |
201+ VERSION="${{ steps.get_version.outputs.version }}"
202+ cd npm/cli
203+
204+ # Inject version into package.json
205+ node -e "
206+ const pkg = JSON.parse(require('fs').readFileSync('package.json', 'utf8'));
207+ pkg.version = '$VERSION';
208+ for (const dep of Object.keys(pkg.optionalDependencies || {})) {
209+ pkg.optionalDependencies[dep] = '$VERSION';
210+ }
211+ require('fs').writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
212+ "
213+
214+ echo "Publishing @openviking/cli@$VERSION..."
215+ npm publish --access public
0 commit comments