diff --git a/.github/workflows/build-node.yaml b/.github/workflows/build-node.yaml new file mode 100644 index 0000000..7709b17 --- /dev/null +++ b/.github/workflows/build-node.yaml @@ -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 diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml deleted file mode 100644 index 6f3be34..0000000 --- a/.github/workflows/build.yaml +++ /dev/null @@ -1,31 +0,0 @@ -name: Build and Run - -on: [push] - -jobs: - build-and-run: - 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 diff --git a/.github/workflows/publish-node.yaml b/.github/workflows/publish-node.yaml new file mode 100644 index 0000000..240d2f4 --- /dev/null +++ b/.github/workflows/publish-node.yaml @@ -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 }} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index f63e55e..8519332 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "native-certs", + "name": "@robocorp/native-certs", "version": "0.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "native-certs", + "name": "@robocorp/native-certs", "version": "0.1.0", "hasInstallScript": true, "license": "ISC", diff --git a/package.json b/package.json index 694b526..b89908e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/postinstall.js b/postinstall.js new file mode 100644 index 0000000..74d839f --- /dev/null +++ b/postinstall.js @@ -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);