|
| 1 | +# Production-grade CI for TruthBounty Smart Contracts |
| 2 | +# Optimized for open-source, protocol security, and fast feedback |
| 3 | + |
| 4 | +name: CI |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: [main] |
| 9 | + pull_request: |
| 10 | + branches: [main] |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: ci-${{ github.ref }} |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +jobs: |
| 17 | + lint: |
| 18 | + name: Lint |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: Checkout code |
| 22 | + uses: actions/checkout@v4 |
| 23 | + - name: Setup Node.js |
| 24 | + uses: actions/setup-node@v4 |
| 25 | + with: |
| 26 | + node-version: 20 |
| 27 | + - name: Cache node_modules |
| 28 | + uses: actions/cache@v4 |
| 29 | + with: |
| 30 | + path: node_modules |
| 31 | + key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }} |
| 32 | + restore-keys: | |
| 33 | + ${{ runner.os }}-node- |
| 34 | + - name: Install dependencies |
| 35 | + run: npm ci |
| 36 | + - name: Solidity Lint |
| 37 | + run: | |
| 38 | + if npm run lint:sol --if-present; then |
| 39 | + npm run lint:sol |
| 40 | + else |
| 41 | + echo "No Solidity linter configured. Skipping." |
| 42 | + fi |
| 43 | + - name: TypeScript Lint |
| 44 | + run: | |
| 45 | + if npm run lint --if-present; then |
| 46 | + npm run lint |
| 47 | + else |
| 48 | + echo "No TypeScript linter configured. Skipping." |
| 49 | + fi |
| 50 | +
|
| 51 | + test: |
| 52 | + name: Test |
| 53 | + runs-on: ubuntu-latest |
| 54 | + needs: lint |
| 55 | + steps: |
| 56 | + - name: Checkout code |
| 57 | + uses: actions/checkout@v4 |
| 58 | + - name: Setup Node.js |
| 59 | + uses: actions/setup-node@v4 |
| 60 | + with: |
| 61 | + node-version: 20 |
| 62 | + - name: Cache node_modules |
| 63 | + uses: actions/cache@v4 |
| 64 | + with: |
| 65 | + path: node_modules |
| 66 | + key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }} |
| 67 | + restore-keys: | |
| 68 | + ${{ runner.os }}-node- |
| 69 | + - name: Install dependencies |
| 70 | + run: npm ci |
| 71 | + - name: Install Foundry |
| 72 | + uses: foundry-rs/foundry-toolchain@v1 |
| 73 | + with: |
| 74 | + version: latest |
| 75 | + - name: Build contracts (forge build) |
| 76 | + run: forge build |
| 77 | + - name: Run Foundry tests (forge test) |
| 78 | + run: forge test --no-match-path test/invariant --no-match-path test/fuzz |
| 79 | + - name: Run Hardhat tests |
| 80 | + run: npx hardhat test |
| 81 | + |
| 82 | + fuzz-tests: |
| 83 | + name: Fuzz Tests |
| 84 | + runs-on: ubuntu-latest |
| 85 | + needs: test |
| 86 | + steps: |
| 87 | + - name: Checkout code |
| 88 | + uses: actions/checkout@v4 |
| 89 | + - name: Setup Node.js |
| 90 | + uses: actions/setup-node@v4 |
| 91 | + with: |
| 92 | + node-version: 20 |
| 93 | + - name: Cache node_modules |
| 94 | + uses: actions/cache@v4 |
| 95 | + with: |
| 96 | + path: node_modules |
| 97 | + key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }} |
| 98 | + restore-keys: | |
| 99 | + ${{ runner.os }}-node- |
| 100 | + - name: Install dependencies |
| 101 | + run: npm ci |
| 102 | + - name: Install Foundry |
| 103 | + uses: foundry-rs/foundry-toolchain@v1 |
| 104 | + with: |
| 105 | + version: latest |
| 106 | + - name: Run Foundry fuzz tests |
| 107 | + run: forge test --match-path test/fuzz |
| 108 | + |
| 109 | + invariant-tests: |
| 110 | + name: Invariant Tests |
| 111 | + runs-on: ubuntu-latest |
| 112 | + needs: test |
| 113 | + steps: |
| 114 | + - name: Checkout code |
| 115 | + uses: actions/checkout@v4 |
| 116 | + - name: Setup Node.js |
| 117 | + uses: actions/setup-node@v4 |
| 118 | + with: |
| 119 | + node-version: 20 |
| 120 | + - name: Cache node_modules |
| 121 | + uses: actions/cache@v4 |
| 122 | + with: |
| 123 | + path: node_modules |
| 124 | + key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }} |
| 125 | + restore-keys: | |
| 126 | + ${{ runner.os }}-node- |
| 127 | + - name: Install dependencies |
| 128 | + run: npm ci |
| 129 | + - name: Install Foundry |
| 130 | + uses: foundry-rs/foundry-toolchain@v1 |
| 131 | + with: |
| 132 | + version: latest |
| 133 | + - name: Run Foundry invariant tests |
| 134 | + run: forge test --match-path test/invariant |
| 135 | + |
| 136 | + gas-check: |
| 137 | + name: Gas Check |
| 138 | + runs-on: ubuntu-latest |
| 139 | + needs: test |
| 140 | + steps: |
| 141 | + - name: Checkout code |
| 142 | + uses: actions/checkout@v4 |
| 143 | + - name: Setup Node.js |
| 144 | + uses: actions/setup-node@v4 |
| 145 | + with: |
| 146 | + node-version: 20 |
| 147 | + - name: Cache node_modules |
| 148 | + uses: actions/cache@v4 |
| 149 | + with: |
| 150 | + path: node_modules |
| 151 | + key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }} |
| 152 | + restore-keys: | |
| 153 | + ${{ runner.os }}-node- |
| 154 | + - name: Install dependencies |
| 155 | + run: npm ci |
| 156 | + - name: Install Foundry |
| 157 | + uses: foundry-rs/foundry-toolchain@v1 |
| 158 | + with: |
| 159 | + version: latest |
| 160 | + - name: Check gas snapshots |
| 161 | + run: | |
| 162 | + if [ -f .gas-snapshots.json ]; then |
| 163 | + forge snapshot --check |
| 164 | + else |
| 165 | + echo "No gas snapshot file found. Skipping." |
| 166 | + fi |
0 commit comments