Skip to content

Commit 3ed65fe

Browse files
additional refactoring
Signed-off-by: Muhammad Awawdi <[email protected]>
1 parent 5f0a3fc commit 3ed65fe

File tree

12 files changed

+177
-153
lines changed

12 files changed

+177
-153
lines changed

.github/workflows/node-create-package-file/action.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ runs:
5151
steps:
5252
- name: Create package.json file
5353
shell: bash
54-
working-directory: ./node
54+
working-directory: ./node/rust-client
5555
run: |
5656
# echo -musl if inputs.target is musl
5757
export MUSL_FLAG=`if [[ "${{ inputs.target }}" =~ .*"musl".* ]]; then echo "-musl"; fi`
5858
# set the package name
59-
name="valkey-glide"
59+
name="glide-rs"
6060
# derive the OS and architecture from the inputs
6161
export node_os="${{ inputs.named_os }}"
6262
export node_arch="${{ inputs.arch }}"

.github/workflows/npm-cd.yml

+62-58
Original file line numberDiff line numberDiff line change
@@ -62,37 +62,9 @@ jobs:
6262
# Get the matrix from the matrix.json file, without the object that has the IMAGE key
6363
export "PLATFORM_MATRIX=$(jq 'map(select(.PACKAGE_MANAGERS != null and (.PACKAGE_MANAGERS | contains(["npm"]))))' < .github/json_matrices/build-matrix.json | jq -c .)"
6464
echo "PLATFORM_MATRIX=${PLATFORM_MATRIX}" >> $GITHUB_OUTPUT
65-
66-
publish-rust-client:
67-
needs: [start-self-hosted-runner, load-platform-matrix]
68-
if: github.repository_owner == 'valkey-io'
69-
name: Publish Rust client to NPM
70-
runs-on: ubuntu-latest
71-
steps:
72-
- name: Checkout
73-
uses: actions/checkout@v4
74-
with:
75-
submodules: "true"
76-
77-
- name: Setup node
78-
uses: actions/setup-node@v4
79-
with:
80-
node-version: "latest"
81-
registry-url: "https://registry.npmjs.org"
82-
scope: "${{ vars.NPM_SCOPE }}"
83-
always-auth: true
84-
85-
- name: Publish Rust client
86-
working-directory: ./node/rust-client
87-
run: |
88-
npm ci
89-
npm run build
90-
npm publish --access public
91-
env:
92-
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
9365
9466
publish-binaries:
95-
needs: [start-self-hosted-runner, load-platform-matrix, publish-rust-client]
67+
needs: [start-self-hosted-runner, load-platform-matrix]
9668
if: github.repository_owner == 'valkey-io'
9769
name: Publish packages to NPM
9870
runs-on: ${{ matrix.build.RUNNER }}
@@ -147,6 +119,31 @@ jobs:
147119
EVENT_NAME: ${{ github.event_name }}
148120
INPUT_VERSION: ${{ github.event.inputs.version }}
149121

122+
- name: Set platform-specific package name
123+
shell: bash
124+
run: |
125+
PLATFORM_NAME="${{ matrix.build.NAMED_OS }}${{ contains(matrix.build.TARGET, 'musl') && '-musl' || '' }}-${{ matrix.build.ARCH }}"
126+
echo "PLATFORM_NAME=${PLATFORM_NAME}" >> $GITHUB_ENV
127+
echo "NODE_OS=${{ matrix.build.NAMED_OS }}" >> $GITHUB_ENV
128+
echo "NODE_ARCH=${{ matrix.build.ARCH }}" >> $GITHUB_ENV
129+
echo "PACKAGE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV
130+
131+
- name: Update Rust client package.json
132+
working-directory: ./node/rust-client
133+
run: |
134+
sed -i 's|\${PLATFORM_NAME}|'"${PLATFORM_NAME}"'|g' package.json
135+
sed -i 's|\${PACKAGE_VERSION}|'"${PACKAGE_VERSION}"'|g' package.json
136+
sed -i 's|\${NODE_OS}|'"${NODE_OS}"'|g' package.json
137+
sed -i 's|\${NODE_ARCH}|'"${NODE_ARCH}"'|g' package.json
138+
139+
- name: Validate Rust client package.json
140+
working-directory: ./node/rust-client
141+
run: |
142+
if ! grep -q "@valkey/glide-rs-${PLATFORM_NAME}" package.json; then
143+
echo "Error: package.json does not contain the correct package name"
144+
exit 1
145+
fi
146+
150147
- name: Setup node
151148
if: ${{ !contains(matrix.build.TARGET, 'musl') }}
152149
uses: actions/setup-node@v4
@@ -206,7 +203,7 @@ jobs:
206203
- name: Publish to NPM
207204
if: github.event_name != 'pull_request'
208205
shell: bash
209-
working-directory: ./node
206+
working-directory: ./node/rust-client
210207
run: |
211208
npm pkg fix
212209
set +e # Disable immediate exit on non-zero exit codes
@@ -224,7 +221,7 @@ jobs:
224221
echo "Skipping publishing, package already published."
225222
elif [[ ! -z "$npm_publish_err" ]]; then
226223
echo "Failed to publish with error: $npm_publish_err"
227-
exit 1
224+
exit 1
228225
fi
229226
env:
230227
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
@@ -244,7 +241,7 @@ jobs:
244241
publish-base-to-npm:
245242
if: github.event_name != 'pull_request'
246243
name: Publish the base NPM package
247-
needs: [publish-binaries, publish-rust-client]
244+
needs: [publish-binaries]
248245
runs-on: ubuntu-latest
249246
steps:
250247
- name: Checkout
@@ -260,32 +257,42 @@ jobs:
260257
scope: "${{ vars.NPM_SCOPE }}"
261258
always-auth: true
262259

263-
- name: Create package.json file
260+
- name: Update package.json and index.ts
264261
shell: bash
265262
working-directory: ./node/npm/glide
266263
run: |
267-
export pkg_name=valkey-glide
268-
269-
echo "The workflow is: ${{env.EVENT_NAME}}"
270-
if ${{ env.EVENT_NAME == 'workflow_dispatch' }}; then
271-
R_VERSION="${{ env.INPUT_VERSION }}"
264+
# Set version
265+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
266+
R_VERSION="${{ github.event.inputs.version }}"
272267
else
273-
R_VERSION=${GITHUB_REF:11}
268+
R_VERSION=${GITHUB_REF#refs/tags/v}
274269
fi
275270
echo "RELEASE_VERSION=${R_VERSION}" >> $GITHUB_ENV
276271
277-
export package_version=${R_VERSION}
278-
export scope=`if [ "$NPM_SCOPE" != '' ]; then echo "$NPM_SCOPE/"; fi`
279-
mv package.json package.json.tmpl
280-
envsubst < package.json.tmpl > "package.json"
281-
cat package.json
282-
# Fix index.ts based on the scope variable
283-
sed -i "s|@scope/|${scope}|g" index.ts
284-
env:
285-
NPM_SCOPE: ${{ vars.NPM_SCOPE }}
286-
EVENT_NAME: ${{ github.event_name }}
287-
INPUT_VERSION: ${{ github.event.inputs.version }}
288-
272+
# Update package.json
273+
jq '.version = env.RELEASE_VERSION | .name = "@valkey/valkey-glide" | .optionalDependencies = {
274+
"@valkey/glide-rs-linux-x64": env.RELEASE_VERSION,
275+
"@valkey/glide-rs-linux-arm64": env.RELEASE_VERSION,
276+
"@valkey/glide-rs-darwin-x64": env.RELEASE_VERSION,
277+
"@valkey/glide-rs-darwin-arm64": env.RELEASE_VERSION,
278+
"@valkey/glide-rs-linux-musl-x64": env.RELEASE_VERSION,
279+
"@valkey/glide-rs-linux-musl-arm64": env.RELEASE_VERSION
280+
}' package.json > temp.json && mv temp.json package.json
281+
282+
# Update index.ts
283+
sed -i 's/@scope\/valkey-glide/@valkey\/glide-rs/g' index.ts
284+
285+
- name: Validate base package.json and index.ts
286+
working-directory: ./node/npm/glide
287+
run: |
288+
if ! grep -q '"@valkey/valkey-glide"' package.json; then
289+
echo "Error: package.json does not contain the correct package name"
290+
exit 1
291+
fi
292+
if ! grep -q '@valkey/glide-rs' index.ts; then
293+
echo "Error: index.ts does not contain the correct import statements"
294+
exit 1
295+
fi
289296
- name: Build Node wrapper
290297
uses: ./.github/workflows/build-node-wrapper
291298
with:
@@ -299,12 +306,11 @@ jobs:
299306
if [[ ${{ env.RELEASE_VERSION }} == *"rc"* ]]
300307
then
301308
echo "This is a release candidate"
302-
export npm_tag="next"
309+
echo "NPM_TAG=next" >> $GITHUB_ENV
303310
else
304311
echo "This is a stable release"
305-
export npm_tag="latest"
312+
echo "NPM_TAG=latest" >> $GITHUB_ENV
306313
fi
307-
echo "NPM_TAG=${npm_tag}" >> $GITHUB_ENV
308314
309315
- name: Publish the base package
310316
if: github.event_name != 'pull_request'
@@ -406,7 +412,7 @@ jobs:
406412
working-directory: ./utils/release-candidate-testing/node
407413
run: |
408414
npm install
409-
npm install --no-save @valkey/valkey-glide@${{ env.NPM_TAG }} @valkey/glide-rs@${{ env.NPM_TAG }}
415+
npm install --no-save @valkey/valkey-glide@${{ env.NPM_TAG }}
410416
npm run test
411417
412418
- name: Deprecating packages on failure
@@ -445,14 +451,12 @@ jobs:
445451
446452
# Deprecating base package
447453
npm deprecate "@valkey/valkey-glide@${RELEASE_VERSION}" "This version has been deprecated" --force || true
448-
# Deprecating Rust client package
449-
npm deprecate "@valkey/glide-rs@${RELEASE_VERSION}" "This version has been deprecated" --force || true
450454
451455
# Process platform matrix
452456
echo "${PLATFORM_MATRIX}" > platform_matrix.json
453457
454458
while read -r pkg; do
455-
package_name="@valkey/valkey-glide-${pkg}"
459+
package_name="@valkey/glide-rs-${pkg}"
456460
echo "Deprecating ${package_name}@${RELEASE_VERSION}"
457461
npm deprecate "${package_name}@${RELEASE_VERSION}" "This version has been deprecated" --force || true
458462
done < <(jq -r '.[] | "\(.NAMED_OS)\(.TARGET | test("musl") | if . then "-musl" else "" end)-\(.ARCH)"' platform_matrix.json)

node/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
33
*/
44

5-
export { ClusterScanCursor, Script } from "@valkey/glide-rs";
5+
export { ClusterScanCursor, Script } from "../npm/glide/glide-rs";
66
export * from "./src/BaseClient";
77
export * from "./src/Commands";
88
export * from "./src/Errors";

node/npm/glide/glide-rs.ts

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
5+
*/
6+
7+
import { GLIBC, MUSL, familySync } from "detect-libc";
8+
import { arch, platform } from "process";
9+
10+
/* eslint-disable @typescript-eslint/no-require-imports */
11+
function loadNativeBinding() {
12+
let nativeBinding = null;
13+
14+
switch (platform) {
15+
case "linux":
16+
switch (arch) {
17+
case "x64":
18+
switch (familySync()) {
19+
case GLIBC:
20+
nativeBinding = require("@scope/glide-rs-linux-x64");
21+
break;
22+
case MUSL:
23+
nativeBinding = require("@scope/glide-rs-linux-musl-x64");
24+
break;
25+
default:
26+
nativeBinding = require("@scope/glide-rs-linux-x64");
27+
break;
28+
}
29+
30+
break;
31+
case "arm64":
32+
switch (familySync()) {
33+
case GLIBC:
34+
nativeBinding = require("@scope/glide-rs-linux-arm64");
35+
break;
36+
case MUSL:
37+
nativeBinding = require("@scope/glide-rs-linux-musl-arm64");
38+
break;
39+
default:
40+
nativeBinding = require("@scope/glide-rs-linux-arm64");
41+
break;
42+
}
43+
44+
break;
45+
default:
46+
throw new Error(
47+
`Unsupported OS: ${platform}, architecture: ${arch}`,
48+
);
49+
}
50+
51+
break;
52+
case "darwin":
53+
switch (arch) {
54+
case "arm64":
55+
nativeBinding = require("@scope/glide-rs-darwin-arm64");
56+
break;
57+
default:
58+
throw new Error(
59+
`Unsupported OS: ${platform}, architecture: ${arch}`,
60+
);
61+
}
62+
63+
break;
64+
default:
65+
throw new Error(
66+
`Unsupported OS: ${platform}, architecture: ${arch}`,
67+
);
68+
}
69+
70+
if (!nativeBinding) {
71+
throw new Error(`Failed to load native binding`);
72+
}
73+
74+
return nativeBinding;
75+
}
76+
77+
const nativeBinding = loadNativeBinding();
78+
79+
export = nativeBinding;

0 commit comments

Comments
 (0)