badger/.github/workflows/hardhat.js.yml
2023-03-04 23:16:24 -06:00

145 lines
4.4 KiB
YAML

name: Smart contracts
on:
pull_request:
branches:
- "**"
defaults:
run:
working-directory: contracts/
jobs:
slither:
name: 🐍 Slither
runs-on: ubuntu-latest
permissions: write-all
env:
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
POLYGON_ALCHEMY_KEY: ${{ secrets.POLYGON_ALCHEMY_KEY }}
ETH_ALCHEMY_KEY: ${{ secrets.ETH_ALCHEMY_KEY }}
steps:
- name: 🛑 Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.11.0
- name: ⬇️ Checkout repo
uses: actions/checkout@v3
- name: ⎔ Setup node ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: 🐢 Cache node modules
id: cache-npm
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
name: 📚 List the state of node modules
continue-on-error: true
run: npm list
- name: 🐍 Run Slither
uses: crytic/slither-action@v0.3.0
id: slither
with:
node-version: 16
sarif: results.sarif
fail-on: none
target: "contracts/"
slither-args: --checklist --markdown-root ${{ github.server_url }}/${{ github.repository }}/blob/${{ github.sha }}/
- name: 🗣️ Create/update checklist as PR comment
uses: actions/github-script@v6
if: github.event_name == 'pull_request'
with:
script: |
const script = require('.github/scripts/comment')
const header = '# Slither report'
const body = `${{ steps.slither.outputs.stdout }}`
await script({ github, context, header, body })
- name: ☁️ Upload SARIF file
uses: github/codeql-action/upload-sarif@v2
if: always()
with:
sarif_file: ${{ steps.slither.outputs.sarif }}
test:
name: ✅ Test
runs-on: ubuntu-latest
env:
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
POLYGON_ALCHEMY_KEY: ${{ secrets.POLYGON_ALCHEMY_KEY }}
ETH_ALCHEMY_KEY: ${{ secrets.ETH_ALCHEMY_KEY }}
steps:
- name: 🛑 Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.11.0
- name: ⬇️ Checkout repo
uses: actions/checkout@v3
- name: ⎔ Setup node ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: 🐢 Cache node modules
id: cache-npm
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
name: 📚 List the state of node modules
continue-on-error: true
run: npm list
- name: 📥 Download deps
run: npm install
- name: 🤔 Run smart contract tests
run: MINING=true npx hardhat test
- name: 🏗️ Save build
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "fix: gas report"
audit:
name: 👁️ Audit
runs-on: ubuntu-latest
steps:
- name: 🛑 Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.11.0
- name: ⬇️ Checkout repo
uses: actions/checkout@v3
- name: 📥 Download deps
run: cd build && git clone https://github.com/byterocket/c4udit && cd c4udit && go build .
- name: 😡 Run contract auditor
run: cd build && ./c4udit/c4udit -s ../contracts/
- name: 🏗️ Save build
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "fix: contract audit"