|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + |
| 12 | +jobs: |
| 13 | + lint: |
| 14 | + name: Lint |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + - uses: actions/setup-go@v5 |
| 19 | + with: |
| 20 | + go-version-file: go.mod |
| 21 | + - uses: golangci/golangci-lint-action@v6 |
| 22 | + with: |
| 23 | + version: v2.1.0 |
| 24 | + args: --timeout=5m |
| 25 | + |
| 26 | + reconcile-guard: |
| 27 | + name: Reconcile Guard |
| 28 | + runs-on: ubuntu-latest |
| 29 | + steps: |
| 30 | + - uses: actions/checkout@v4 |
| 31 | + - name: Check for bare r.Update/r.Create on managed resources |
| 32 | + run: | |
| 33 | + # Find bare r.Update() or r.Create() calls that are NOT on the CR itself |
| 34 | + # and do NOT have a reconcile-guard:allow comment |
| 35 | + if grep -rn 'r\.Update\|r\.Create' internal/controller/ \ |
| 36 | + | grep -v 'reconcile-guard:allow' \ |
| 37 | + | grep -v '_test\.go' \ |
| 38 | + | grep -v 'r\.Status()' \ |
| 39 | + | grep -v 'r\.Recorder' \ |
| 40 | + | grep -v 'controllerutil\.CreateOrUpdate' \ |
| 41 | + | grep -v 'ensureDatabaseSecret'; then |
| 42 | + echo "ERROR: Found bare r.Update()/r.Create() calls on managed resources." |
| 43 | + echo "Use controllerutil.CreateOrUpdate instead, or add '// reconcile-guard:allow' comment." |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | + echo "Reconcile guard check passed." |
| 47 | +
|
| 48 | + test: |
| 49 | + name: Test |
| 50 | + runs-on: ubuntu-latest |
| 51 | + steps: |
| 52 | + - uses: actions/checkout@v4 |
| 53 | + - uses: actions/setup-go@v5 |
| 54 | + with: |
| 55 | + go-version-file: go.mod |
| 56 | + - name: Run tests |
| 57 | + run: make test |
| 58 | + |
| 59 | + security-scan: |
| 60 | + name: Security Scan |
| 61 | + runs-on: ubuntu-latest |
| 62 | + steps: |
| 63 | + - uses: actions/checkout@v4 |
| 64 | + - uses: actions/setup-go@v5 |
| 65 | + with: |
| 66 | + go-version-file: go.mod |
| 67 | + - name: Run gosec |
| 68 | + uses: securego/gosec@master |
| 69 | + with: |
| 70 | + args: ./... |
| 71 | + - name: Run Trivy |
| 72 | + uses: aquasecurity/trivy-action@master |
| 73 | + with: |
| 74 | + scan-type: fs |
| 75 | + severity: CRITICAL,HIGH |
| 76 | + |
| 77 | + build: |
| 78 | + name: Build |
| 79 | + runs-on: ubuntu-latest |
| 80 | + needs: [lint, test] |
| 81 | + steps: |
| 82 | + - uses: actions/checkout@v4 |
| 83 | + - uses: actions/setup-go@v5 |
| 84 | + with: |
| 85 | + go-version-file: go.mod |
| 86 | + - name: Build binary |
| 87 | + run: make build |
| 88 | + - name: Build Docker image |
| 89 | + run: make docker-build IMG=ghcr.io/paperclipai/k8s-operator:ci-${{ github.sha }} |
0 commit comments