From 6fd6c73d0c3ab802ac47a81914ff2d9687ba277c Mon Sep 17 00:00:00 2001 From: Bogdan Condurache Date: Mon, 13 Nov 2023 20:40:44 +0100 Subject: [PATCH 1/8] CI/CD and postinstall script --- .../workflows/{build.yaml => build-node.yaml} | 4 +- .github/workflows/publish-node.yaml | 75 +++++++++++++++++++ package.json | 3 +- postinstall.js | 25 +++++++ 4 files changed, 104 insertions(+), 3 deletions(-) rename .github/workflows/{build.yaml => build-node.yaml} (91%) create mode 100644 .github/workflows/publish-node.yaml create mode 100644 postinstall.js diff --git a/.github/workflows/build.yaml b/.github/workflows/build-node.yaml similarity index 91% rename from .github/workflows/build.yaml rename to .github/workflows/build-node.yaml index 6f3be34..f430e76 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build-node.yaml @@ -1,9 +1,9 @@ -name: Build and Run +name: Build and Test Node Addon on: [push] jobs: - build-and-run: + build-and-test: runs-on: ${{ matrix.os }} strategy: diff --git a/.github/workflows/publish-node.yaml b/.github/workflows/publish-node.yaml new file mode 100644 index 0000000..03d83b6 --- /dev/null +++ b/.github/workflows/publish-node.yaml @@ -0,0 +1,75 @@ +name: Publish Node Addon + +on: + push: + tags: + - 'v*' + +jobs: + build-and-publish: + 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: Install and build package + run: npm install + + - name: Run test + run: npm start + + - name: Rename and move binary + run: | + 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' + + - 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.GITHUB_TOKEN }} \ No newline at end of file diff --git a/package.json b/package.json index 694b526..4a2c359 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "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..379d76c --- /dev/null +++ b/postinstall.js @@ -0,0 +1,25 @@ +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'); + +fs.renameSync(binaryPath, targetPath); From dbc5ee0bde855e59b850764a1675598dd881ed30 Mon Sep 17 00:00:00 2001 From: Bogdan Condurache Date: Mon, 13 Nov 2023 20:48:29 +0100 Subject: [PATCH 2/8] fix pipeline --- .github/workflows/build-node.yaml | 4 ++-- .github/workflows/publish-node.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-node.yaml b/.github/workflows/build-node.yaml index f430e76..766818e 100644 --- a/.github/workflows/build-node.yaml +++ b/.github/workflows/build-node.yaml @@ -24,8 +24,8 @@ jobs: with: toolchain: stable - - name: Install and build package - run: npm install + - name: Build package + run: npm run build-release - name: Run test run: npm start diff --git a/.github/workflows/publish-node.yaml b/.github/workflows/publish-node.yaml index 03d83b6..bc464e4 100644 --- a/.github/workflows/publish-node.yaml +++ b/.github/workflows/publish-node.yaml @@ -28,8 +28,8 @@ jobs: with: toolchain: stable - - name: Install and build package - run: npm install + - name: Build package + run: npm run build-release - name: Run test run: npm start From 73a06772509c46a9759fd5384b6da39948975432 Mon Sep 17 00:00:00 2001 From: Bogdan Condurache Date: Mon, 13 Nov 2023 20:54:39 +0100 Subject: [PATCH 3/8] conditional postinstall --- postinstall.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/postinstall.js b/postinstall.js index 379d76c..74d839f 100644 --- a/postinstall.js +++ b/postinstall.js @@ -22,4 +22,9 @@ switch (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); From c795ecda6826c3279041dc92eb0da6c85ada2da8 Mon Sep 17 00:00:00 2001 From: Bogdan Condurache Date: Mon, 13 Nov 2023 20:58:47 +0100 Subject: [PATCH 4/8] temp changes to test new pipeline --- .github/workflows/build-node.yaml | 46 ++++++++++++++--------------- .github/workflows/publish-node.yaml | 5 +--- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/.github/workflows/build-node.yaml b/.github/workflows/build-node.yaml index 766818e..ede0ed5 100644 --- a/.github/workflows/build-node.yaml +++ b/.github/workflows/build-node.yaml @@ -1,31 +1,31 @@ -name: Build and Test Node Addon +# name: Build and Test Node Addon -on: [push] +# on: [push] -jobs: - build-and-test: - runs-on: ${{ matrix.os }} +# jobs: +# build-and-test: +# runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] +# strategy: +# matrix: +# os: [ubuntu-latest, windows-latest, macos-latest] - steps: - - name: Check out the code - uses: actions/checkout@v2 +# 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 Node.js +# uses: actions/setup-node@v2 +# with: +# node-version: 18 - - name: Set up Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable +# - name: Set up Rust +# uses: actions-rs/toolchain@v1 +# with: +# toolchain: stable - - name: Build package - run: npm run build-release +# - name: Install and build package +# run: npm install - - name: Run test - run: npm start +# - name: Run test +# run: npm start diff --git a/.github/workflows/publish-node.yaml b/.github/workflows/publish-node.yaml index bc464e4..585f84c 100644 --- a/.github/workflows/publish-node.yaml +++ b/.github/workflows/publish-node.yaml @@ -1,9 +1,6 @@ name: Publish Node Addon -on: - push: - tags: - - 'v*' +on: [push] jobs: build-and-publish: From 9367947284531305f421555e09350f60f3a631ac Mon Sep 17 00:00:00 2001 From: Bogdan Condurache Date: Mon, 13 Nov 2023 21:01:49 +0100 Subject: [PATCH 5/8] fix identation --- .github/workflows/publish-node.yaml | 56 ++++++++++++++--------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/.github/workflows/publish-node.yaml b/.github/workflows/publish-node.yaml index 585f84c..5dfb36f 100644 --- a/.github/workflows/publish-node.yaml +++ b/.github/workflows/publish-node.yaml @@ -41,32 +41,32 @@ jobs: name: binary-${{ matrix.os }} path: ./binaries/index-${{ matrix.os }}.node -publish: - needs: build - runs-on: ubuntu-latest + 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' - - - 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.GITHUB_TOKEN }} \ No newline at end of file + 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' + + - 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.GITHUB_TOKEN }} \ No newline at end of file From e344c375fb132cc383f498bde521ca027df9ec9f Mon Sep 17 00:00:00 2001 From: Bogdan Condurache Date: Mon, 13 Nov 2023 21:03:31 +0100 Subject: [PATCH 6/8] name fix --- .github/workflows/publish-node.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-node.yaml b/.github/workflows/publish-node.yaml index 5dfb36f..022baf5 100644 --- a/.github/workflows/publish-node.yaml +++ b/.github/workflows/publish-node.yaml @@ -3,7 +3,7 @@ name: Publish Node Addon on: [push] jobs: - build-and-publish: + build: runs-on: ${{ matrix.os }} strategy: From e97fa6a08b9620bc0300cbe9bd7da19a4321be61 Mon Sep 17 00:00:00 2001 From: Bogdan Condurache Date: Mon, 13 Nov 2023 21:12:59 +0100 Subject: [PATCH 7/8] small fix + node 18 --- .github/workflows/build-node.yaml | 2 +- .github/workflows/publish-node.yaml | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-node.yaml b/.github/workflows/build-node.yaml index ede0ed5..7709b17 100644 --- a/.github/workflows/build-node.yaml +++ b/.github/workflows/build-node.yaml @@ -17,7 +17,7 @@ # - name: Set up Node.js # uses: actions/setup-node@v2 # with: -# node-version: 18 +# node-version: '18' # - name: Set up Rust # uses: actions-rs/toolchain@v1 diff --git a/.github/workflows/publish-node.yaml b/.github/workflows/publish-node.yaml index 022baf5..adce1e5 100644 --- a/.github/workflows/publish-node.yaml +++ b/.github/workflows/publish-node.yaml @@ -17,7 +17,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v2 with: - node-version: 18 + node-version: '18' registry-url: 'https://npm.pkg.github.com' - name: Set up Rust @@ -33,6 +33,7 @@ jobs: - name: Rename and move binary run: | + mkdir -p ./binaries mv index.node ./binaries/index-${{ matrix.os }}.node - name: Upload binary artifact @@ -51,7 +52,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v2 with: - node-version: 18 + node-version: '18' registry-url: 'https://npm.pkg.github.com' - name: Download all artifacts From a77845bb7879f222ece4a0f5307965ce6a118498 Mon Sep 17 00:00:00 2001 From: Matti Mokko Date: Thu, 16 Nov 2023 08:34:51 +0200 Subject: [PATCH 8/8] Add npm publish information Publish the package privately to only robocorp organization. --- .github/workflows/publish-node.yaml | 10 +++++++--- package-lock.json | 4 ++-- package.json | 9 ++++++++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish-node.yaml b/.github/workflows/publish-node.yaml index adce1e5..240d2f4 100644 --- a/.github/workflows/publish-node.yaml +++ b/.github/workflows/publish-node.yaml @@ -1,6 +1,9 @@ name: Publish Node Addon -on: [push] +on: + push: + tags: + - 'v*' jobs: build: @@ -53,7 +56,8 @@ jobs: uses: actions/setup-node@v2 with: node-version: '18' - registry-url: 'https://npm.pkg.github.com' + registry-url: 'https://npm.pkg.github.com/' + scope: '@robocorp' - name: Download all artifacts uses: actions/download-artifact@v2 @@ -70,4 +74,4 @@ jobs: - name: Publish to GitHub Packages run: npm publish env: - NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + 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 4a2c359..b89908e 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,15 @@ { - "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 --",