|
| 1 | +name: Contracts |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths: |
| 8 | + - '**' |
| 9 | + - '.github/workflows/contracts.yaml' |
| 10 | + pull_request: |
| 11 | + types: |
| 12 | + - opened |
| 13 | + - reopened |
| 14 | + - synchronize |
| 15 | + - ready_for_review |
| 16 | + paths: |
| 17 | + - '**' |
| 18 | + - '.github/workflows/contracts.yaml' |
| 19 | + |
| 20 | +defaults: |
| 21 | + run: |
| 22 | + working-directory: '.' |
| 23 | + |
| 24 | +jobs: |
| 25 | + foundry: |
| 26 | + if: github.event.pull_request.draft == false |
| 27 | + runs-on: ubuntu-latest |
| 28 | + permissions: {} |
| 29 | + |
| 30 | + steps: |
| 31 | + - name: Checkout sources |
| 32 | + uses: actions/checkout@v4 |
| 33 | + with: |
| 34 | + submodules: recursive |
| 35 | + persist-credentials: false |
| 36 | + |
| 37 | + - name: Install Foundry |
| 38 | + uses: foundry-rs/foundry-toolchain@82dee4ba654bd2146511f85f0d013af94670c4de # v1.4.0 |
| 39 | + with: |
| 40 | + version: nightly |
| 41 | + |
| 42 | + - name: Setup LCOV |
| 43 | + uses: hrishikesh-kadam/setup-lcov@6c1aa0cc9e1c02f9f58f01ac599f1064ccc83470 # v1 |
| 44 | + |
| 45 | + - name: Install Node.js 18 |
| 46 | + uses: actions/setup-node@v4 |
| 47 | + with: |
| 48 | + node-version: '18' |
| 49 | + |
| 50 | + - name: Get yarn cache directory path |
| 51 | + id: yarn-cache-dir-path |
| 52 | + run: echo "::set-output name=dir::$(yarn cache dir)" |
| 53 | + |
| 54 | + - name: Cache yarn dependencies |
| 55 | + uses: actions/cache@v4 |
| 56 | + id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) |
| 57 | + with: |
| 58 | + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} |
| 59 | + key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} |
| 60 | + restore-keys: | |
| 61 | + ${{ runner.os }}-yarn- |
| 62 | +
|
| 63 | + - name: Cache node_modules |
| 64 | + id: npm_cache |
| 65 | + uses: actions/cache@v4 |
| 66 | + with: |
| 67 | + path: node_modules |
| 68 | + key: node_modules-${{ hashFiles('yarn.lock') }} |
| 69 | + |
| 70 | + - name: yarn install |
| 71 | + # if: steps.npm_cache.outputs.cache-hit != 'true' |
| 72 | + run: yarn install |
| 73 | + |
| 74 | + - name: Compile with foundry |
| 75 | + run: forge build --evm-version cancun |
| 76 | + |
| 77 | + - name: Run foundry tests |
| 78 | + run: forge test --evm-version cancun -vvv |
| 79 | + |
| 80 | + - name: Run foundry coverage |
| 81 | + run : forge coverage --evm-version cancun --report lcov |
| 82 | + |
| 83 | + - name : Prune coverage |
| 84 | + run : lcov --rc branch_coverage=1 --remove ./lcov.info -o ./lcov.info.pruned 'src/mocks/*' 'test/*' 'script/*' 'node_modules/*' 'lib/*' --ignore-errors unused,unused |
| 85 | + |
| 86 | + - name: Upload coverage reports to Codecov |
| 87 | + uses: codecov/codecov-action@ad3126e916f78f00edff4ed0317cf185271ccc2d # v5.4.2 |
| 88 | + env: |
| 89 | + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
| 90 | + with: |
| 91 | + files: lcov.info.pruned |
| 92 | + flags: contracts |
| 93 | + |
| 94 | + slither: |
| 95 | + if: github.event.pull_request.draft == false |
| 96 | + needs: foundry |
| 97 | + runs-on: ubuntu-latest |
| 98 | + permissions: |
| 99 | + statuses: write |
| 100 | + security-events: write |
| 101 | + |
| 102 | + steps: |
| 103 | + - uses: actions/checkout@v4 |
| 104 | + with: |
| 105 | + submodules: recursive |
| 106 | + persist-credentials: false |
| 107 | + |
| 108 | + - uses: actions/setup-node@v4 |
| 109 | + with: |
| 110 | + node-version: '18' |
| 111 | + |
| 112 | + - run: yarn install --frozen-lockfile |
| 113 | + |
| 114 | + - uses: foundry-rs/foundry-toolchain@82dee4ba654bd2146511f85f0d013af94670c4de # v1.4.0 |
| 115 | + with: |
| 116 | + version: nightly |
| 117 | + |
| 118 | + - name: Build contracts |
| 119 | + run: forge build --build-info --out out --evm-version cancun |
| 120 | + |
| 121 | + - uses: actions/setup-python@v5 |
| 122 | + with: |
| 123 | + python-version: '3.11' |
| 124 | + |
| 125 | + - run: | |
| 126 | + python -m pip install --upgrade pip |
| 127 | + pip install slither-analyzer==0.11.3 |
| 128 | +
|
| 129 | + - name: Run Slither (High severity gate) |
| 130 | + run: | |
| 131 | + slither . \ |
| 132 | + --filter-paths "src/test/*|src/mocks/*|scripts/*|node_modules" \ |
| 133 | + --foundry-out-directory out \ |
| 134 | + --exclude-dependencies \ |
| 135 | + --exclude-medium \ |
| 136 | + --exclude-low \ |
| 137 | + --exclude-informational \ |
| 138 | + --fail-high \ |
| 139 | + --json slither-report.json \ |
| 140 | + --markdown-root slither-report.md |
| 141 | +
|
| 142 | + - uses: actions/upload-artifact@v4 |
| 143 | + with: |
| 144 | + name: slither-static-analysis |
| 145 | + path: | |
| 146 | + slither-report.json |
| 147 | + slither-report.md |
0 commit comments