diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index ae1ee665..e22ad4e9 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -1,7 +1,6 @@ name: ⚃ Builds # TODO: brew formula (Macs), cargo-wix (Windows Installs), cargo-aur (Arch) -# TODO: bring back release hook (vs on PR) on: workflow_dispatch: @@ -16,7 +15,7 @@ on: # for debugging # pull_request: - # branches: [ '**' ] + # branches: ['**'] concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -30,14 +29,19 @@ jobs: include: - target: aarch64-unknown-linux-gnu - target: aarch64-unknown-linux-musl + npm: linux-arm64 - target: aarch64-apple-darwin os: macos-latest + npm: darwin-arm64 - target: x86_64-unknown-linux-gnu - target: x86_64-unknown-linux-musl + npm: linux-x64 - target: x86_64-apple-darwin os: macos-latest + npm: darwin-x64 - target: x86_64-pc-windows-msvc os: windows-latest + npm: windows-x64 - target: x86_64-unknown-freebsd permissions: @@ -95,6 +99,69 @@ jobs: include: LICENSE,README.md token: ${{ secrets.GITHUB_TOKEN }} + npm-publish: + needs: binary-builds + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - target: aarch64-unknown-linux-musl + os: linux + arch: arm64 + - target: x86_64-unknown-linux-musl + os: linux + arch: x64 + - target: aarch64-apple-darwin + os: darwin + arch: arm64 + - target: x86_64-apple-darwin + os: darwin + arch: x64 + - target: x86_64-pc-windows-msvc + os: windows + arch: x64 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: lts/* + registry-url: 'https://registry.npmjs.org' + - name: Install cargo get + run: cargo install cargo-get + - name: Prepare os/arch packages + shell: bash + env: + node_os: ${{ matrix.os }} + node_arch: ${{ matrix.arch }} + node_pkg: homestar-${{ matrix.os }}-${{ matrix.arch }} + run: | + export node_version=$(cargo get workspace.package.version) + echo "node_pkg=${node_pkg}" >> "$GITHUB_ENV" + cd homestar-runtime/npm + mkdir -p "${node_pkg}/bin" + envsubst < package.json.tmpl > "${node_pkg}/package.json" + - name: Download build artifacts + uses: actions/download-artifact@v3 + with: + name: ${{ matrix.target }} + path: 'homestar-runtime/npm/${{ env.node_pkg }}/bin' + - name: Publish production + if: github.event_name == 'release' && github.event.action == 'published' + run: | + cd "homestar-runtime/npm/${{ env.node_pkg }}" + npm publish --access=public + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + - name: Publish RC + if: github.event_name == 'workflow_dispatch' + run: | + cd "homestar-runtime/npm/${{ env.node_pkg }}" + npm version $(cargo get package.version)-rc.$(date +%s) --git-tag-version false + npm publish --access public --tag rc + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + build-packages: runs-on: ubuntu-latest strategy: diff --git a/.gitignore b/.gitignore index 8e6e9508..2279e665 100644 --- a/.gitignore +++ b/.gitignore @@ -55,3 +55,6 @@ examples/**/tmp/* # nix build results /result + +# npm packages +homestar-runtime/npm/binaries \ No newline at end of file diff --git a/Cross.toml b/Cross.toml index ff92d71f..78ef8d29 100644 --- a/Cross.toml +++ b/Cross.toml @@ -17,8 +17,8 @@ passthrough = [ [target.x86_64-unknown-linux-musl] image = "burntsushi/cross:x86_64-unknown-linux-musl" -[target.aarch64-unknown-linux-musl] -image = "burntsushi/cross:aarch64-unknown-linux-musl" +[target.aarch64-unknown-linux-gnu] +image = "burntsushi/cross:aarch64-unknown-linux-gnu" [target.x86_64-apple-darwin] image = "freeznet/x86_64-apple-darwin-cross:11.3" diff --git a/README.md b/README.md index 345c2fdb..c452bed1 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ different platforms. - [homebrew][homebrew]: `brew install fission-codes/fission/homestar` This includes `ipfs` in the install by default. +- [npm](https://www.npmjs.com/package/homestar-runtime): `npm install homestar-runtime -g` Wraps the `homestar-runtime` binary in a node script. ## Running Examples diff --git a/homestar-runtime/npm/base/index.js b/homestar-runtime/npm/base/index.js new file mode 100644 index 00000000..65abe3ff --- /dev/null +++ b/homestar-runtime/npm/base/index.js @@ -0,0 +1,42 @@ +#!/usr/bin/env node + +import { execa } from 'execa' +import { createRequire } from 'module' +const require = createRequire(import.meta.url) + +/** + * Returns the executable path which is located inside `node_modules` + * The naming convention is app-${os}-${arch} + * If the platform is `win32` or `cygwin`, executable will include a `.exe` extension. + * @see https://nodejs.org/api/os.html#osarch + * @see https://nodejs.org/api/os.html#osplatform + * @example "x/xx/node_modules/app-darwin-arm64" + */ +function getExePath() { + const arch = process.arch + let os = process.platform + let extension = '' + if (['win32', 'cygwin'].includes(process.platform)) { + os = 'windows' + extension = '.exe' + } + + try { + // Since the binary will be located inside `node_modules`, we can simply call `require.resolve` + return require.resolve(`homestar-${os}-${arch}/bin/homestar${extension}`) + } catch (e) { + throw new Error( + `Couldn't find application binary inside node_modules for ${os}-${arch}` + ) + } +} + +/** + * Runs the application with args using nodejs spawn + */ +function run() { + const args = process.argv.slice(2) + execa(getExePath(), args, { stdio: 'inherit' }) +} + +run() diff --git a/homestar-runtime/npm/base/package-lock.json b/homestar-runtime/npm/base/package-lock.json new file mode 100644 index 00000000..dcf9b431 --- /dev/null +++ b/homestar-runtime/npm/base/package-lock.json @@ -0,0 +1,263 @@ +{ + "name": "homestar-runtime", + "version": "0.0.8", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "homestar-runtime", + "version": "0.0.8", + "license": "MIT", + "dependencies": { + "execa": "^8.0.1" + }, + "bin": { + "homestar": "index.js" + }, + "optionalDependencies": { + "homestar-darwin-arm64": "*", + "homestar-darwin-x64": "*", + "homestar-linux-arm64": "*", + "homestar-linux-x64": "*", + "homestar-windows-arm64": "*", + "homestar-windows-x64": "*" + } + }, + "node_modules/cross-spawn": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", + "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/execa": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/execa/-/execa-8.0.1.tgz", + "integrity": "sha512-VyhnebXciFV2DESc+p6B+y0LjSm0krU4OgJN44qFAhBY0TJ+1V61tYD2+wHusZ6F9n5K+vl8k0sTy7PEfV4qpg==", + "dependencies": { + "cross-spawn": "^7.0.3", + "get-stream": "^8.0.1", + "human-signals": "^5.0.0", + "is-stream": "^3.0.0", + "merge-stream": "^2.0.0", + "npm-run-path": "^5.1.0", + "onetime": "^6.0.0", + "signal-exit": "^4.1.0", + "strip-final-newline": "^3.0.0" + }, + "engines": { + "node": ">=16.17" + }, + "funding": { + "url": "https://github.com/sindresorhus/execa?sponsor=1" + } + }, + "node_modules/get-stream": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-8.0.1.tgz", + "integrity": "sha512-VaUJspBffn/LMCJVoMvSAdmscJyS1auj5Zulnn5UoYcY531UWmdwhRWkcGKnGU93m5HSXP9LP2usOryrBtQowA==", + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/homestar-darwin-arm64": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/homestar-darwin-arm64/-/homestar-darwin-arm64-0.0.1.tgz", + "integrity": "sha512-ftcZyXJalctBtj3jhTepLVE6LjNaB/k2KB9zAAZjQi6neAKs+MMTqaRt8TV3/X16hOryOeyjDPCshgbGnqpBJw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/homestar-darwin-x64": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/homestar-darwin-x64/-/homestar-darwin-x64-0.0.1.tgz", + "integrity": "sha512-DT4H2XnKD6bwjY/3ooYRwfqnP8maKlLp53ZOkeSPIWT8HDf7DI/6WJxeZZy8AGkMox5SU0xP64CrIQ3W/D57NA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/homestar-linux-arm64": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/homestar-linux-arm64/-/homestar-linux-arm64-0.0.1.tgz", + "integrity": "sha512-IKDrLIvZWmp1ZrcYyySV1xp7wOYOCHPELeuiOEd0a3YuHssURXS4CdibUGKXGnTnxv7w7bjNla5HAVyOnC/dNA==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/homestar-linux-x64": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/homestar-linux-x64/-/homestar-linux-x64-0.0.1.tgz", + "integrity": "sha512-LuY2HA3SM1B5B4LFpyb+eAKHFaKlEJ0vtkr/aFJCR9d0SA/omf3ZpqmeT4zDrCNgCnqT81rvVDjBOP094890zw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/human-signals": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-5.0.0.tgz", + "integrity": "sha512-AXcZb6vzzrFAUE61HnN4mpLqd/cSIwNQjtNWR0euPm6y0iqx3G4gOXaIDdtdDwZmhwe82LA6+zinmW4UBWVePQ==", + "engines": { + "node": ">=16.17.0" + } + }, + "node_modules/is-stream": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-3.0.0.tgz", + "integrity": "sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA==", + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" + }, + "node_modules/merge-stream": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", + "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==" + }, + "node_modules/mimic-fn": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-4.0.0.tgz", + "integrity": "sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/npm-run-path": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-5.1.0.tgz", + "integrity": "sha512-sJOdmRGrY2sjNTRMbSvluQqg+8X7ZK61yvzBEIDhz4f8z1TZFYABsqjjCBd/0PUNE9M6QDgHJXQkGUEm7Q+l9Q==", + "dependencies": { + "path-key": "^4.0.0" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/npm-run-path/node_modules/path-key": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-4.0.0.tgz", + "integrity": "sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/onetime": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-6.0.0.tgz", + "integrity": "sha512-1FlR+gjXK7X+AsAHso35MnyN5KqGwJRi/31ft6x0M194ht7S+rWAvd7PHss9xSKMzE0asv1pyIHaJYq+BbacAQ==", + "dependencies": { + "mimic-fn": "^4.0.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "engines": { + "node": ">=8" + } + }, + "node_modules/signal-exit": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", + "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/strip-final-newline": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-3.0.0.tgz", + "integrity": "sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + } + } +} diff --git a/homestar-runtime/npm/base/package.json b/homestar-runtime/npm/base/package.json new file mode 100644 index 00000000..d5a6669a --- /dev/null +++ b/homestar-runtime/npm/base/package.json @@ -0,0 +1,38 @@ +{ + "name": "homestar-runtime", + "version": "0.0.8", + "description": "The IPVM reference implementation", + "author": "Hugo Dias (hugodias.me)", + "homepage": "https://github.com/ipvm-wg/homestar/tree/main/homestar-runtime", + "repository": { + "url": "ipvm-wg/homestar", + "directory": "homestar-runtime" + }, + "keywords": [ + "homestar", + "wasm", + "wit", + "webassembly", + "workflows", + "scheduling" + ], + "bin": { + "homestar": "index.js" + }, + "type": "module", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "license": "Apache-2.0", + "optionalDependencies": { + "homestar-darwin-arm64": "*", + "homestar-darwin-x64": "*", + "homestar-linux-arm64": "*", + "homestar-linux-x64": "*", + "homestar-windows-arm64": "*", + "homestar-windows-x64": "*" + }, + "dependencies": { + "execa": "^8.0.1" + } +} diff --git a/homestar-runtime/npm/package.json.tmpl b/homestar-runtime/npm/package.json.tmpl new file mode 100644 index 00000000..90d0dc29 --- /dev/null +++ b/homestar-runtime/npm/package.json.tmpl @@ -0,0 +1,22 @@ +{ + "name": "${node_pkg}", + "version": "${node_version}", + "description": "The IPVM reference implementation", + "homepage": "https://github.com/ipvm-wg/homestar/tree/main/homestar-runtime", + "repository": { + "url": "ipvm-wg/homestar", + "directory": "homestar-runtime" + }, + "keywords": ["homestar", "wasm", "wit", "webassembly", "workflows", "scheduling"], + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Hugo Dias (hugodias.me)", + "license": "Apache-2.0", + "os": [ + "${node_os}" + ], + "cpu": [ + "${node_arch}" + ] +} diff --git a/homestar-runtime/npm/readme.md b/homestar-runtime/npm/readme.md new file mode 100644 index 00000000..cd51c934 --- /dev/null +++ b/homestar-runtime/npm/readme.md @@ -0,0 +1,75 @@ +# Homestar NPM packages + +## Packages + +- [homestar-runtime](https://www.npmjs.com/package/homestar-runtime) - This is the main package that installs the os specific binary package and runs it. +- [homestar-darwin-arm64](https://www.npmjs.com/package/homestar-darwin-arm64) +- [homestar-darwin-x64](https://www.npmjs.com/package/homestar-darwin-x64) +- [homestar-linux-arm64](https://www.npmjs.com/package/homestar-linux-arm64) +- [homestar-linux-x64](https://www.npmjs.com/package/homestar-linux-x64) +- [homestar-windows-x64](https://www.npmjs.com/package/homestar-windows-x64) + +## Usage + +```bash +npx homestar-runtime --help + +# Global install +npm install -g homestar-runtime +homestar start -c config.toml +``` + +## Manual publishing + +```bash + +rustup target add aarch64-unknown-linux-gnu +rustup target add x86_64-unknown-linux-musl +cargo install cargo-get + + +export node_version=$(cargo get workspace.package.version) +export bin="homestar" + + +## darwin arm64 +cargo build -p homestar-runtime --features ansi-logs --locked --release --target aarch64-apple-darwin +export node_os=darwin +export node_arch=arm64 +export node_pkg="${bin}-${node_os}-${node_arch}" +mkdir -p "binaries/${node_pkg}/bin" +envsubst < package.json.tmpl > "binaries/${node_pkg}/package.json" +cp "../../target/aarch64-apple-darwin/release/${bin}" "binaries/${node_pkg}/bin" + +## darwin x64 +cross build -p homestar-runtime --features ansi-logs --locked --release --target x86_64-apple-darwin +export node_os=darwin +export node_arch=x64 +export node_pkg="${bin}-${node_os}-${node_arch}" +mkdir -p "binaries/${node_pkg}/bin" +envsubst < package.json.tmpl > "binaries/${node_pkg}/package.json" +cp "../../target/x86_64-apple-darwin/release/${bin}" "binaries/${node_pkg}/bin" + +## linux arm64 +cross build -p homestar-runtime --features ansi-logs --locked --release --target aarch64-unknown-linux-gnu +export node_os=linux +export node_arch=arm64 +export node_pkg="${bin}-${node_os}-${node_arch}" +mkdir -p "binaries/${node_pkg}/bin" +envsubst < package.json.tmpl > "binaries/${node_pkg}/package.json" +cp "../../target/aarch64-unknown-linux-gnu/release/${bin}" "binaries/${node_pkg}/bin" + +## linux x64 +cross build -p homestar-runtime --features ansi-logs --locked --release --target x86_64-unknown-linux-musl +export node_os=linux +export node_arch=x64 +export node_pkg="${bin}-${node_os}-${node_arch}" +mkdir -p "binaries/${node_pkg}/bin" +envsubst < package.json.tmpl > "binaries/${node_pkg}/package.json" +cp "../../target/x86_64-unknown-linux-musl/release/${bin}" "binaries/${node_pkg}/bin" + +# publish the RC package +cd "${node_pkg}" +npm version $(cargo get package.version)-rc.$(date +%s) --git-tag-version false +npm publish --access public --tag rc +```