diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eb2a101..aa54e22 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -162,6 +162,49 @@ jobs: artifacts/* fi + # ── Publish to npm ───────────────────────────────────────────────────── + # Requires: + # 1. Package claimed on npmjs.com: @vmvarela/sql-pipe + # 2. Trusted Publishing configured on npmjs.com for repo vmvarela/sql-pipe, workflow release.yml + # 3. No NPM_TOKEN secret needed — uses OIDC (id-token: write) + publish-npm: + name: Publish to npm + needs: release + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + steps: + - name: Download all artifacts + uses: actions/download-artifact@v8 + with: + path: artifacts/ + merge-multiple: true + + - name: Stage npm binaries + run: | + mkdir -p npm-pkg/bin + cp artifacts/sql-pipe-x86_64-linux npm-pkg/bin/sql-pipe-linux-x64 + cp artifacts/sql-pipe-aarch64-linux npm-pkg/bin/sql-pipe-linux-arm64 + cp artifacts/sql-pipe-armv7-linux npm-pkg/bin/sql-pipe-linux-arm + cp artifacts/sql-pipe-x86_64-macos npm-pkg/bin/sql-pipe-darwin-x64 + cp artifacts/sql-pipe-aarch64-macos npm-pkg/bin/sql-pipe-darwin-arm64 + cp artifacts/sql-pipe-x86_64-windows.exe npm-pkg/bin/sql-pipe-win32-x64.exe + chmod +x npm-pkg/bin/sql-pipe-linux-* npm-pkg/bin/sql-pipe-darwin-* + + - name: Copy packaging files + run: | + cp -r packaging/npm/* npm-pkg/ + + - name: Set package version + run: | + VERSION="${GITHUB_REF_NAME#v}" + npm version "$VERSION" --no-git-tag-version --workspaces=false --prefix ./npm-pkg + + - name: Publish to npm + run: npm publish ./npm-pkg --provenance --access public + continue-on-error: true + # ── Update Homebrew tap ───────────────────────────────────────────── # Requires: # 1. Repository: vmvarela/homebrew-tap (with a Formula/ directory) diff --git a/README.md b/README.md index 753d5a4..ff1935b 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,12 @@ By default it installs to `/usr/local/bin`. Override with `INSTALL_DIR`: curl -sSL https://raw.githubusercontent.com/vmvarela/sql-pipe/master/install.sh | INSTALL_DIR="$HOME/.local/bin" sh ``` +**npm (Node.js ≥ 18):** + +```sh +npm install -g @vmvarela/sql-pipe +``` + **Debian / Ubuntu (APT repository):** ```sh diff --git a/packaging/npm/.npmignore b/packaging/npm/.npmignore new file mode 100644 index 0000000..22046dd --- /dev/null +++ b/packaging/npm/.npmignore @@ -0,0 +1,5 @@ +# Include only what's in files[] +* +!bin/ +!package.json +!LICENSE \ No newline at end of file diff --git a/packaging/npm/bin/sql-pipe.js b/packaging/npm/bin/sql-pipe.js new file mode 100644 index 0000000..b16f65d --- /dev/null +++ b/packaging/npm/bin/sql-pipe.js @@ -0,0 +1,37 @@ +#!/usr/bin/env node + +const { spawnSync } = require('child_process'); +const path = require('path'); + +const BINARIES = { + 'linux-x64': 'sql-pipe-linux-x64', + 'linux-arm64': 'sql-pipe-linux-arm64', + 'linux-arm': 'sql-pipe-linux-arm', + 'darwin-x64': 'sql-pipe-darwin-x64', + 'darwin-arm64': 'sql-pipe-darwin-arm64', + 'win32-x64': 'sql-pipe-win32-x64.exe', +}; + +const key = `${process.platform}-${process.arch}`; +const binary = BINARIES[key]; + +if (!binary) { + const supported = Object.keys(BINARIES).join(', '); + console.error( + `sql-pipe: unsupported platform "${key}". Supported platforms: ${supported}` + ); + process.exit(1); +} + +const result = spawnSync( + path.join(__dirname, binary), + process.argv.slice(2), + { stdio: 'inherit' } +); + +if (result.error) { + console.error(`sql-pipe: failed to run binary: ${result.error.message}`); + process.exit(1); +} + +process.exit(result.status === null ? 1 : result.status); \ No newline at end of file diff --git a/packaging/npm/package.json b/packaging/npm/package.json new file mode 100644 index 0000000..9530590 --- /dev/null +++ b/packaging/npm/package.json @@ -0,0 +1,25 @@ +{ + "name": "@vmvarela/sql-pipe", + "version": "0.24.0", + "description": "Read CSV from stdin, query with SQL, write CSV to stdout", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/vmvarela/sql-pipe.git" + }, + "homepage": "https://github.com/vmvarela/sql-pipe", + "bugs": "https://github.com/vmvarela/sql-pipe/issues", + "bin": { + "sql-pipe": "bin/sql-pipe.js" + }, + "files": [ + "bin/" + ], + "engines": { + "node": ">=18" + }, + "keywords": [ + "csv", "sql", "cli", "sqlite", "etl", "data" + ], + "author": "vmvarela " +} \ No newline at end of file