Jaypore CI

> Jaypore CI: Minimal, Offline, Local CI system.
Log | Files | Refs | README | LICENSE

run.sh (3160B)


      1 #!/usr/bin/env bash
      2 set -euo pipefail
      3 
      4 # ── Navigate to the project directory ────────────────────────────────────────
      5 cd "$JCI_REPO_ROOT/00-golang-lint-build-test"
      6 echo "==> Working directory: $(pwd)"
      7 echo "==> Commit: ${JCI_COMMIT:-unknown}"
      8 echo
      9 
     10 # ── Initialise Go module if needed ───────────────────────────────────────────
     11 if [ ! -f go.mod ]; then
     12     echo "==> No go.mod found – initialising module"
     13     go mod init example.com/server
     14 fi
     15 
     16 # ── Lint (go vet) ────────────────────────────────────────────────────────────
     17 echo "==> Running go vet ./..."
     18 go vet ./... 2>&1 | tee "$JCI_OUTPUT_DIR/vet-report.txt"
     19 echo "    vet report saved to \$JCI_OUTPUT_DIR/vet-report.txt"
     20 echo
     21 
     22 # ── Format check ─────────────────────────────────────────────────────────────
     23 echo "==> Checking formatting with gofmt"
     24 unformatted=$(gofmt -l .)
     25 if [ -n "$unformatted" ]; then
     26     echo "    ERROR: the following files need gofmt:"
     27     echo "$unformatted"
     28     exit 1
     29 fi
     30 echo "    all files formatted correctly"
     31 echo
     32 
     33 # ── Build ────────────────────────────────────────────────────────────────────
     34 echo "==> Building binary"
     35 go build -o "$JCI_OUTPUT_DIR/server" .
     36 echo "    binary saved to \$JCI_OUTPUT_DIR/server"
     37 echo
     38 
     39 # ── Test ─────────────────────────────────────────────────────────────────────
     40 echo "==> Running tests"
     41 go test -v -cover ./... 2>&1 | tee "$JCI_OUTPUT_DIR/test-results.txt"
     42 echo "    test results saved to \$JCI_OUTPUT_DIR/test-results.txt"
     43 echo
     44 
     45 # ── Publish (optional) ───────────────────────────────────────────────────────
     46 if [ -n "${PUBLISH_DIR:-}" ]; then
     47     echo "==> Publishing binary to $PUBLISH_DIR"
     48     mkdir -p "$PUBLISH_DIR"
     49     cp "$JCI_OUTPUT_DIR/server" "$PUBLISH_DIR/server"
     50     echo "    published successfully"
     51 else
     52     echo "==> PUBLISH_DIR not set – skipping publish step"
     53 fi
     54 echo
     55 
     56 # ── Summary ──────────────────────────────────────────────────────────────────
     57 echo "========================================"
     58 echo "  Pipeline complete"
     59 echo "  Commit  : ${JCI_COMMIT:-unknown}"
     60 echo "  Binary  : $JCI_OUTPUT_DIR/server"
     61 echo "  Vet     : $JCI_OUTPUT_DIR/vet-report.txt"
     62 echo "  Tests   : $JCI_OUTPUT_DIR/test-results.txt"
     63 echo "========================================"