hezarfen_backend
Clone
https://git.tahinli.com/Hezarfen/hezarfen_backend.git
0 watching0 forksRust8.3 MiB6d68754Ahmet Kaan Gümüş2 months ago566 commits
| 1 | #!/usr/bin/env bash |
| 2 | # The LOCAL full gate: the "special path" where this machine proves the suite |
| 3 | # instead of a GitHub runner. |
| 4 | # |
| 5 | # Why it exists: the same suite is 565s here and ~55min on a 4-core runner. |
| 6 | # When you have run it, commit the `Local-Gate:` trailer this script prints |
| 7 | # (`--amend` writes it for you) and the push carries proof: the workflow's |
| 8 | # "Decide test gate" step verifies the trailer against HEAD^{tree} and then |
| 9 | # skips the runner suite, so CI only packs and deploys. |
| 10 | # |
| 11 | # Default path (nothing here): push without a trailer and GitHub runs |
| 12 | # everything, suite included. Nothing is mandatory; this is the fast lane. |
| 13 | # |
| 14 | # What it runs, in order, each fatal on failure: |
| 15 | # 1. cargo clippy --all-targets -- -D warnings (same lint CI runs) |
| 16 | # 2. cargo nextest run --no-fail-fast (the whole suite, or |
| 17 | # the --scope filter; CI's env, and DATABASE_URL unset so the harness |
| 18 | # picks its own per-test databases) |
| 19 | # 3. cargo test --test doc_sync (README drift gate) |
| 20 | # |
| 21 | # On success it writes .git/local-gate/<tree-sha>.ok (inside .git, so it is |
| 22 | # never committed) holding the tree, the timestamp, the scope, the exact |
| 23 | # commands and the counts parsed from nextest's summary line. Re-running for |
| 24 | # the same tree is a no-op that just re-prints the trailer — the stamp IS the |
| 25 | # proof, so `--force` is the only way to pay for the suite twice. |
| 26 | # |
| 27 | # The trailer is printed only for a FULL run: a --scope run is quick |
| 28 | # iteration, not a claim about the suite. |
| 29 | # |
| 30 | # Prerequisites: cargo-nextest, and a reachable Postgres (the suite mints a |
| 31 | # control+school database pair per test). Both are checked first and reported |
| 32 | # with the exact command to fix them. |
| 33 | # |
| 34 | # Usage: |
| 35 | # scripts/gate-local.sh # full gate (reuses a stamp if it exists) |
| 36 | # scripts/gate-local.sh --force # full gate, even if already stamped |
| 37 | # scripts/gate-local.sh --scope e2e # quick iteration (no trailer) |
| 38 | # scripts/gate-local.sh --amend # full gate, then append the |
| 39 | # # trailer to the HEAD commit |
| 40 | |
| 41 | |
| 42 | here= |
| 43 | |
| 44 | |
| 45 | scope="" |
| 46 | amend=0 |
| 47 | force=0 |
| 48 | while [; do |
| 49 | case "" in |
| 50 | --scope) |
| 51 | [ || { ; ; } |
| 52 | scope= |
| 53 | |
| 54 | ;; |
| 55 | --amend) |
| 56 | amend=1 |
| 57 | |
| 58 | ;; |
| 59 | --force) |
| 60 | force=1 |
| 61 | |
| 62 | ;; |
| 63 | -h|--help) |
| 64 | | |
| 65 | |
| 66 | ;; |
| 67 | *) |
| 68 | |
| 69 | |
| 70 | ;; |
| 71 | esac |
| 72 | done |
| 73 | |
| 74 | # ── Record what this run is ───────────────────────────────────────────────── |
| 75 | tree= |
| 76 | head= |
| 77 | stamp_dir=/local-gate |
| 78 | |
| 79 | stamp=/.ok |
| 80 | log=/.log |
| 81 | |
| 82 | if [; then |
| 83 | scope_label= |
| 84 | else |
| 85 | scope_label=full |
| 86 | fi |
| 87 | |
| 88 | dirty=no |
| 89 | if [; then |
| 90 | dirty=yes |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | fi |
| 97 | |
| 98 | # The tail both paths share: print (and optionally amend in) the trailer. |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | # Already proven on this exact tree: the stamp IS the evidence, so re-running |
| 144 | # the suite would only burn ten minutes to arrive at the same line. |
| 145 | if [ && [ && [; then |
| 146 | scope_label= |
| 147 | passed= |
| 148 | seconds= |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | fi |
| 154 | |
| 155 | # ── Prerequisites ─────────────────────────────────────────────────────────── |
| 156 | # Each says what is missing and the exact command that fixes it: a mysterious |
| 157 | # failure 90 seconds in is worse than not starting. |
| 158 | || { |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | } |
| 165 | |
| 166 | # The compose stack's Postgres first (that is the repo's own container, and |
| 167 | # the one with max_connections=500 the parallel suite needs), then the CI |
| 168 | # sidecar's name in case it was started locally, then a plain reachable |
| 169 | # server on the harness's default address. |
| 170 | pg_container="" |
| 171 | pg_tool="" |
| 172 | for; do |
| 173 | for; do |
| 174 | if && |
| 175 | | ; then |
| 176 | pg_container= |
| 177 | pg_tool= |
| 178 | break |
| 179 | fi |
| 180 | done |
| 181 | done |
| 182 | |
| 183 | if [; then |
| 184 | || { |
| 185 | |
| 186 | |
| 187 | } |
| 188 | max_conn= |
| 189 | |
| 190 | if [ && [ ; then |
| 191 | |
| 192 | fi |
| 193 | elif (); then |
| 194 | |
| 195 | else |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | fi |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | # ── The three steps ───────────────────────────────────────────────────────── |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | # CI runs the same lint on its own runner before anything is packaged; a |
| 234 | # warning that only shows up there costs a full round trip. |
| 235 | |
| 236 | |
| 237 | |
| 238 | # CI's env, verbatim: no debug info in the test/dev profiles (the binaries |
| 239 | # blow past a runner's disk), no incremental artifacts, sqlx offline cache. |
| 240 | # DATABASE_URL is unset on purpose — the harness mints its own databases and a |
| 241 | # stray value would point every test at one schema. |
| 242 | if [; then |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | else |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | fi |
| 255 | |
| 256 | # The README's ## Endpoints table is generated; this is the drift gate. No |
| 257 | # UPDATE_DOCS: a run that regenerates what it should be checking is not a gate. |
| 258 | |
| 259 | |
| 260 | |
| 261 | # ── Parse nextest's summary line ──────────────────────────────────────────── |
| 262 | summary= |
| 263 | if [; then |
| 264 | |
| 265 | |
| 266 | fi |
| 267 | # Every parse is `|| true`: "0 failed" / "0 skipped" simply do not appear in |
| 268 | # the summary line, and a bare `grep -oE` with no match exits 1 — which, under |
| 269 | # `set -e` + pipefail, would abort a run that passed. |
| 270 | duration= |
| 271 | total= |
| 272 | passed= |
| 273 | skipped= |
| 274 | failed= |
| 275 | if [ || [; then |
| 276 | |
| 277 | |
| 278 | fi |
| 279 | seconds= |
| 280 | counts=" tests run, passed, failed, skipped" |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | if [; then |
| 287 | |
| 288 | |
| 289 | fi |
| 290 | |
| 291 | # ── The stamp ─────────────────────────────────────────────────────────────── |
| 292 | { |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | for; do |
| 302 | |
| 303 | done |
| 304 | } |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 |