Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add npm package to homestar runtime #434

Merged
merged 26 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 17 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
81 changes: 76 additions & 5 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ on:
types: [published]

# for debugging
hugomrdias marked this conversation as resolved.
Show resolved Hide resolved
# pull_request:
# branches: [ '**' ]
pull_request:
branches: [ '**' ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# concurrency:
zeeshanlakhani marked this conversation as resolved.
Show resolved Hide resolved
hugomrdias marked this conversation as resolved.
Show resolved Hide resolved
# group: ${{ github.workflow }}-${{ github.ref }}
# cancel-in-progress: true

jobs:
binary-builds:
Expand All @@ -30,14 +30,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:
Expand Down Expand Up @@ -95,6 +100,72 @@ 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"
- run: echo ${{ github.event_name }}
- name: Publish production
if: github.event_name == 'release' && github.event.action == 'published'
run: |
cd "homestar-runtime/npm/${{ env.node_pkg }}"
pnpm -r publish --access=public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
- name: Publish RC
if: github.event_name == 'workflow_dispatch' || github.event_name == 'pull_request'
zeeshanlakhani marked this conversation as resolved.
Show resolved Hide resolved
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}}

hugomrdias marked this conversation as resolved.
Show resolved Hide resolved


build-packages:
runs-on: ubuntu-latest
strategy:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@ examples/**/tmp/*

# nix build results
/result

# npm packages
homestar-runtime/npm/binaries
4 changes: 2 additions & 2 deletions Cross.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
hugomrdias marked this conversation as resolved.
Show resolved Hide resolved
image = "burntsushi/cross:aarch64-unknown-linux-gnu"

[target.x86_64-apple-darwin]
image = "freeznet/x86_64-apple-darwin-cross:11.3"
Expand Down
42 changes: 42 additions & 0 deletions homestar-runtime/npm/base/index.js
Original file line number Diff line number Diff line change
@@ -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()
Loading
Loading