Skip to content

Commit

Permalink
Add husky hooks, CI tests and purge dependencies (#5)
Browse files Browse the repository at this point in the history
* Add pre-push hook husky

* Fix .prettierignore

See: prettier/prettier#4081 (comment)

* Remove eslint functional, fix eslint issues

* Add GH actions workflow

* Fix tsc issues and tests

* Purge unused dependencies, move common dev deps to root

* Fix CI
  • Loading branch information
Siegrift authored Sep 18, 2023
1 parent 5c35a62 commit 0caa6a1
Show file tree
Hide file tree
Showing 26 changed files with 442 additions and 2,658 deletions.
24 changes: 0 additions & 24 deletions .eslintrc.fp.js

This file was deleted.

4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
root: true, // https://github.com/eslint/eslint/issues/13385#issuecomment-641252879
env: {
es6: true,
jest: true,
Expand All @@ -20,7 +21,6 @@ module.exports = {
'plugin:import/recommended',
'plugin:import/typescript',
'plugin:jest/recommended',
'.eslintrc.fp.js',
],
plugins: ['@typescript-eslint', 'import', 'jest'],
rules: {
Expand Down Expand Up @@ -61,7 +61,7 @@ module.exports = {
// ESLint
'comma-dangle': ['error', 'only-multiline'],
indent: 'off',
'no-console': 'warn',
'no-console': 'error',
'no-useless-escape': 'off',
semi: 'error',
eqeqeq: ['error', 'smart'],
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Continuous Build

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
documentation:
runs-on: ubuntu-latest
steps:
- name: Clone repo
uses: actions/checkout@v3
- name: Check hyperlinks
uses: gaurav-nelson/github-action-markdown-link-check@v1

lint-build-test:
runs-on: ubuntu-latest
name: Lint, build and test
steps:
- name: Clone repo
uses: actions/checkout@v3
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8.7.0
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '18.x'
cache: 'pnpm'
- name: Install Dependencies
run: pnpm install --frozen-lockfile
- name: Lint
run: pnpm run prettier:check && pnpm run eslint:check
- name: Build
run: pnpm run tsc
- name: Test
run: pnpm run test

required-checks-passed:
name: All required checks passed
runs-on: ubuntu-latest
needs: [lint-build-test]
steps:
- run: exit 0
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ build
dist
docker
node_modules
coverage
4 changes: 4 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

pnpm run prettier:check && pnpm run eslint:check
13 changes: 13 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* For a detailed explanation regarding each configuration property and type check, visit:
* https://jestjs.io/docs/configuration
*/
module.exports = {
clearMocks: true,
collectCoverage: true,
coverageDirectory: 'coverage',
coverageProvider: 'v8',
preset: 'ts-jest',
testEnvironment: 'jest-environment-node',
modulePathIgnorePatterns: ['<rootDir>/.build', '<rootDir>/dist/', '<rootDir>/build/'],
};
21 changes: 19 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,25 @@
"eslint:fix": "pnpm recursive run eslint:fix",
"prettier:check": "pnpm recursive run prettier:check",
"prettier:fix": "pnpm recursive run prettier:fix",
"tsc": "pnpm recursive run tsc"
"tsc": "pnpm recursive run tsc",
"test": "pnpm recursive run test"
},
"keywords": [],
"license": "MIT"
"license": "MIT",
"devDependencies": {
"@types/jest": "^28.1.6",
"@types/node": "^18.16.3",
"@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.1.3",
"eslint": "^8.43.0",
"husky": "^8.0.3",
"jest": "^28.1.3",
"prettier": "^2.8.8",
"rimraf": "^5.0.0",
"ts-jest": "^28.0.8",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
}
}
1 change: 1 addition & 0 deletions packages/api/.eslintignore
1 change: 1 addition & 0 deletions packages/api/.prettierignore
5 changes: 5 additions & 0 deletions packages/api/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const config = require('../../jest.config');

module.exports = {
...config,
};
24 changes: 8 additions & 16 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,27 @@
"dynamodb-local-down": "docker compose -f docker-compose.dynamodb-local.yml down ",
"init-tables": "LOCAL_DEV=true npx ts-node scripts/init-tables.ts",
"start-local": "LOCAL_DEV=true npx ts-node src/local-server.ts",
"prettier:check": "prettier --check \"./**/*.{js,ts,md,json,json.example}\"",
"prettier:write": "prettier --write \"./**/*.{js,ts,md,json,json.example}\"",
"eslint:check": "eslint . --ext .js,.ts",
"eslint:write": "eslint . --ext .js,.ts --fix",
"tsc": "tsc --project ."
"prettier:check": "prettier --check \"./**/*.{js,ts,md,json}\"",
"prettier:fix": "prettier --write \"./**/*.{js,ts,md,json}\"",
"eslint:check": "eslint . --ext .js,.ts --max-warnings 0",
"eslint:fix": "eslint . --ext .js,.ts --fix",
"tsc": "tsc --project .",
"test": "jest --passWithNoTests"
},
"license": "MIT",
"devDependencies": {
"@types/aws-lambda": "^8.10.115",
"@types/express": "^4.17.17",
"@types/lodash": "^4.14.194",
"@types/node": "^18.16.3",
"@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0",
"eslint": "^8.43.0",
"eslint-plugin-functional": "^5.0.8",
"eslint-plugin-import": "^2.27.5",
"prettier": "^2.8.8",
"serverless": "^3.30.1",
"serverless-plugin-typescript": "^2.1.4",
"ts-node": "^10.9.1",
"typescript": "^4.9.4"
"serverless": "^3.30.1"
},
"dependencies": {
"@api3/promise-utils": "0.3.0",
"aws-lambda": "^1.0.7",
"aws-sdk": "^2.1370.0",
"dotenv": "^16.0.3",
"ethers": "5.*",
"ethers": "^5.7.2",
"express": "^4.18.2",
"lodash": "^4.17.21",
"zod": "^3.21.4"
Expand Down
3 changes: 3 additions & 0 deletions packages/api/scripts/init-tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ export const POOL_TABLE_SCHEMA = {
};

export async function createTable(params: CreateTableInput) {
// eslint-disable-next-line no-console
console.log('Creating table with params: ', params);
try {
await ddbClient.createTable(params).promise();
} catch (e) {
// eslint-disable-next-line no-console
console.error('Unable to create table. Error JSON:', JSON.stringify(e, null, 2));
}
// eslint-disable-next-line no-console
console.log('Created table ', params.TableName);
}

Expand Down
1 change: 1 addition & 0 deletions packages/api/src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ if (process.env.LOCAL_DEV) {
endpoint: 'http://localhost:8000',
};
AWS.config.update(localAWSConfig);
// eslint-disable-next-line no-console
console.log('AWS SDK was configured for local development.');
}

Expand Down
1 change: 1 addition & 0 deletions packages/api/src/local-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ app.get('/', async (req, res) => {
});

const server = app.listen(port, () => {
// eslint-disable-next-line no-console
console.log(`Server listening at http://localhost:${port}`);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
"outDir": "dist"
},
"exclude": ["dist/**/*", "node_modules/**/*"],
"include": ["./src/**/*", "./test/**/*"]
"include": ["./src/**/*", "./test/**/*", "jest.config.js"]
}
1 change: 1 addition & 0 deletions packages/data-pusher/.eslintignore
1 change: 1 addition & 0 deletions packages/data-pusher/.prettierignore
5 changes: 5 additions & 0 deletions packages/data-pusher/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const config = require('../../jest.config');

module.exports = {
...config,
};
44 changes: 8 additions & 36 deletions packages/data-pusher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,66 +10,38 @@
"clean": "rimraf -rf ./ncc ./build ./dist *.tgz",
"compile": "tsc --build tsconfig.json",
"build:ncc": "ncc build -m -o ncc -s --target es2023 src/serverless.ts",
"dev:create-local-config": "ts-node scripts/create-local-config.js",
"dev:setup-local-node": "hardhat run scripts/setup-local-node.js",
"dev:api": "ts-node test/server/server.ts",
"dev:eth-node": "hardhat node",
"dev:testing-services:start": "pm2 start test/testing-services.config.js",
"dev:testing-services:stop": "pm2 delete test/testing-services.config.js",
"eslint:check": "eslint . --ext .js,.ts",
"eslint:check": "eslint . --ext .js,.ts --max-warnings 0",
"eslint:fix": "eslint . --ext .js,.ts --fix",
"prettier:check": "prettier --check \"./**/*.{js,ts,md,yml,json}\"",
"prettier:fix": "prettier --write \"./**/*.{js,ts,md,yml,json}\" --ignore-unknown",
"test": "SILENCE_LOGGER=true jest --selectProjects unit",
"test:e2e": "jest --selectProjects e2e --runInBand",
"prettier:fix": "prettier --write \"./**/*.{js,ts,md,yml,json}\"",
"test": "jest",
"tsc": "tsc --project ."
},
"license": "MIT",
"dependencies": {
"@api3/airnode-abi": "^0.11.1",
"@api3/airnode-adapter": "^0.11.1",
"@api3/airnode-node": "^0.11.1",
"@api3/airnode-protocol": "^0.11.1",
"@api3/airnode-protocol-v1": "^2.6.1",
"@api3/airnode-protocol": "^0.11.1",
"@api3/airnode-utilities": "^0.11.1",
"@api3/airnode-validator": "^0.11.1",
"@api3/ois": "^2.1.0",
"@api3/promise-utils": "^0.4.0",
"@vercel/ncc": "^0.36.1",
"axios": "^1.1.3",
"bottleneck": "^2.19.5",
"ethers": "^5.7.2",
"express": "^4.18.1",
"lodash": "^4.17.21",
"promise.any": "^2.0.4",
"source-map-support": "^0.5.21",
"zod": "^3.17.3"
},
"devDependencies": {
"@api3/airnode-admin": "^0.11.1",
"@nomiclabs/hardhat-ethers": "^2.2.0",
"@types/express": "^4.17.13",
"@types/jest": "^28.1.6",
"@types/lodash": "^4.14.186",
"@types/node": "^20.1.2",
"@types/promise.any": "^2.0.0",
"@types/prompts": "^2.0.14",
"@types/serverless": "^3.12.8",
"@typescript-eslint/eslint-plugin": "^5.40.1",
"@typescript-eslint/parser": "^5.40.0",
"cross-env": "^7.0.3",
"eslint": "^8.25.0",
"eslint-plugin-functional": "^5.0.8",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^27.1.3",
"express": "^4.18.1",
"hardhat": "^2.12.0",
"jest": "^28.1.3",
"pm2": "^5.2.2",
"prettier": "^2.7.1",
"prompts": "^2.4.2",
"rimraf": "^5.0.0",
"serverless": "^3.23.0",
"ts-jest": "^28.0.8",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
"@vercel/ncc": "^0.36.1",
"serverless": "^3.23.0"
}
}
1 change: 0 additions & 1 deletion packages/data-pusher/scripts/load-secrets-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const fs = require('fs');
const path = require('path');
const dotenv = require('dotenv');

// eslint-disable-next-line functional/immutable-data
module.exports = async ({ _options, _resolveConfigurationProperty }) => {
const secretsPath = path.resolve(__dirname, '..', 'config', 'secrets.env');
const envVars = fs.existsSync(secretsPath)
Expand Down
Loading

0 comments on commit 0caa6a1

Please sign in to comment.