Skip to content

chore: update repository URLs in package.json files to reflect new ow… #25

chore: update repository URLs in package.json files to reflect new ow…

chore: update repository URLs in package.json files to reflect new ow… #25

Workflow file for this run

name: Build Native Modules
on:
# Only trigger on version tags
push:
tags:
- 'v*'
# Allow manual trigger for testing
workflow_dispatch:
inputs:
version:
description: 'Version to publish (e.g., 0.1.7)'
required: false
type: string
env:
APP_NAME: opencontext-node
MACOSX_DEPLOYMENT_TARGET: '10.13'
jobs:
# First, ensure CI passes
ci-check:
name: Verify CI Status
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
workspaces: crates/opencontext-core -> target
- name: Install Protobuf
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
- name: Check Rust formatting
run: |
cd crates/opencontext-core
cargo fmt --check
- name: Run Clippy
run: |
cd crates/opencontext-core
cargo clippy --features search -- -D warnings
- name: Run Rust tests
run: |
cd crates/opencontext-core
cargo test --release --features search
# Build native modules after CI passes
build:
name: Build - ${{ matrix.settings.target }}
runs-on: ${{ matrix.settings.host }}
needs: ci-check
defaults:
run:
working-directory: crates/opencontext-node
strategy:
fail-fast: false
matrix:
settings:
# macOS
- host: macos-latest
target: x86_64-apple-darwin
build: npm run build -- --target x86_64-apple-darwin
- host: macos-latest
target: aarch64-apple-darwin
build: npm run build -- --target aarch64-apple-darwin
# Windows (only x64, ARM64 requires special cross-compilation setup)
- host: windows-latest
target: x86_64-pc-windows-msvc
build: npm run build -- --target x86_64-pc-windows-msvc
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
cache-dependency-path: crates/opencontext-node/package-lock.json
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.settings.target }}
- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
workspaces: crates/opencontext-node -> target
key: ${{ matrix.settings.target }}
- name: Install Protobuf (macOS)
if: runner.os == 'macOS'
run: brew install protobuf
working-directory: .
- name: Install Protobuf (Windows)
if: runner.os == 'Windows'
run: choco install protoc -y
working-directory: .
- name: Install dependencies
run: npm ci --omit=optional
- name: Build native module
run: ${{ matrix.settings.build }}
shell: bash
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: bindings-${{ matrix.settings.target }}
path: crates/opencontext-node/*.node
if-no-files-found: error
# Publish to npm after build succeeds
publish:
name: Publish to npm
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/
- name: Install dependencies
run: npm ci --omit=optional
working-directory: crates/opencontext-node
- name: Get version
id: version
run: |
if [ "${{ github.event.inputs.version }}" != "" ]; then
VERSION="${{ github.event.inputs.version }}"
elif [[ "${{ github.ref }}" == refs/tags/v* ]]; then
VERSION="${{ github.ref_name }}"
VERSION="${VERSION#v}"
else
VERSION="0.0.0-dev"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION"
shell: bash
- name: Update version
working-directory: crates/opencontext-node
run: |
npm version ${{ steps.version.outputs.version }} --no-git-tag-version --allow-same-version
shell: bash
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: crates/opencontext-node/artifacts
- name: List downloaded artifacts
working-directory: crates/opencontext-node
run: |
echo "=== Artifacts directory structure ==="
find artifacts -type f -name "*.node" 2>/dev/null || echo "No .node files found"
ls -laR artifacts/ || echo "artifacts dir not found"
- name: Setup npm packages manually
working-directory: crates/opencontext-node
run: |
node << 'SCRIPT'
const fs = require('fs');
const path = require('path');
const version = require('./package.json').version;
console.log('Version:', version);
const targets = [
{ rust: 'x86_64-apple-darwin', npm: 'darwin-x64', os: 'darwin', cpu: 'x64' },
{ rust: 'aarch64-apple-darwin', npm: 'darwin-arm64', os: 'darwin', cpu: 'arm64' },
{ rust: 'x86_64-pc-windows-msvc', npm: 'win32-x64-msvc', os: 'win32', cpu: 'x64' }
];
for (const t of targets) {
const artifactDir = `artifacts/bindings-${t.rust}`;
const npmDir = `npm/${t.npm}`;
if (!fs.existsSync(artifactDir)) {
console.log(`Warning: ${artifactDir} not found`);
continue;
}
console.log(`Processing ${t.rust} -> ${npmDir}`);
fs.mkdirSync(npmDir, { recursive: true });
// Copy .node file
const files = fs.readdirSync(artifactDir).filter(f => f.endsWith('.node'));
for (const f of files) {
const src = path.join(artifactDir, f);
const dst = path.join(npmDir, `opencontext-node.${t.npm}.node`);
fs.copyFileSync(src, dst);
console.log(`Copied ${src} -> ${dst}`);
}
// Create package.json
const pkg = {
name: `@aicontextlab/core-native-${t.npm}`,
version: version,
os: [t.os],
cpu: [t.cpu],
main: `opencontext-node.${t.npm}.node`,
files: [`opencontext-node.${t.npm}.node`],
license: 'ISC',
repository: {
type: 'git',
url: 'https://github.com/0xranx/OpenContext'
}
};
fs.writeFileSync(path.join(npmDir, 'package.json'), JSON.stringify(pkg, null, 2));
}
console.log('=== npm directory structure ===');
SCRIPT
ls -laR npm/
- name: Publish native packages
working-directory: crates/opencontext-node
run: |
for dir in npm/*/; do
echo "Publishing $dir"
(cd "$dir" && npm publish --access public) || true
done
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Update optionalDependencies versions
working-directory: crates/opencontext-node
run: |
node << 'SCRIPT'
const fs = require('fs');
const pkg = require('./package.json');
const version = pkg.version;
// Update optionalDependencies to match the current version
if (pkg.optionalDependencies) {
for (const dep of Object.keys(pkg.optionalDependencies)) {
if (dep.startsWith('@aicontextlab/core-native-')) {
pkg.optionalDependencies[dep] = version;
console.log(`Updated ${dep} to ${version}`);
}
}
}
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
console.log('package.json updated');
SCRIPT
- name: Publish main package
working-directory: crates/opencontext-node
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}