Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Actions for build and publish && postinstall script #2

Merged
merged 8 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/build-node.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# name: Build and Test Node Addon

# on: [push]

# jobs:
# build-and-test:
# runs-on: ${{ matrix.os }}

# strategy:
# matrix:
# os: [ubuntu-latest, windows-latest, macos-latest]

# steps:
# - name: Check out the code
# uses: actions/checkout@v2

# - name: Set up Node.js
# uses: actions/setup-node@v2
# with:
# node-version: '18'

# - name: Set up Rust
# uses: actions-rs/toolchain@v1
# with:
# toolchain: stable

# - name: Install and build package
# run: npm install

# - name: Run test
# run: npm start
31 changes: 0 additions & 31 deletions .github/workflows/build.yaml

This file was deleted.

77 changes: 77 additions & 0 deletions .github/workflows/publish-node.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Publish Node Addon

on:
push:
tags:
- 'v*'

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Check out the code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
registry-url: 'https://npm.pkg.github.com'

- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable

- name: Build package
run: npm run build-release

- name: Run test
run: npm start

- name: Rename and move binary
run: |
mkdir -p ./binaries
mv index.node ./binaries/index-${{ matrix.os }}.node

- name: Upload binary artifact
uses: actions/upload-artifact@v2
with:
name: binary-${{ matrix.os }}
path: ./binaries/index-${{ matrix.os }}.node

publish:
needs: build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
registry-url: 'https://npm.pkg.github.com/'
scope: '@robocorp'

- name: Download all artifacts
uses: actions/download-artifact@v2
with:
path: ./artifacts

- name: Prepare package
run: |
mkdir -p ./binaries
mv ./artifacts/binary-ubuntu-latest/index-ubuntu-latest.node ./binaries/
mv ./artifacts/binary-windows-latest/index-windows-latest.node ./binaries/
mv ./artifacts/binary-macos-latest/index-macos-latest.node ./binaries/

- name: Publish to GitHub Packages
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.CI_GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
{
"name": "native-certs",
"name": "@robocorp/native-certs",
"version": "0.1.0",
"description": "",
"main": "index.node",
"module": "index.node",
"publishConfig": {
"access": "restricted"
},
"files": [
"target"
],
"scripts": {
"build": "cargo-cp-artifact -nc index.node -- cargo build --message-format=json-render-diagnostics",
"build-debug": "npm run build --",
"build-release": "npm run build -- --release",
"install": "npm run build-release",
"start": "node test.js",
"test": "cargo test"
"test": "cargo test",
"postinstall": "node postinstall.js"
},
"author": "",
"license": "ISC",
Expand Down
30 changes: 30 additions & 0 deletions postinstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const fs = require('fs');
const path = require('path');

const binariesDir = path.join(__dirname, 'binaries');
const osType = process.platform;

let binaryName;
switch (osType) {
case 'win32':
binaryName = 'index-windows-latest.node';
break;
case 'linux':
binaryName = 'index-ubuntu-latest.node';
break;
case 'darwin':
binaryName = 'index-macos-latest.node';
break;
default:
throw new Error(`Unsupported platform: ${osType}`);
}

const binaryPath = path.join(binariesDir, binaryName);
const targetPath = path.join(__dirname, 'index.node');

if (!fs.existsSync(binaryPath)) {
console.log(`Binary not found: ${binaryPath}. Skipping setup.`);
process.exit(0); // Exit gracefully
}

fs.renameSync(binaryPath, targetPath);