codemp/.github/workflows/javascript.yml

90 lines
3 KiB
YAML
Raw Normal View History

2024-09-09 19:48:41 +02:00
name: javascript
on:
push:
branches:
- stable
permissions:
contents: read
jobs:
build:
runs-on: ${{ matrix.platform.runner }}
strategy:
2024-09-09 19:54:20 +02:00
fail-fast: false
2024-09-09 19:48:41 +02:00
matrix:
platform:
- runner: ubuntu-latest
target: linux-x64-gnu
2024-09-09 22:02:06 +02:00
- runner: windows-latest
target: win32-x64
2024-09-10 00:04:25 +02:00
- runner: macos-14
target: darwin-arm64
2024-09-09 19:48:41 +02:00
steps:
- uses: actions/checkout@v4
- uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
2024-09-09 19:48:41 +02:00
- uses: dtolnay/rust-toolchain@stable
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm install
2024-09-13 22:56:32 +02:00
working-directory: dist/js
- run: npx napi build --cargo-cwd=../.. --platform --release --features=js --strip
working-directory: dist/js
2024-09-09 19:48:41 +02:00
- uses: actions/upload-artifact@v4
with:
name: codemp-js-${{ matrix.platform.target }}
2024-09-13 22:56:32 +02:00
path: dist/js/codemp.*.node
2024-09-09 19:48:41 +02:00
publish:
runs-on: ubuntu-latest
needs: [build]
steps:
# TODO we need index.d.ts and index.js but those get auto generated with napi build
# we could upload them from one of the previous runs but its messy, so we'll waste
# some github resources and build another time here, discarding the binary
- uses: actions/checkout@v4
- uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
2024-09-09 19:48:41 +02:00
- uses: dtolnay/rust-toolchain@stable
- uses: actions/setup-node@v4
with:
node-version: '20'
2024-09-09 22:08:11 +02:00
registry-url: 'https://registry.npmjs.org'
2024-09-09 19:48:41 +02:00
- run: npm install
2024-09-13 22:56:32 +02:00
working-directory: dist/js
- run: npx napi build --cargo-cwd=../.. --platform --features=js
working-directory: dist/js
- run: rm *.node
2024-09-13 22:56:32 +02:00
working-directory: dist/js
2024-09-09 23:05:27 +02:00
- run: npx napi create-npm-dir -t .; tree
2024-09-13 22:56:32 +02:00
working-directory: dist/js
- uses: actions/download-artifact@v4
with:
2024-09-13 22:56:32 +02:00
path: dist/js/artifacts
pattern: codemp-js-*
2024-09-09 23:05:27 +02:00
- run: npx napi artifacts; tree
2024-09-13 22:56:32 +02:00
working-directory: dist/js
- run: npx napi prepublish -t . --skip-gh-release
2024-09-13 22:56:32 +02:00
working-directory: dist/js
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- run: rm -rf *.node artifacts node_modules npm
2024-09-13 22:56:32 +02:00
working-directory: dist/js
- run: cp ../../README.md .
working-directory: dist/js
# TODO this is a bit awful, but napi just appends the platform triplet to the resulting package name
# however we want '@codemp/native-...' and 'codemp' (because otherwise it gets flagged as spam)
# so we just sed out before releasing. this is really ugly but if it works right now i'll just
# take it and think again about it later
- run: sed -i 's/"@codemp\/native"/"codemp"/' package.json
2024-09-13 22:56:32 +02:00
working-directory: dist/js
2024-09-09 22:02:06 +02:00
- run: npm publish
2024-09-13 22:56:32 +02:00
working-directory: dist/js
2024-09-09 22:02:06 +02:00
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}