Skip to content
Draft
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
26 changes: 26 additions & 0 deletions .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Publish npm package

on:
release:
types: [published]

permissions:
contents: read
id-token: write

jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
registry-url: https://registry.npmjs.org

- name: Publish to npm
run: npm publish --provenance
61 changes: 61 additions & 0 deletions install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env node

// For NPM publishing purposes

const fs = require("fs");
const path = require("path");

const version = require("./package.json").version;

const platform = process.platform;
const arch = process.arch;

function getAssetName() {
if (platform === "linux" && arch === "x64") {
return `noir-v${version}-linux-x86_64`;
}

if (platform === "linux" && arch === "arm64") {
return `noir-v${version}-linux-arm64`;
}

if (platform === "darwin" && arch === "arm64") {
return `noir-v${version}-osx-arm64`;
}

if (platform === "darwin" && arch === "x64") {
return `noir-v${version}-osx-x86_64`;
}

throw new Error(`Unsupported platform: ${platform} ${arch}`);
}

(async () => {
const asset = getAssetName();

const downloadUrl =
`https://github.com/owasp-noir/noir/releases/download/v${version}/${asset}`;

const binDir = path.join(__dirname, "bin");
const output = path.join(binDir, "noir");

fs.mkdirSync(binDir, { recursive: true });

console.log(`Downloading ${asset}...`);

const response = await fetch(downloadUrl);

if (!response.ok) {
throw new Error(`Download failed (${response.status})`);
}

const buffer = Buffer.from(await response.arrayBuffer());

fs.writeFileSync(output, buffer);
fs.chmodSync(output, 0o755);

console.log("Binary installed.");
})().catch((err) => {
console.error(err.message);
process.exit(1);
});
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "@owasp-noir/noir",
"version": "1.1.0",
"description": "OWASP Noir CLI",
"license": "MIT",
"bin": {
"noir": "./bin/noir"
},
"scripts": {
"postinstall": "node install.js"
},
"files": [
"install.js"
],
"engines": {
"node": ">=18"
}
}