Build Shinkai Tools #125
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Shinkai Tools | |
on: | |
workflow_dispatch: | |
inputs: | |
node_version: | |
description: 'Shinkai Node version to use (e.g. 0.9.7)' | |
required: true | |
type: string | |
default: "0.9.7" | |
use_dev_prefix: | |
description: 'Use dev prefix for download URL (e.g. https://download.shinkai.com/dev-tools-0.9.7)' | |
required: true | |
type: boolean | |
default: true | |
jobs: | |
run_tests: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Install Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
profile: minimal | |
- name: Install b3sum | |
run: cargo install b3sum | |
- name: Setup Deno | |
uses: denoland/setup-deno@v2 | |
with: | |
deno-version: v2.x | |
- name: Install dependencies | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y curl jq zip unzip coreutils | |
- name: Run node in background | |
id: run_node | |
env: | |
INITIAL_AGENT_NAMES: ${{ secrets.INITIAL_AGENT_NAMES }} | |
INITIAL_AGENT_URLS: ${{ secrets.INITIAL_AGENT_URLS }} | |
INITIAL_AGENT_MODELS: ${{ secrets.INITIAL_AGENT_MODELS }} | |
INITIAL_AGENT_API_KEYS: ${{ secrets.INITIAL_AGENT_API_KEYS }} | |
API_V2_KEY: ${{ secrets.API_V2_KEY }} | |
EMBEDDINGS_SERVER_URL: ${{ secrets.EMBEDDINGS_SERVER_URL }} | |
SHINKAI_NODE_ADDR: "http://localhost:9550" | |
BEARER_TOKEN: ${{ secrets.API_V2_KEY }} | |
INITIALIZATION_DATA: ${{ secrets.INITIALIZATION_DATA }} | |
DOWNLOAD_PREFIX: ${{ inputs.use_dev_prefix && 'https://download.shinkai.com/dev-tools-' || 'https://download.shinkai.com/tools-' }}${{ inputs.node_version }} | |
SKIP_IMPORT_FROM_DIRECTORY: true | |
SHINKAI_STORE_ADDR: "https://shinkai-store-302883622007.us-central1.run.app" | |
SHINKAI_STORE_TOKEN: ${{ secrets.SHINKAI_STORE_TOKEN }} | |
USE_DOCKER: true | |
SHINKAI_NODE_IMAGE: "dcsparkdevops/shinkai-node:${{ inputs.node_version }}" | |
run: | | |
./scripts/run_node.sh & | |
timeout 60 bash -c 'until curl -s --location "$SHINKAI_NODE_ADDR/v2/health_check" | jq -e ".status == \"ok\"" > /dev/null; do sleep 1; done' | |
curl --location "$SHINKAI_NODE_ADDR/v2/initial_registration" \ | |
--header 'Content-Type: application/json; charset=utf-8' \ | |
--data "$INITIALIZATION_DATA" | |
rm -rf ./packages && mkdir ./packages | |
deno test --allow-read --allow-write --allow-env --allow-net --allow-run scripts/ | |
rm -rf ./shinkai-node/storage | |
build_tools: | |
needs: run_tests | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Install Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
profile: minimal | |
- name: Install b3sum | |
run: cargo install b3sum | |
- name: Setup Deno | |
uses: denoland/setup-deno@v2 | |
with: | |
deno-version: v2.x | |
- name: Install dependencies | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y curl jq zip unzip coreutils | |
- name: Run node in background | |
id: run_node | |
env: | |
INITIAL_AGENT_NAMES: ${{ secrets.INITIAL_AGENT_NAMES }} | |
INITIAL_AGENT_URLS: ${{ secrets.INITIAL_AGENT_URLS }} | |
INITIAL_AGENT_MODELS: ${{ secrets.INITIAL_AGENT_MODELS }} | |
INITIAL_AGENT_API_KEYS: ${{ secrets.INITIAL_AGENT_API_KEYS }} | |
API_V2_KEY: ${{ secrets.API_V2_KEY }} | |
EMBEDDINGS_SERVER_URL: ${{ secrets.EMBEDDINGS_SERVER_URL }} | |
SHINKAI_NODE_ADDR: "http://localhost:9550" | |
BEARER_TOKEN: ${{ secrets.API_V2_KEY }} | |
INITIALIZATION_DATA: ${{ secrets.INITIALIZATION_DATA }} | |
DOWNLOAD_PREFIX: ${{ inputs.use_dev_prefix && 'https://download.shinkai.com/dev-tools-' || 'https://download.shinkai.com/tools-' }}${{ inputs.node_version }} | |
SKIP_IMPORT_FROM_DIRECTORY: true | |
SHINKAI_STORE_ADDR: "https://shinkai-store-302883622007.us-central1.run.app" | |
SHINKAI_STORE_TOKEN: ${{ secrets.SHINKAI_STORE_TOKEN }} | |
USE_DOCKER: true | |
SHINKAI_NODE_IMAGE: "dcsparkdevops/shinkai-node:${{ inputs.node_version }}" | |
run: | | |
./scripts/run_node.sh & | |
timeout 60 bash -c 'until curl -s --location "$SHINKAI_NODE_ADDR/v2/health_check" | jq -e ".status == \"ok\"" > /dev/null; do sleep 1; done' | |
curl --location "$SHINKAI_NODE_ADDR/v2/initial_registration" \ | |
--header 'Content-Type: application/json; charset=utf-8' \ | |
--data "$INITIALIZATION_DATA" | |
rm -rf ./packages && mkdir ./packages | |
deno run --allow-read --allow-write --allow-env --allow-net --allow-run scripts/build_tools.ts | |
- name: Install AWS CLI v2 (R2 compatible version) | |
id: install_aws_cli | |
run: | | |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64-2.22.25.zip" -o /tmp/awscliv2.zip | |
unzip -q /tmp/awscliv2.zip -d /tmp | |
rm /tmp/awscliv2.zip | |
sudo /tmp/aws/install --update | |
rm -rf /tmp/aws/ | |
- name: Upload to Cloudflare R2 | |
if: steps.run_node.outcome == 'success' && steps.install_aws_cli.outcome == 'success' | |
env: | |
R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }} | |
R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }} | |
R2_BUCKET: ${{ secrets.R2_BUCKET }} | |
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
CLOUDFLARE_ZONE: ${{ secrets.CLOUDFLARE_ZONE }} | |
CLOUDFLARE_TOKEN: ${{ secrets.CLOUDFLARE_CACHE_INVALIDATION_TOKEN }} | |
DOWNLOAD_PREFIX: ${{ inputs.use_dev_prefix && 'https://download.shinkai.com/dev-tools-' || 'https://download.shinkai.com/tools-' }}${{ inputs.node_version }} | |
run: | | |
export AWS_ACCESS_KEY_ID=${R2_ACCESS_KEY_ID} | |
export AWS_SECRET_ACCESS_KEY=${R2_SECRET_ACCESS_KEY} | |
export AWS_ENDPOINT_URL=https://${CLOUDFLARE_ACCOUNT_ID}.r2.cloudflarestorage.com | |
UPLOAD_PATH=${{ inputs.use_dev_prefix && format('dev-tools-{0}', inputs.node_version) || format('tools-{0}', inputs.node_version) }} | |
aws configure set default.s3.max_concurrent_requests 1 | |
aws s3 sync ./packages/ s3://${R2_BUCKET}/${UPLOAD_PATH}/ --exclude "*" --include "*.zip" --include "directory.json" \ | |
--endpoint-url https://${CLOUDFLARE_ACCOUNT_ID}.r2.cloudflarestorage.com | |
deno run --allow-read --allow-env --allow-net scripts/invalidate_cache.ts | |