Skip to content

Commit

Permalink
Download binaries from github releases
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Nov 13, 2024
1 parent 40452e5 commit 972c708
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 11 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
--debug \
--parallel 4 \
--CDTORCH_BACKEND_${{ steps.backend.outputs.uppercase }}=ON
cp build/Debug/executorch.node executorch-${{ matrix.backend }}-${{ matrix.os }}-${{ matrix.arch }}-debug.node
- name: Test
id: test
Expand All @@ -65,9 +66,7 @@ jobs:
yarn build \
--parallel 4 \
--CDTORCH_BACKEND_${{ steps.backend.outputs.uppercase }}=ON
- name: Prepare .node File
run: cp build/Release/executorch.node executorch-${{ matrix.backend }}-${{ matrix.os }}-${{ matrix.arch }}.node
cp build/Release/executorch.node executorch-${{ matrix.backend }}-${{ matrix.os }}-${{ matrix.arch }}-release.node
- name: Upload Binary Files
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -97,6 +96,6 @@ jobs:
uses: softprops/action-gh-release@v2
with:
draft: true
name: executorch.js ${{ github.ref_name }}
name: ExecuTorch.js ${{ github.ref_name }}
body: '## Changelog'
files: '*.gz'
26 changes: 20 additions & 6 deletions .github/workflows/post-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
# Required by npm publish.
registry-url: https://registry.npmjs.org

- name: Checkout
uses: actions/checkout@v4

Expand All @@ -23,9 +30,16 @@ jobs:
- name: Install deps
run: yarn

- name: Publish npm package
uses: JS-DevTools/npm-publish@v3
with:
token: ${{ secrets.NPM_TOKEN }}
access: public
ignore-scripts: false
- name: Publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
npm publish
npx dot-json package.json name @executorch/runtime
npm publish --access public
npx dot-json package.json name @executorch/runtime-cpu
npm publish --access public
npx dot-json package.json name @executorch/runtime-mps
npm publish --access public
npx dot-json package.json name @executorch/runtime-xnnpack
npm publish --access public
45 changes: 45 additions & 0 deletions install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env node

const packageJson = require('./package.json');

// Local developement.
if (packageJson.version === '0.0.1-dev')
process.exit(0);

const fs = require('node:fs');
const zlib = require('node:zlib');
const {pipeline} = require('node:stream/promises');

const urlPrefix = 'https://github.com/frost-beta/executorch.js/releases/download';

main().catch((error) => {
console.error('Error downloading node-mlx:', error);
process.exit(1);
});

async function main() {
const dir = `${__dirname}/build/Release`;
fs.mkdirSync(dir, {recursive: true});

const os = {darwin: 'mac', win32: 'win'}[process.platform] ?? process.platform;
const arch = process.arch;
const version = packageJson.version;

let backend;
if (packageJson.name.includes('-'))
backend = packageJson.name.substring(packageJson.name.lastIndexOf('-') + 1);
else
backend = os == 'mac' ? 'mps' : 'xnnpack';

const prefix = `${urlPrefix}/v${version}/executorch-${backend}-${os}-${arch}-release`;
await download(`${prefix}.node.gz`, `${dir}/executorch.node`);
}

async function download(url, filename) {
const response = await fetch(url);
if (!response.ok)
throw new Error(`Failed to download ${url}, status: ${response.status}`);

const gunzip = zlib.createGunzip();
await pipeline(response.body, gunzip, fs.createWriteStream(filename));
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"prebuild": "tsc --project tsconfig.json",
"install": "node install.js",
"prepack": "tsc",
"prebuild": "tsc",
"build": "cmake-js build",
"pretest": "tsc --project tests/tsconfig.json --noEmit",
"test": "tsx tests/run.ts"
Expand Down

0 comments on commit 972c708

Please sign in to comment.