Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

publish to npm #179

Merged
merged 6 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/actions/setup-and-build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: "Setup and build the repo"
description: "A task to reuse setup steps during multiple jobs"
inputs:
node:
description: Node version
required: true

runs:
using: "composite"
steps:
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: ${{inputs.node}}
check-latest: true
cache: yarn

- name: Node.js version
id: node
shell: bash
run: echo "v8CppApiVersion=$(node --print "process.versions.modules")" >> $GITHUB_OUTPUT

- name: Restore build
uses: actions/cache/restore@v4
id: cache-build-restore
with:
path: |
node_modules
packages/*/node_modules
lib/
packages/*/lib
packages/*/.git-data.json
key: ${{ runner.os }}-${{ runner.arch }}-node-${{ inputs.node }}-${{ github.sha }}

- name: Install & build
if: steps.cache-build-restore.outputs.cache-hit != 'true'
shell: bash
run: yarn install --frozen-lockfile && yarn build

- name: Build
if: steps.cache-build-restore.outputs.cache-hit == 'true'
shell: bash
run: yarn build

- name: Check Build
shell: bash
run: yarn check-build

- name: Cache build artifacts
uses: actions/cache@master
with:
path: |
node_modules
packages/*/node_modules
lib/
packages/*/lib
packages/*/.git-data.json
key: ${{ runner.os }}-${{ runner.arch }}-node-${{ inputs.node }}-${{ github.sha }}
56 changes: 56 additions & 0 deletions .github/workflows/binaries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Build binaries

on:
workflow_dispatch:
inputs:
version:
required: true
type: string
workflow_call:
inputs:
version:
required: true
type: string

jobs:
binaries:
name: Build skandha binaries
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
platform: linux
arch: amd64
- os: skandha-arm64-runner
platform: linux
arch: arm64
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4
- name: Install arm64 specifics
run: |-
# Install missing yarn
# See https://github.com/github-early-access/arm-runners-beta/issues/5
curl -fsSL --create-dirs -o $HOME/bin/yarn \
https://github.com/yarnpkg/yarn/releases/download/v1.22.22/yarn-1.22.22.js
chmod +x $HOME/bin/yarn
echo "$HOME/bin" >> $GITHUB_PATH
# Install missing build-essential
sudo apt-get update
sudo apt-get install -y build-essential
- uses: "./.github/actions/setup-and-build"
with:
node: 20
- run: |
mkdir -p dist
yarn global add [email protected]
npx caxa -m "Unpacking skandha binary, please wait..." -D -p "yarn install --frozen-lockfile --production" --input . --output "skandha" -- "{{caxa}}/node_modules/.bin/node" "--max-old-space-size=8192" "{{caxa}}/node_modules/.bin/skandha"
tar -czf "dist/skandha-${{ inputs.version }}-${{ matrix.platform }}-${{ matrix.arch }}.tar.gz" "skandha"
- name: Upload binaries
if: ${{ !github.event.act }} # skip during local actions testing
uses: actions/upload-artifact@v4
with:
name: binaries-${{ matrix.os }}
path: dist/
if-no-files-found: error
108 changes: 99 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,105 @@ on:
- "master"

jobs:
build:
tag:
name: Check tag
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get tag
id: get_tag
run: echo "tag=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT

- name: Assert tag == package.json version
run: ./.github/workflows/scripts/assert-same-package-version.sh
env:
TAG: ${{ steps.get_tag.outputs.tag }}

- name: Get previous tag
id: get_prev_tag
run: node tasks/get_prev_tag.js
env:
CURRENT_TAG: ${{ steps.get_tag.outputs.tag }}
IGNORE_PATTERN: rc
outputs:
tag: ${{ steps.get_tag.outputs.tag }}
prev_tag: ${{ steps.get_prev_tag.outputs.prev_tag }}

binaries:
name: Build skandha binaries
uses: ./.github/workflows/binaries.yml
needs: tag
with:
version: ${{ needs.tag.outputs.tag }}

npm:
name: Publish to NPM & Github
runs-on: ubuntu-latest
needs: [tag, binaries]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Needs full depth for changelog generation

- name: Install arm64 specifics
run: |-
# Install missing yarn
# See https://github.com/github-early-access/arm-runners-beta/issues/5
curl -fsSL --create-dirs -o $HOME/bin/yarn \
https://github.com/yarnpkg/yarn/releases/download/v1.22.22/yarn-1.22.22.js
chmod +x $HOME/bin/yarn
echo "$HOME/bin" >> $GITHUB_PATH
# Install missing build-essential
sudo apt-get update
sudo apt-get install -y build-essential
- uses: "./.github/actions/setup-and-build"
with:
node: 20

- name: Get binaries
uses: actions/download-artifact@v4
with:
path: dist/
merge-multiple: true

- name: Create Release
id: create_release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: dist/*
fail_on_unmatched_files: true
tag_name: ${{ needs.tag.outputs.tag }}
body_path: "CHANGELOG.md"
body: Release ${{ needs.tag.outputs.tag }}
name: Release ${{ needs.tag.outputs.tag }}
prerelease: false
- run: echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > .npmrc
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish to npm registry (release)
if: ${{ !github.event.act }} # skip during local actions testing
run: yarn run release:publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Rollback on failure
if: failure()
uses: author/action-rollback@9ec72a6af74774e00343c6de3e946b0901c23013
with:
id: ${{ steps.create_release.outputs.id }}
tag: ${{ needs.tag.outputs.tag }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

docker:
if: ${{ !github.event.act }} # skip during local actions testing
runs-on: ubuntu-latest
steps:
-
Expand Down Expand Up @@ -40,14 +138,6 @@ jobs:
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/skandha:${{ steps.get_version.outputs.version }}
${{ secrets.DOCKERHUB_USERNAME }}/skandha:latest
-
name: Create GitHub release
uses: "marvinpinto/action-automatic-releases@6273874b61ebc8c71f1a61b2d98e234cf389b303"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: ${{ steps.get_version.outputs.version }}
prerelease: false
title: Release ${{ steps.get_version.outputs.version }}
-
name: Trigger pipeline
run: ${{ secrets.PIPELINE_TRIGGER }}
19 changes: 19 additions & 0 deletions .github/workflows/scripts/assert-same-package-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Our current release strategy does not gurantee that the tagged commit
# has the same version in the package.json.
#
# If that's not the case, no version will be published to NPM and a faulty image will be published to dockerhub

LOCAL_VERSION=$(jq -r .version lerna.json)

if [ -z "$TAG" ]; then
echo "ENV TAG is empty"
exit 1
fi

if [[ $TAG == *"$LOCAL_VERSION"* ]]; then
echo "TAG $TAG includes LOCAL_VERSION $LOCAL_VERSION"
exit 0
else
echo "TAG $TAG does not include LOCAL_VERSION $LOCAL_VERSION"
exit 1
fi
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ Temporary Items

dist
data
scripts/
/scripts/
**/lib
packages/*/lib
skandha
db
/db/

# foundry files
packages/contracts/cache/
Expand Down
4 changes: 4 additions & 0 deletions event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"act": true,
"ref": "refs/tags/1.5.6"
}
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@
"scripts": {
"clean": "rm -rf ./packages/*/lib ./packages/*/*.tsbuildinfo",
"bootstrap": "lerna bootstrap & lerna link",
"prebuild": "yarn workspace types run build",
"build": "yarn workspace types run build && yarn workspace db run build & lerna run build",
"prebuild": "yarn workspace @skandha/types run build",
"build-db": "yarn workspace @skandha/db run build",
"build": "yarn prebuild && yarn build-db & lerna run build",
"lint": "eslint --color --ext .ts packages/*/src/",
"fix-lint": "eslint --ext .ts --fix packages/*/src/",
"test": "lerna run test --concurrency 1",
"test:unit": "lerna run test:unit --no-bail --concurrency 1",
"coverage": "vitest run --coverage",
"check-build": "lerna run check-build",
"check-readme": "lerna run check-readme",
"release:publish": "lerna publish from-package --yes --no-verify-access",
"release:docker": "exit 0"
"release:docker": "exit 0",
"act": "act -W .github/workflows/release.yml -e event.json -b"
},
"dependencies": {
"abstract-leveldown": "7.2.0",
Expand Down
10 changes: 5 additions & 5 deletions packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "api",
"name": "@skandha/api",
"version": "1.5.6",
"description": "The API module of Etherspot bundler client",
"author": "Etherspot",
Expand Down Expand Up @@ -28,19 +28,19 @@
"check-readme": "typescript-docs-verifier"
},
"dependencies": {
"@skandha/executor": "^1.5.6",
"@skandha/monitoring": "^1.5.6",
"@skandha/types": "^1.5.6",
"@skandha/utils": "^1.5.6",
"@fastify/cors": "9.0.1",
"@fastify/websocket": "10.0.1",
"class-transformer": "0.5.1",
"class-validator": "0.14.1",
"ethers": "5.7.2",
"executor": "^1.5.6",
"fastify": "4.25.2",
"monitoring": "^1.5.6",
"pino": "8.11.0",
"pino-pretty": "10.0.0",
"reflect-metadata": "0.1.13",
"types": "^1.5.6",
"utils": "^1.5.6",
"ws": "8.16.0"
},
"devDependencies": {
Expand Down
10 changes: 5 additions & 5 deletions packages/api/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { WebSocket } from "ws";
import { Executor } from "executor/lib/executor";
import { Config } from "executor/lib/config";
import RpcError from "types/lib/api/errors/rpc-error";
import * as RpcErrorCodes from "types/lib/api/errors/rpc-error-codes";
import { deepHexlify } from "utils/lib/hexlify";
import { Executor } from "@skandha/executor/lib/executor";
import { Config } from "@skandha/executor/lib/config";
import RpcError from "@skandha/types/lib/api/errors/rpc-error";
import * as RpcErrorCodes from "@skandha/types/lib/api/errors/rpc-error-codes";
import { deepHexlify } from "@skandha/utils/lib/hexlify";
import {
BundlerRPCMethods,
CustomRPCMethods,
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/dto/SetReputation.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
IsNumber,
ValidateNested,
} from "class-validator";
import { ReputationStatus } from "types/lib/executor";
import { ReputationStatus } from "@skandha/types/lib/executor";

export class SetReputationEntry {
@IsEthereumAddress()
Expand Down
10 changes: 5 additions & 5 deletions packages/api/src/modules/debug.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { UserOperationStruct } from "types/lib/executor/contracts/EntryPoint";
import { Debug } from "executor/lib/modules";
import { UserOperationStruct } from "@skandha/types/lib/executor/contracts/EntryPoint";
import { Debug } from "@skandha/executor/lib/modules";
import { IsEthereumAddress } from "class-validator";
import { BundlingMode } from "types/lib/api/interfaces";
import { GetStakeStatus } from "executor/lib/interfaces";
import { MempoolEntrySerialized } from "executor/lib/entities/interfaces";
import { BundlingMode } from "@skandha/types/lib/api/interfaces";
import { GetStakeStatus } from "@skandha/executor/lib/interfaces";
import { MempoolEntrySerialized } from "@skandha/executor/lib/entities/interfaces";
import { RpcMethodValidator } from "../utils/RpcMethodValidator";
import {
SetReputationArgs,
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/modules/eth.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Eth } from "executor/lib/modules/eth";
import { Eth } from "@skandha/executor/lib/modules/eth";
import {
EstimatedUserOperationGas,
UserOperationByHashResponse,
UserOperationReceipt,
} from "types/lib/api/interfaces";
} from "@skandha/types/lib/api/interfaces";
import { RpcMethodValidator } from "../utils/RpcMethodValidator";
import { SendUserOperationGasArgs } from "../dto/SendUserOperation.dto";
import { EstimateUserOperationGasArgs } from "../dto/EstimateUserOperation.dto";
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/modules/redirect.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { providers } from "ethers";
import { Config } from "executor/lib/config";
import { Config } from "@skandha/executor/lib/config";

export class RedirectAPI {
private provider: providers.JsonRpcProvider;
Expand Down
Loading
Loading