Skip to content

Commit

Permalink
Add a workflow to create a release PR (#19)
Browse files Browse the repository at this point in the history
* Add release pr workflow

* Add codeowners

* lint rules and wf

* add dynamic version
  • Loading branch information
LukeHackett12 authored Feb 27, 2024
1 parent 2420a0b commit 5ea1ac3
Show file tree
Hide file tree
Showing 29 changed files with 5,977 additions and 1,417 deletions.
35 changes: 35 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module.exports = {
"env": {
"browser": true,
"es2021": true
},
"extends": "standard-with-typescript",
"overrides": [
{
"env": {
"node": true
},
"files": [
".eslintrc.{js,cjs}"
],
"parserOptions": {
"sourceType": "script"
}
}
],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"ignorePatterns": ["**/dist/**"],
"rules": {
"@typescript-eslint/strict-boolean-expressions": 0,
"@typescript-eslint/comma-dangle": 0,
"@typescript-eslint/dot-notation": 0,
"@typescript-eslint/indent": 0,
"@typescript-eslint/consistent-type-definitions": 0,
"@typescript-eslint/non-nullable-type-assertion-style": 0,
"no-useless-catch": 0,
"new-cap": 0,
}
}
3 changes: 1 addition & 2 deletions .github/workflows/build-deploy-obol-sdk.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
name: Publish Obol-SDK to NPM

on:
workflow_dispatch:
push:
branches: [main]

jobs:
build:
if: github.event_name == 'workflow_dispatch' || (github.event.pull_request.merged == true && github.event.pull_request.head.label == 'obol-sdk:release')
if: github.event.pull_request.merged == true && github.event.pull_request.head.label == 'release'
runs-on: ubuntu-latest

steps:
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: 'Lint, Unit and E2E Tests'

on:
pull_request:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install SDK dependancies
run: yarn install --frozen-lockfile

- name: Check eslint rules
run: yarn run lint-ci

- name: Build SDK
run: yarn run build

- name: Run unit tests
run: yarn run test

- name: Install e2e dependancies
working-directory: ./test/sdk-package-test
run: yarn install --frozen-lockfile

- name: Build e2e
working-directory: ./test/sdk-package-test
run: yarn run build

- name: Run e2e tests
working-directory: ./test/sdk-package-test
run: yarn run test:e2e
73 changes: 73 additions & 0 deletions .github/workflows/release-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Release PR
on:
workflow_dispatch:
inputs:
type:
type: choice
description: Choose release type
options:
- auto
- patch
- minor
- major
default: auto
jobs:
releaseIt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: git config
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
- name: Setup node

- uses: actions/setup-node@v3
with:
node-version: 18.x
cache: npm

- name: Prepare release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TYPE_ARG: ${{ fromJSON('{"auto":"", "patch":"patch", "minor":"minor", "major":"major"}')[github.event.inputs.type] }}
run: npm run release -- $TYPE_ARG --ci --verbose --no-git.push --no-git.commit --no-git.tag --no-github

- name: Show git status
if: failure()
run: git status && git diff

- name: get-npm-version
id: package-version
uses: martinbeentjes/npm-get-version-action@main

- name: Extract release notes
id: extract-release-notes
uses: ffurrer2/extract-release-notes@v1

- name: Generate PR body
id: body
uses: mathiasvr/command-output@v1
with:
run: node ./bin/pr.js

- name: Create pull request
uses: peter-evans/create-pull-request@v4
id: cpr
with:
branch: release
delete-branch: true
commit-message: 'chore(release): v${{ steps.package-version.outputs.current-version}}'
title: '[Release] v${{ steps.package-version.outputs.current-version}}'
body: |
## Release notes:
${{ steps.extract-release-notes.outputs.release_notes }}
labels: |
release
automated pr
signoff: false
draft: false
7 changes: 0 additions & 7 deletions .prettierrc

This file was deleted.

4 changes: 4 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file sets up the designated owners of the infrastructure repo.
# All PR's will require a review from a member of the codeowners team.

* @ObolNetwork/sdk
21 changes: 21 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Obol Labs, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ This repo contains the Obol Software Development Kit, for creating Distributed V

## Getting Started

Checkout our [docs](https://docs.obol.tech/docs/advanced/quickstart-sdk), [examples](https://github.com/ObolNetwork/obol-sdk-examples/), and SDK [reference](https://obolnetwork.github.io/obol-packages). Further guides and walkthroughs coming soon.
Checkout our [docs](https://docs.obol.tech/docs/advanced/quickstart-sdk), [examples](https://github.com/ObolNetwork/obol-sdk-examples/), and SDK [reference](https://obolnetwork.github.io/obol-sdk). Further guides and walkthroughs coming soon.
20 changes: 13 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.12",
"description": "A package for creating Distributed Validators using the Obol API.",
"bugs": {
"url": "https://github.com/obolnetwork/obol-packages/issues"
"url": "https://github.com/obolnetwork/obol-sdk/issues"
},
"homepage": "https://docs.obol.tech/",
"keywords": [
Expand All @@ -17,18 +17,18 @@
"build": "npm-run-all build:clean compile",
"test": "jest ./test/methods.test.ts",
"generate-typedoc": "typedoc",
"ds:release": "npm publish --tag latest",
"ds:release:major": "npm version $(semver $npm_package_version -i major) && npm publish --tag latest",
"ds:release:minor": "npm version $(semver $npm_package_version -i minor) && npm publish --tag latest",
"ds:release:patch": "npm version $(semver $npm_package_version -i patch) && npm publish --tag latest"
"release": "release-it",
"release:dry": "release-it --dry-run --no-npm",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"lint-ci": "eslint \"{src,apps,libs,test}/**/*.ts\""
},
"main": "./dist/cjs/src/index.js",
"module": "./dist/esm/src/index.js",
"typings": "./dist/types/src/index.d.ts",
"author": "Obol Labs (https://obol.tech)",
"repository": {
"type": "git",
"url": "git+https://github.com/obolnetwork/obol-packages.git"
"url": "git+https://github.com/obolnetwork/obol-sdk.git"
},
"license": "ISC",
"publishConfig": {
Expand All @@ -44,16 +44,22 @@
"ajv": "^8.12.0",
"cross-fetch": "^3.1.5",
"elliptic": "^6.5.4",
"eslint-config-standard-with-typescript": "^43.0.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-promise": "^6.1.1",
"ethers": "^6.4.0",
"nock": "^13.5.3",
"release-it": "^17.1.1",
"typescript-eslint": "^7.1.0",
"uuid": "^9.0.0"
},
"devDependencies": {
"@types/elliptic": "^6.4.18",
"@types/jest": "^28.1.8",
"@types/node": "^20.2.5",
"@types/uuid": "^9.0.1",
"eslint": "^8.6.0",
"eslint": "^8.57.0",
"jest": "^28.1.3",
"msw": "^2.2.1",
"npm-run-all": "^4.1.5",
Expand Down
25 changes: 15 additions & 10 deletions src/ajv.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import Ajv, { ErrorObject } from 'ajv';
import Ajv, { type ErrorObject } from 'ajv'

export function validatePayload(data: any, schema: any): ErrorObject[] | undefined | null | boolean {
const ajv = new Ajv();
const validate = ajv.compile(schema);
const isValid = validate(data);
if (!isValid) {
throw new Error(`Schema compilation errors', ${validate.errors && validate.errors[0].message}`);
}
return isValid;
}
export function validatePayload (
data: any,
schema: any,
): ErrorObject[] | undefined | null | boolean {
const ajv = new Ajv()
const validate = ajv.compile(schema)
const isValid = validate(data)
if (!isValid) {
throw new Error(
`Schema compilation errors', ${validate.errors?.[0].message}`,
)
}
return isValid
}
46 changes: 25 additions & 21 deletions src/base.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
// src/resources/base.ts
import { DEFAULT_BASE_URL, DEFAULT_CHAIN_ID, SDK_VERSION } from './constants.js';
import { FORK_MAPPING } from './types.js';
import { DEFAULT_BASE_URL, DEFAULT_CHAIN_ID, SDK_VERSION } from './constants.js'
import { FORK_MAPPING } from './types.js'

type Config = {
baseUrl?: string;
chainId?: FORK_MAPPING;
};
interface Config {
baseUrl?: string
chainId?: FORK_MAPPING
}

export abstract class Base {
baseUrl: string;
chainId: number;
fork_version: string;


baseUrl: string
chainId: number
fork_version: string

constructor({ baseUrl = DEFAULT_BASE_URL, chainId = DEFAULT_CHAIN_ID }: Config) {
this.baseUrl = baseUrl;
this.chainId = chainId;
constructor ({
baseUrl = DEFAULT_BASE_URL,
chainId = DEFAULT_CHAIN_ID,
}: Config) {
this.baseUrl = baseUrl
this.chainId = chainId
this.fork_version = FORK_MAPPING[this.chainId]
}

protected async request<T>(endpoint: string, options?: RequestInit): Promise<T> {
protected async request<T>(
endpoint: string,
options?: RequestInit,
): Promise<T> {
const url = `${this.baseUrl}${endpoint}`
const config = {
...options,
headers: {
'Content-Type': 'application/json',
'User-Agent': `Obol-SDK/${SDK_VERSION}`,
...options?.headers
}
};
...options?.headers,
},
}

try {
const response = await fetch(url, config);
const response = await fetch(url, config)
if (response.ok) {
return (await response.json())
return await response.json()
}
throw new Error(response.statusText);
throw new Error(response.statusText)
} catch (e) {
throw e
}
Expand Down
Loading

0 comments on commit 5ea1ac3

Please sign in to comment.