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

feat: add log-level lib #1

Merged
merged 14 commits into from
Jan 6, 2025
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
66 changes: 66 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"env": {
"commonjs": true,
"es6": true,
"node": true,
},
"extends": [
"semistandard",
"plugin:n/recommended", // Uses the recommended rules from eslint-plugin-n (node)
"plugin:@typescript-eslint/recommended", // Uses the recommended rules from the @typescript-eslint/eslint-plugin
"prettier", // enables eslint-plugin-prettier and displays prettier errors as ESLint errors. (must be the last config in extends array)
],
"ignorePatterns": ["node_modules/", "artifacts", "dist"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"ecmaVersion": 2018,
"sourceType": "module", // Allows for the use of imports
},
"settings": {
"import/parsers": {
"@typescript-eslint/parser": [".ts"],
},
"import/resolver": {
"typescript": {
"alwaysTryTypes": true, // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
"project": "./tsconfig.json",
},
},
},
"rules": {
"comma-dangle": ["warn", "always-multiline"],
"curly": ["error", "all"],
"max-len": ["error", { "code": 120 }],
"mocha/no-async-describe": "error",
"mocha/no-exclusive-tests": "error",
"no-nested-ternary": "error",
"padded-blocks": "off",
"space-before-function-paren": "off",
"no-useless-constructor": "off",
"n/no-process-exit": "off",
"n/no-unsupported-features/es-syntax": "off",
"n/no-missing-import": "off", // disable as it conflicts with TS compiling to ES modules.
"n/no-unpublished-import": "off",
"n/no-extraneous-import": "error",
"import/no-unresolved": "error", // replaces the above n/no-missing-import
"no-use-before-define": "off", // disable as it conflicts with @typescript-eslint/no-use-before-define
"@typescript-eslint/no-use-before-define": "error",
"prettier/prettier": "error", // Ensure Prettier discrepancies are treated as errors
"import/order": [
1,
{
"groups": ["builtin", "external", "internal", ["parent", "sibling", "index"], "object", "type"],
"alphabetize": { "order": "asc", "caseInsensitive": true },
"newlines-between": "always",
},
],
},
"plugins": [
"mocha",
"import",
"@typescript-eslint",
"prettier", // so prettier errors shows up in eslint
],
"root": true,
}
138 changes: 138 additions & 0 deletions .github/workflows/merge-master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
name: release

on:
push:
branches:
- master

env:
NODE_VERSION: '18'
CACHE_KEY: ${{ secrets.CACHE_KEY }} # Change to bust caches

jobs:
version:
runs-on: ubuntu-22.04
outputs:
local_version: ${{ steps.local_version.outputs.value }}
registry_version: ${{ steps.registry_version.outputs.value }}
steps:
- name: GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"

- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- name: Get local version
id: local_version
run: |
version=$(cat ./package.json | jq --raw-output .version)
echo $version
echo "value=$version" >> $GITHUB_OUTPUT

- name: Get registry version
id: registry_version
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
run: |
package_name="$(cat ./package.json | jq --raw-output .name)"
echo $package_name
version=$(npm view $package_name version || echo "0.0.0")
echo $version
echo "value=$version" >> $GITHUB_OUTPUT

- name: Validate version
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const local_version = '${{ steps.local_version.outputs.value }}';
const registry_version = '${{ steps.registry_version.outputs.value }}';
core.info(`Repository version: ${local_version}`);
core.info(`Registry version: ${registry_version}`);
if (registry_version === local_version) {
core.setFailed('Please bump version before merging');
}

build:
runs-on: ubuntu-22.04
needs: [version]
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- uses: actions/cache@v3
id: cache
with:
path: node_modules
key: ${{ runner.os }}-${{ env.CACHE_KEY }}-${{ hashFiles('package-lock.json') }}

- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm ci --ignore-scripts

- name: Build package
run: npm run build

- name: Run linter
run: npm run lint

- name: Check types and typescript
run: npm run ts:check

- name: Run tests
run: npm run test

- uses: actions/upload-artifact@v3
with:
name: utils-${{ needs.version.outputs.local_version }}
path: dist

publish:
runs-on: ubuntu-22.04
needs: [version, build]
environment: production
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: 'https://registry.npmjs.org'

- uses: actions/download-artifact@v3
with:
name: utils-${{ needs.version.outputs.local_version }}
path: dist

- name: Remove prepare script
run: npm pkg delete scripts.prepare

- name: Publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
run: npm publish --access public

- name: Create release
uses: actions/github-script@v6
with:
github-token: '${{ github.token }}'
script: |
try {
const response = await github.rest.repos.createRelease({
name: "${{ needs.version.outputs.local_version }}",
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: "${{ needs.version.outputs.local_version }}",
generate_release_notes: true,
});
} catch (error) {
core.setFailed(error.message);
}
103 changes: 103 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: pull-request
on:
pull_request:
types: [opened, synchronize]
workflow_dispatch:
inputs:
CACHE_KEY: # Provide inputs.CACHE_KEY manually from UI to bust cache
description: "Cache key override"
required: false
default: "v1"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
NODE_VERSION: "18"
CACHE_KEY: ${{ inputs.CACHE_KEY || 'v1' }}
PROVIDER_URL: https://eth-mainnet.g.alchemy.com/v2/${{ secrets.ALCHEMY_API_KEY }}
IPFS_GATEWAY_URL: https://api.nexusmutual.io
COVER_ROUTER_URL: https://api.nexusmutual.io/v2

jobs:
version:
runs-on: ubuntu-22.04
if: github.base_ref == 'master'
outputs:
local_version: ${{ steps.local_version.outputs.value }}
registry_version: ${{ steps.registry_version.outputs.value }}
steps:
- name: GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"

- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- name: Get local version
id: local_version
run: |
version=$(cat ./package.json | jq --raw-output .version)
echo $version
echo "value=$version" >> $GITHUB_OUTPUT

- name: Get registry version
id: registry_version
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
run: |
package_name="$(cat ./package.json | jq --raw-output .name)"
echo $package_name
version=$(npm view $package_name version)
echo $version
echo "value=$version" >> $GITHUB_OUTPUT

- name: Validate version
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const local_version = '${{ steps.local_version.outputs.value }}';
const registry_version = '${{ steps.registry_version.outputs.value }}';
core.info(`Repository version: ${local_version}`);
core.info(`Registry version: ${registry_version}`);
if (registry_version === local_version) {
core.setFailed('Please bump version before merging');
}

checks:
runs-on: ubuntu-22.04
needs: [version]
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- uses: actions/cache@v3
id: cache
with:
path: ~/.npm
key: ${{ runner.os }}-${{ env.CACHE_KEY }}-${{ hashFiles('package-lock.json') }}

- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm ci --ignore-scripts

- name: Build package
run: npm run build

- name: Run linter
run: npm run lint

- name: Check types and typescript
run: npm run ts:check

- name: Run tests
run: npm run test
Loading