ci: add version option pkg/ziex

This commit is contained in:
Nurul Huda (Apon) 2026-07-12 15:25:10 +06:00
parent f54a43439c
commit 1365558a95
No known key found for this signature in database
GPG Key ID: 5D3F1DE2855A2F79
4 changed files with 22 additions and 6 deletions

View File

@ -352,9 +352,11 @@ jobs:
env:
NODE_AUTH_TOKEN: ""
DIST_TAG: ${{ needs.resolve-version.outputs.dist-tag }}
VERSION: ${{ needs.resolve-version.outputs.version }}
run: |
cd pkg/ziex
zig build -p dist
rm -rf dist
zig build -p dist -Dversion="$VERSION"
cd dist
rc=0
out=$(npm publish --access public --provenance --tag "$DIST_TAG" 2>&1) || rc=$?

View File

@ -10,6 +10,9 @@ packages:
'@ziex/*':
access: $anonymous
publish: $anonymous
'ziex':
access: $anonymous
publish: $anonymous
'**':
access: $anonymous
publish: $anonymous

View File

@ -85,11 +85,11 @@ if [ "$cli_rc" -ne 0 ]; then
echo "==> @ziex/cli* already present at this version; continuing"
fi
# Build and publish ziex to local registry
# Build and publish ziex to local registry.
echo "==> Building and publishing ziex to local registry..."
cd "$SCRIPT_DIR/ziex"
BUN_CONFIG_REGISTRY="$REGISTRY" bun install --registry "$REGISTRY" 2>&1
zig build -p dist
rm -rf dist
zig build -p dist -Dversion="$VERSION"
cd dist
publish_idempotent ziex

View File

@ -7,6 +7,7 @@ pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
_ = target;
const type_decl = b.option(bool, "type-decl", "Generate type declarations") orelse true;
const version = b.option([]const u8, "version", "npm package version to embed") orelse build_zon.version;
const is_release = optimize != .Debug;
// --- JS bundles (esbuild) --- //
@ -66,7 +67,7 @@ pub fn build(b: *std.Build) !void {
// --- Static package files --- //
{
_ = dist_files.addCopyFile(try makePublishPackageJson(b), "package.json");
_ = dist_files.addCopyFile(try makePublishPackageJson(b, version), "package.json");
_ = dist_files.addCopyFile(b.path("../../README.md"), "README.md");
_ = dist_files.addCopyFile(b.path("bin/ziex"), "bin/ziex");
_ = dist_files.addCopyFile(makePublishBuildZig(b), "build.zig");
@ -128,7 +129,7 @@ fn makePublishBuildZigZon(b: *std.Build) !std.Build.LazyPath {
return b.addWriteFiles().add("build.zig.zon", out);
}
fn makePublishPackageJson(b: *std.Build) !std.Build.LazyPath {
fn makePublishPackageJson(b: *std.Build, version: []const u8) !std.Build.LazyPath {
const src = try b.root.root_dir.handle.readFileAlloc(b.graph.io, "package.json", b.allocator, .unlimited);
defer b.allocator.free(src);
@ -136,6 +137,7 @@ fn makePublishPackageJson(b: *std.Build) !std.Build.LazyPath {
defer parsed.deinit();
const obj = &parsed.value.object;
try obj.put(b.allocator, "version", .{ .string = version });
try obj.put(b.allocator, "main", .{ .string = "index.js" });
try obj.put(b.allocator, "module", .{ .string = "index.js" });
try obj.put(b.allocator, "types", .{ .string = "index.d.ts" });
@ -146,6 +148,15 @@ fn makePublishPackageJson(b: *std.Build) !std.Build.LazyPath {
_ = obj.swapRemove("release");
_ = obj.swapRemove("prettier");
// Keep the CLI dependency pinned to the same version we are publishing.
if (obj.getPtr("dependencies")) |deps_val| {
if (deps_val.* == .object) {
if (deps_val.object.getPtr("@ziex/cli")) |cli_dep| {
cli_dep.* = .{ .string = version };
}
}
}
const json = try std.json.Stringify.valueAlloc(b.allocator, parsed.value, .{ .whitespace = .indent_2 });
defer b.allocator.free(json);
const out = try std.mem.concat(b.allocator, u8, &.{ json, "\n" });