|
| 1 | +# Architecture Overview |
| 2 | + |
| 3 | +## System Context |
| 4 | + |
| 5 | +This repository is the single source of truth for GitHub repository |
| 6 | +settings across all `gamaware` repositories. It acts as a control |
| 7 | +plane that reads a desired state from JSON configuration and |
| 8 | +reconciles it against the actual state via the GitHub API. |
| 9 | + |
| 10 | +```text |
| 11 | ++---------------------+ +------------------+ |
| 12 | +| config/ | | GitHub API | |
| 13 | +| baseline.json |------>| (repos, branches,| |
| 14 | +| overrides.json | | labels, security| |
| 15 | ++---------------------+ +------------------+ |
| 16 | + | ^ |
| 17 | + v | |
| 18 | ++---------------------+ | |
| 19 | +| scripts/ | | |
| 20 | +| sync-repo-settings |---------------+ |
| 21 | +| generate-report | |
| 22 | ++---------------------+ |
| 23 | + | |
| 24 | + v |
| 25 | ++---------------------+ |
| 26 | +| GitHub Issues | |
| 27 | +| Job Summaries | |
| 28 | +| Artifacts (90 days) | |
| 29 | ++---------------------+ |
| 30 | +``` |
| 31 | + |
| 32 | +## Components |
| 33 | + |
| 34 | +### Configuration Layer (`config/`) |
| 35 | + |
| 36 | +- `baseline.json` — settings enforced on every repository |
| 37 | +- `overrides.json` — per-repo exceptions (status checks, exclusions) |
| 38 | + |
| 39 | +The effective configuration for a repo is the baseline deep-merged |
| 40 | +with its overrides. If no override exists, the baseline is used |
| 41 | +as-is. |
| 42 | + |
| 43 | +### Sync Engine (`scripts/`) |
| 44 | + |
| 45 | +`sync-repo-settings.sh` is the core reconciliation loop: |
| 46 | + |
| 47 | +1. **Discovery** — `gh repo list` finds all non-archived repos |
| 48 | +2. **Comparison** — for each repo, current state is fetched via API |
| 49 | + and compared field-by-field against the effective config |
| 50 | +3. **Remediation** — in `--apply` mode, PATCH/PUT calls correct drift |
| 51 | +4. **Reporting** — a markdown report is generated with per-repo diffs |
| 52 | + |
| 53 | +The script handles 7 categories independently: |
| 54 | + |
| 55 | +| Category | API Endpoint | Method | |
| 56 | +| --- | --- | --- | |
| 57 | +| Repo settings | `repos/{owner}/{repo}` | PATCH | |
| 58 | +| Security | `repos/{owner}/{repo}` | PATCH | |
| 59 | +| Vulnerability alerts | `repos/{owner}/{repo}/vulnerability-alerts` | PUT | |
| 60 | +| Branch protection | `repos/{owner}/{repo}/branches/main/protection` | PUT | |
| 61 | +| Labels | `repos/{owner}/{repo}/labels` | POST | |
| 62 | +| Default branch | `repos/{owner}/{repo}` | PATCH | |
| 63 | +| Metadata | (advisory only) | — | |
| 64 | + |
| 65 | +### Composite Actions (`.github/actions/`) |
| 66 | + |
| 67 | +Reusable building blocks consumed by workflows: |
| 68 | + |
| 69 | +- `security-scan/` — Semgrep SAST + Trivy SCA with SARIF upload |
| 70 | +- `sync-settings/` — wraps the sync script with structured outputs |
| 71 | +- `update-pre-commit-composite/` — autoupdates hooks and creates PR |
| 72 | + |
| 73 | +### Workflows (`.github/workflows/`) |
| 74 | + |
| 75 | +| Workflow | Schedule | Purpose | |
| 76 | +| --- | --- | --- | |
| 77 | +| `sync-settings.yml` | Weekly Sunday 00:00 UTC | Settings enforcement | |
| 78 | +| `quality-checks.yml` | PR + push | Linting and validation | |
| 79 | +| `security.yml` | PR + push | SAST + SCA | |
| 80 | +| `update-pre-commit-hooks.yml` | Weekly Sunday 00:00 UTC | Hook version updates | |
| 81 | + |
| 82 | +### Reporting |
| 83 | + |
| 84 | +Drift is communicated through three channels: |
| 85 | + |
| 86 | +1. **GitHub Issues** — auto-created with `settings-drift` label when |
| 87 | + drift is found, auto-closed when all repos are compliant |
| 88 | +2. **Job Summaries** — visible in the Actions run page |
| 89 | +3. **Artifacts** — full markdown report stored for 90 days |
| 90 | + |
| 91 | +## Security Model |
| 92 | + |
| 93 | +- The `ORG_SETTINGS_PAT` secret provides API access with `repo` and |
| 94 | + `admin:org` scopes |
| 95 | +- Workflows use least-privilege `permissions` blocks |
| 96 | +- All third-party actions are pinned to SHA commits |
| 97 | +- Secret scanning and push protection are enforced on this repo too |
| 98 | + |
| 99 | +## Design Decisions |
| 100 | + |
| 101 | +Detailed rationale is documented in Architecture Decision Records: |
| 102 | + |
| 103 | +- [ADR 001: Settings Governance](adr/001-settings-governance.md) |
| 104 | +- [ADR 002: Sync Architecture](adr/002-sync-architecture.md) |
0 commit comments