|
| 1 | +############################################################################## |
| 2 | +# CodeQL Analysis — EsuStellar |
| 3 | +# |
| 4 | +# Runs GitHub's CodeQL static analysis on TypeScript and Rust code. |
| 5 | +# This workflow helps identify security vulnerabilities and code quality issues |
| 6 | +# before mainnet launch. |
| 7 | +# |
| 8 | +# Triggers: |
| 9 | +# - Push to main, develop branches |
| 10 | +# - Pull requests to main, develop branches |
| 11 | +# - Weekly schedule (Sundays at 00:00 UTC) |
| 12 | +# - Manual workflow dispatch |
| 13 | +############################################################################## |
| 14 | + |
| 15 | +name: CodeQL Analysis |
| 16 | + |
| 17 | +on: |
| 18 | + push: |
| 19 | + branches: [main, develop] |
| 20 | + pull_request: |
| 21 | + branches: [main, develop] |
| 22 | + schedule: |
| 23 | + - cron: '0 0 * * 0' # Weekly on Sunday at 00:00 UTC |
| 24 | + workflow_dispatch: |
| 25 | + |
| 26 | +# Cancel in-flight runs on the same PR to save runner minutes |
| 27 | +concurrency: |
| 28 | + group: codeql-${{ github.ref }} |
| 29 | + cancel-in-progress: true |
| 30 | + |
| 31 | +jobs: |
| 32 | + analyze: |
| 33 | + name: CodeQL Analysis |
| 34 | + runs-on: ubuntu-latest |
| 35 | + timeout-minutes: 90 |
| 36 | + permissions: |
| 37 | + actions: read |
| 38 | + contents: read |
| 39 | + security-events: write |
| 40 | +name: CodeQL SAST |
| 41 | + |
| 42 | +on: |
| 43 | + push: |
| 44 | + branches: [main] |
| 45 | + pull_request: |
| 46 | + branches: [main] |
| 47 | + schedule: |
| 48 | + - cron: "0 3 * * 1" |
| 49 | + |
| 50 | +jobs: |
| 51 | + analyze: |
| 52 | + name: Analyze |
| 53 | + runs-on: ubuntu-latest |
| 54 | + permissions: |
| 55 | + security-events: write |
| 56 | + actions: read |
| 57 | + contents: read |
| 58 | + |
| 59 | + strategy: |
| 60 | + fail-fast: false |
| 61 | + matrix: |
| 62 | + language: ['typescript', 'rust'] |
| 63 | + |
| 64 | + steps: |
| 65 | + - name: Checkout repository |
| 66 | + uses: actions/checkout@v4 |
| 67 | + |
| 68 | + # ── TypeScript Analysis ─────────────────────────────────────────────────── |
| 69 | + - name: Initialize CodeQL (TypeScript) |
| 70 | + if: matrix.language == 'typescript' |
| 71 | + uses: github/codeql-action/init@v3 |
| 72 | + with: |
| 73 | + languages: typescript |
| 74 | + queries: security-extended,security-and-quality |
| 75 | + config: | |
| 76 | + packs: |
| 77 | + - codeql/javascript-queries:* |
| 78 | + query-filters: |
| 79 | + - exclude: |
| 80 | + id: js/unused-local-variable |
| 81 | + - exclude: |
| 82 | + id: js/unused-import |
| 83 | +
|
| 84 | + - name: Setup Node.js for TypeScript |
| 85 | + if: matrix.language == 'typescript' |
| 86 | + uses: actions/setup-node@v4 |
| 87 | + with: |
| 88 | + node-version: '20' |
| 89 | + |
| 90 | + - name: Install dependencies (mobile) |
| 91 | + if: matrix.language == 'typescript' |
| 92 | + working-directory: mobile |
| 93 | + run: npm ci |
| 94 | + |
| 95 | + - name: Install dependencies (web) |
| 96 | + if: matrix.language == 'typescript' |
| 97 | + working-directory: apps/web |
| 98 | + run: npm ci |
| 99 | + |
| 100 | + - name: Install dependencies (sdk) |
| 101 | + if: matrix.language == 'typescript' |
| 102 | + working-directory: packages/sdk |
| 103 | + run: npm ci |
| 104 | + |
| 105 | + - name: Install dependencies (shared) |
| 106 | + if: matrix.language == 'typescript' |
| 107 | + working-directory: packages/shared |
| 108 | + run: npm ci |
| 109 | + |
| 110 | + # ── Rust Analysis ───────────────────────────────────────────────────────── |
| 111 | + - name: Initialize CodeQL (Rust) |
| 112 | + if: matrix.language == 'rust' |
| 113 | + uses: github/codeql-action/init@v3 |
| 114 | + with: |
| 115 | + languages: rust |
| 116 | + queries: security-extended,security-and-quality |
| 117 | + config: | |
| 118 | + packs: |
| 119 | + - codeql/rust-queries:* |
| 120 | +
|
| 121 | + - name: Setup Rust toolchain |
| 122 | + if: matrix.language == 'rust' |
| 123 | + uses: dtolnay/rust-toolchain@stable |
| 124 | + with: |
| 125 | + toolchain: stable |
| 126 | + |
| 127 | + - name: Cache Cargo registry |
| 128 | + if: matrix.language == 'rust' |
| 129 | + uses: actions/cache@v4 |
| 130 | + with: |
| 131 | + path: ~/.cargo/registry |
| 132 | + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} |
| 133 | + |
| 134 | + - name: Cache Cargo index |
| 135 | + if: matrix.language == 'rust' |
| 136 | + uses: actions/cache@v4 |
| 137 | + with: |
| 138 | + path: ~/.cargo/git |
| 139 | + key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} |
| 140 | + |
| 141 | + - name: Cache Cargo build |
| 142 | + if: matrix.language == 'rust' |
| 143 | + uses: actions/cache@v4 |
| 144 | + with: |
| 145 | + path: target |
| 146 | + key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} |
| 147 | + |
| 148 | + - name: Build Rust contracts |
| 149 | + if: matrix.language == 'rust' |
| 150 | + run: | |
| 151 | + cargo build --manifest-path contracts/registry/Cargo.toml |
| 152 | + cargo build --manifest-path contracts/savings/Cargo.toml |
| 153 | +
|
| 154 | + - name: Run cargo clippy (Rust) |
| 155 | + if: matrix.language == 'rust' |
| 156 | + run: | |
| 157 | + cargo clippy --all-targets --manifest-path contracts/registry/Cargo.toml -- -D warnings |
| 158 | + cargo clippy --all-targets --manifest-path contracts/savings/Cargo.toml -- -D warnings |
| 159 | +
|
| 160 | + # ── Perform Analysis ─────────────────────────────────────────────────────── |
| 161 | + - name: Perform CodeQL Analysis |
| 162 | + uses: github/codeql-action/analyze@v3 |
| 163 | + with: |
| 164 | + category: "/language:${{matrix.language}}" |
| 165 | + upload: true |
| 166 | + wait-for-processing: true |
| 167 | + language: [javascript-typescript] |
| 168 | + |
| 169 | + steps: |
| 170 | + - name: Checkout |
| 171 | + uses: actions/checkout@v4 |
| 172 | + |
| 173 | + - name: Initialize CodeQL |
| 174 | + uses: github/codeql-action/init@v3 |
| 175 | + with: |
| 176 | + languages: ${{ matrix.language }} |
| 177 | + queries: security-and-quality |
| 178 | + |
| 179 | + - name: Autobuild |
| 180 | + uses: github/codeql-action/autobuild@v3 |
| 181 | + |
| 182 | + - name: Perform CodeQL Analysis |
| 183 | + uses: github/codeql-action/analyze@v3 |
| 184 | + with: |
| 185 | + category: "/language:${{ matrix.language }}" |
0 commit comments