Skip to content

Commit

Permalink
Merge pull request #686 from safe-global/add-precommit
Browse files Browse the repository at this point in the history
Add pre-commit hook for linting and formatting
  • Loading branch information
mmv08 authored Oct 20, 2023
2 parents 810fad9 + f839437 commit b344bd8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 22 deletions.
41 changes: 29 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,49 @@
name: safe-contracts
on: [push, pull_request]
env:
NODE_VERSION: 18.17.1

jobs:
tests:
lint-solidity:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 18.17.1
node-version: ${{ env.NODE_VERSION }}
cache: "npm"
- run: npm ci
- run: npm run build
- run: SAFE_CONTRACT_UNDER_TEST=SafeL2 npm run coverage
- name: Coveralls
uses: coverallsapp/github-action@master
- run: npm run lint:sol:prettier
- run: npm run lint:sol

lint-typescript:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
lint:
node-version: ${{ env.NODE_VERSION }}
cache: "npm"
- run: npm ci
- run: npm run lint:ts:prettier
- run: npm run lint:ts

tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 18.17.1
node-version: ${{ env.NODE_VERSION }}
cache: "npm"
- run: npm ci
- run: npm run lint:sol && npm run lint:ts && npm run lint:sol:prettier
- run: npm run build
- run: SAFE_CONTRACT_UNDER_TEST=SafeL2 npm run coverage
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

tests-other:
runs-on: ubuntu-latest
strategy:
Expand All @@ -39,7 +56,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 18.17.1
node-version: ${{ env.NODE_VERSION }}
cache: "npm"
- run: npm ci
- run: npm run build
Expand All @@ -64,6 +81,6 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 18.17.1
node-version: ${{ env.NODE_VERSION }}
cache: "npm"
- run: (npm ci && npm run build && npx hardhat codesize --contractname Safe && npm run benchmark) || echo "Benchmark failed"
20 changes: 10 additions & 10 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

# Redirect output to stderr.
exec 1>&2

# prevent it.only or describe.only commited
npm run lint:sol:prettier
npm run lint:ts:prettier
npm run lint:sol
npm run lint:ts

# Prevent `it.only` or `describe.only` tests commited
if [ "$allowonlytests" != "true" ] &&
test $(git diff --cached | grep -E "\b(it|describe).only\(" | wc -l) != 0
then
cat <<\EOF
Error: Attempt to add it.only or describe.only - which may disable all other tests
If you know what you are doing you can disable this check using:
git config hooks.allowonlytests true
EOF
exit 1
fi

exit 0
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"lint:sol": "solhint 'contracts/**/*.sol'",
"lint:sol:prettier": "prettier 'contracts/**/*.sol' --list-different",
"lint:ts": "eslint 'src/**/*.ts' 'test/**/*.ts' --fix",
"lint:ts:prettier": "prettier 'src/**/*.ts' 'test/**/*.ts' --list-different",
"fmt:sol": "prettier 'contracts/**/*.sol' -w",
"fmt:ts": "prettier 'src/**/*.ts' 'test/**/*.ts' -w",
"prepack": "npm run build",
Expand Down

0 comments on commit b344bd8

Please sign in to comment.