Skip to content

Commit

Permalink
add a publish workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
arvid220u committed Feb 17, 2024
1 parent e44dba4 commit 10061c3
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 8 deletions.
102 changes: 102 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Publish

on:
push:
branches: [main, publish]
pull_request:

env:
DEBUG: "napi:*"
MACOSX_DEPLOYMENT_TARGET: "10.13"

jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: tiktoken-node
strategy:
matrix:
target:
- x86_64-pc-windows-msvc
- x86_64-unknown-linux-gnu
- aarch64-unknown-linux-gnu
- x86_64-apple-darwin
- aarch64-apple-darwin

steps:
- uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x

- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
targets: ${{ matrix.target }}

- uses: Swatinem/rust-cache@v2

- name: Install ziglang
uses: goto-bus-stop/setup-zig@v1
with:
version: 0.10.0

- run: cargo install cargo-xwin
if: matrix.target == 'x86_64-pc-windows-msvc'

- name: Check formatting
run: cargo fmt --all --check

- name: Node install
run: npm i

- name: Build Mac and Linux
if: matrix.target != 'x86_64-pc-windows-msvc'
run: npm run build -- --zig --target ${{ matrix.target }}

- name: Build Windows
if: matrix.target == 'x86_64-pc-windows-msvc'
run: npm run build -- --target ${{ matrix.target }}

- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: OS specific binaries
path: dist
if-no-files-found: error

publish:
if: ${{ github.repository == 'anysphere/priompt' && github.event_name == 'push' && github.ref == 'refs/heads/publish' }}
runs-on: ubuntu-20.04
needs: build

steps:
- uses: actions/checkout@v3

- name: Download build
uses: actions/download-artifact@v3
with:
name: OS specific binaries
path: dist/

- name: Publish to npm
uses: JS-DevTools/npm-publish@v1
with:
package: tiktoken-node
token: ${{ secrets.NPM_TOKEN }}

- name: Publish to npm
uses: JS-DevTools/npm-publish@v1
with:
package: priompt
token: ${{ secrets.NPM_TOKEN }}

- name: Publish to npm
uses: JS-DevTools/npm-publish@v1
with:
package: priompt-preview
token: ${{ secrets.NPM_TOKEN }}
19 changes: 13 additions & 6 deletions publish.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#!/bin/bash

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
cd "$SCRIPT_DIR"

if [[ -n $(git status --porcelain) ]]; then
echo -e "${RED}Your git state is not empty. Aborting the script...${NC}"
exit 1
fi

# Check if a version bumping flag is provided
if [ $# -ne 1 ]; then
Expand All @@ -27,11 +33,12 @@ npm version $1
cd $SCRIPT_DIR/tiktoken-node
npm version $1

cd $SCRIPT_DIR/priompt
pnpm publish-to-npm
git commit -am "update version"

cd $SCRIPT_DIR/priompt-preview
pnpm publish-to-npm
git push

cd $SCRIPT_DIR/tiktoken-node
pnpm publish-to-npm
DEPLOY_BRANCH=publish
git branch -D $DEPLOY_BRANCH || true
git checkout -b $DEPLOY_BRANCH
git push origin $DEPLOY_BRANCH -f
git checkout $CURRENT_BRANCH
7 changes: 5 additions & 2 deletions tiktoken-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
"name": "tiktoken-node",
"triples": {
"additional": [
"aarch64-apple-darwin",
"universal-apple-darwin"
"x86_64-pc-windows-msvc",
"x86_64-unknown-linux-gnu",
"aarch64-unknown-linux-gnu",
"x86_64-apple-darwin",
"aarch64-apple-darwin"
]
}
},
Expand Down

0 comments on commit 10061c3

Please sign in to comment.