Skip to content
Open
81 changes: 81 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: "release"

on:
push:
tags:
- "v*"

jobs:
build-x64:
name: "Release for linux-amd64"
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: '20'
architecture: x64

- run: |
npm ci
npm run build
npm pack

- name: Verify package contents
run: |
echo "Verifying package contains required files..."
tar -tzf *.tgz | grep "package/build/src/context.js" || (echo "ERROR: context.js not found in package" && exit 1)
tar -tzf *.tgz | grep "package/build/src/index.js" || (echo "ERROR: index.js not found in package" && exit 1)
echo "Package verification successful"

- name: Rename package with suffix
run: |
for file in *.tgz; do
if [ -f "$file" ]; then
mv "$file" "${file%.tgz}-linux-amd64.tgz"
fi
done

- name: Create Release
uses: marvinpinto/action-automatic-releases@latest
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: false
files: |
*-linux-amd64.tgz

build-arm64:
name: "Release for linux-arm64"
runs-on: ubuntu-latest
needs: build-x64
steps:
- name: Checkout the repository
uses: actions/checkout@v4

- name: Build in ARM64 Docker container
run: |
docker run --rm -v ${{ github.workspace }}:/workspace -w /workspace node:20-bullseye bash -c "
npm ci &&
npm run build &&
npm pack &&
echo 'Verifying package contents...' &&
tar -tzf *.tgz | grep 'package/build/src/context.js' || (echo 'ERROR: context.js not found in package' && exit 1) &&
tar -tzf *.tgz | grep 'package/build/src/index.js' || (echo 'ERROR: index.js not found in package' && exit 1) &&
echo 'Package verification successful'
"

- name: Rename package with suffix
run: |
for file in *.tgz; do
if [ -f "$file" ]; then
mv "$file" "${file%.tgz}-linux-arm64.tgz"
fi
done

- name: Upload Release Asset
run: gh release upload ${{ github.ref_name }} *-linux-arm64.tgz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@
"url": "https://github.com/o1-labs/Archive-Node-API"
},
"main": "build/src/index.js",
"start": "build/src/index.js",
"bin": {
"archive-node-api": "build/src/index.js"
},
"type": "module",
"files": [
"build/**/*",
"schema.graphql"
],
"scripts": {
"build": "npm run clean && npx tsc",
"start": "node build/src/index.js",
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env node
import * as dotenv from 'dotenv';
dotenv.config();

Expand Down
11 changes: 10 additions & 1 deletion src/resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { makeExecutableSchema } from '@graphql-tools/schema';
import { loadSchemaSync } from '@graphql-tools/load';
import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';

import { Resolvers } from './resolvers-types.js';
import {
Expand Down Expand Up @@ -45,9 +47,16 @@ const resolvers: Resolvers = {
},
};

// Get the directory containing this module file
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

// Resolve schema.graphql relative to the package root (two levels up from build/src/)
const schemaPath = join(__dirname, '..', '..', 'schema.graphql');

const schema = makeExecutableSchema({
resolvers: [resolvers],
typeDefs: loadSchemaSync('./schema.graphql', {
typeDefs: loadSchemaSync(schemaPath, {
loaders: [new GraphQLFileLoader()],
}),
});
Loading