diff --git a/.github/workflows/adr-validate.yml b/.github/workflows/adr-validate.yml new file mode 100644 index 00000000..ccf09054 --- /dev/null +++ b/.github/workflows/adr-validate.yml @@ -0,0 +1,215 @@ +name: ADR Validation + +on: + pull_request: + paths: + - 'docs/adr/**' + push: + branches: [main] + paths: + - 'docs/adr/**' + schedule: + - cron: '0 0 * * 1' # Weekly on Monday at 00:00 UTC + +jobs: + validate-adrs: + name: Validate ADRs + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Full history for numbering validation + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + + - name: Install ADR validator + run: npm ci @adr/madr-cli@latest + + - name: Validate ADR structure with madr-cli + run: npx @adr/madr-cli validate docs/adr/ + + - name: Validate front-matter and index sync + run: | + #!/bin/bash + set -euo pipefail + + ADR_DIR="docs/adr" + INDEX_FILE="$ADR_DIR/README.md" + TEMPLATE_FILE="$ADR_DIR/template.md" + + echo "Checking template exists..." + if [[ ! -f "$TEMPLATE_FILE" ]]; then + echo "ERROR: Template file $TEMPLATE_FILE not found" + exit 1 + fi + + echo "Checking index exists..." + if [[ ! -f "$INDEX_FILE" ]]; then + echo "ERROR: Index file $INDEX_FILE not found" + exit 1 + fi + + # Find all ADR files (excluding template) + ADR_FILES=$(find "$ADR_DIR" -maxdepth 1 -name '*.md' ! -name 'template.md' ! -name 'README.md' | sort) + + if [[ -z "$ADR_FILES" ]]; then + echo "No ADR files found (except template and index) — skipping detailed validation" + exit 0 + fi + + echo "Found ADR files:" + echo "$ADR_FILES" + + # Check each ADR file + VALID_STATUSES=("Proposed" "Accepted" "Rejected" "Superseded" "Deprecated") + SEEN_IDS=() + ERRORS=0 + + while IFS= read -r file; do + echo "Validating $file..." + + # Check front-matter exists + if ! head -20 "$file" | grep -q '^---$'; then + echo "ERROR: $file missing front-matter (--- delimiter)" + ERRORS=$((ERRORS + 1)) + continue + fi + + # Extract front-matter + FM=$(sed -n '/^---$/,/^---$/p' "$file" | sed '1d;$d') + + # Check required fields + for field in "status" "date" "deciders"; do + if ! echo "$FM" | grep -q "^$field:"; then + echo "ERROR: $file missing required front-matter field: $field" + ERRORS=$((ERRORS + 1)) + fi + done + + # Validate status + STATUS=$(echo "$FM" | grep "^status:" | cut -d: -f2- | xargs) + if [[ -n "$STATUS" ]]; then + VALID=false + for s in "${VALID_STATUSES[@]}"; do + if [[ "$STATUS" == "$s" ]]; then + VALID=true + break + fi + done + if [[ "$VALID" == "false" ]]; then + echo "ERROR: $file invalid status '$STATUS' (must be one of: ${VALID_STATUSES[*]})" + ERRORS=$((ERRORS + 1)) + fi + fi + + # Validate date format (YYYY-MM-DD) + DATE=$(echo "$FM" | grep "^date:" | cut -d: -f2- | xargs) + if [[ -n "$DATE" ]] && ! [[ "$DATE" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then + echo "ERROR: $file invalid date format '$DATE' (must be YYYY-MM-DD)" + ERRORS=$((ERRORS + 1)) + fi + + # Extract ID from filename + BASENAME=$(basename "$file" .md) + if [[ "$BASENAME" =~ ^([0-9]{4})- ]]; then + ID="${BASH_REMATCH[1]}" + if [[ " ${SEEN_IDS[*]} " =~ " $ID " ]]; then + echo "ERROR: Duplicate ADR ID: $ID" + ERRORS=$((ERRORS + 1)) + fi + SEEN_IDS+=("$ID") + else + echo "ERROR: $file invalid filename format (must be NNNN-title.md)" + ERRORS=$((ERRORS + 1)) + fi + + done <<< "$ADR_FILES" + + # Check for gaps in numbering + if [[ ${#SEEN_IDS[@]} -gt 0 ]]; then + IFS=$'\n' SORTED_IDS=($(sort <<<"${SEEN_IDS[*]}")) + FIRST=$(printf "%d" "${SORTED_IDS[0]}") + LAST=$(printf "%d" "${SORTED_IDS[-1]}") + EXPECTED_COUNT=$((LAST - FIRST + 1)) + if [[ ${#SORTED_IDS[@]} -ne $EXPECTED_COUNT ]]; then + echo "WARNING: Gap in ADR numbering (found ${#SORTED_IDS[@]}, expected $EXPECTED_COUNT from $FIRST to $LAST)" + fi + fi + + # Validate index sync + echo "Checking index sync..." + INDEX_ROWS=$(grep '^| [0-9]' "$INDEX_FILE" | wc -l) + ADR_COUNT=$(echo "$ADR_FILES" | wc -l) + + if [[ "$INDEX_ROWS" -ne "$ADR_COUNT" ]]; then + echo "ERROR: Index row count ($INDEX_ROWS) != ADR file count ($ADR_COUNT)" + echo "Every ADR must have a row in docs/adr/README.md" + ERRORS=$((ERRORS + 1)) + fi + + # Check each ADR ID appears in index + for ID in "${SEEN_IDS[@]}"; do + if ! grep -q "| $ID |" "$INDEX_FILE"; then + echo "ERROR: ADR $ID not found in index ($INDEX_FILE)" + ERRORS=$((ERRORS + 1)) + fi + done + + if [[ $ERRORS -gt 0 ]]; then + echo "VALIDATION FAILED: $ERRORS error(s)" + exit 1 + fi + + echo "All ADR validations passed!" + + validate-template: + name: Validate Template + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Check template exists + run: | + if [[ ! -f "docs/adr/template.md" ]]; then + echo "ERROR: docs/adr/template.md not found" + exit 1 + fi + echo "Template found" + + - name: Validate template structure + run: | + # Check required sections + REQUIRED_SECTIONS=( + "Context and Problem Statement" + "Decision Drivers" + "Considered Options" + "Decision Outcome" + "Consequences" + "Implementation Notes" + "Validation" + "References" + "Changelog" + ) + + for section in "${REQUIRED_SECTIONS[@]}"; do + if ! grep -q "## $section" docs/adr/template.md; then + echo "ERROR: Template missing required section: $section" + exit 1 + fi + done + + # Check front-matter fields documented + for field in "status" "date" "deciders" "technical-story"; do + if ! grep -q "$field" docs/adr/template.md; then + echo "ERROR: Template missing documentation for front-matter field: $field" + exit 1 + fi + done + + echo "Template structure valid" \ No newline at end of file diff --git a/docs/adr/README.md b/docs/adr/README.md new file mode 100644 index 00000000..8e46908c --- /dev/null +++ b/docs/adr/README.md @@ -0,0 +1,80 @@ +# Architecture Decision Records (ADR) Index + +> This directory contains Architecture Decision Records for the SubTrackr project. +> Each ADR documents a significant architectural decision, its context, and consequences. + +## ADR Template + +* [Template](template.md) — Use this template for new ADRs. + +## ADR List + +| ID | Title | Status | Date | Authors | +|----|-------|--------|------|---------| +| 0001 | Example ADR — Replace with real title | Proposed | YYYY-MM-DD | Author Name | + +--- + +## How to Create a New ADR + +1. **Copy the template:** + ```bash + cp docs/adr/template.md docs/adr/0002-your-decision-title.md + ``` + +2. **Fill in the template:** + - Replace `` with the next sequential number (zero-padded to 4 digits) + - Fill in all sections + - Set initial status to `Proposed` + +3. **Update this index:** + Add a row to the table above with the new ADR. + +4. **Open a PR:** + - The CI workflow (`adr-validate.yml`) will validate the format + - Requires review from at least one architect + - On merge, status becomes `Accepted` + +--- + +## ADR Status Lifecycle + +```mermaid +stateDiagram-v2 + [*] --> Proposed + Proposed --> Accepted : Review approved + CI passes + Proposed --> Rejected : Review rejected + Accepted --> Superseded : New ADR replaces this + Accepted --> Deprecated : No longer relevant + Superseded --> [*] + Deprecated --> [*] + Rejected --> [*] +``` + +--- + +## Validation Rules (enforced by CI) + +Each ADR file must: + +1. **Follow the template structure** — all required sections present +2. **Have valid front-matter** — Status, Date, Deciders fields +3. **Use valid status values** — `Proposed`, `Accepted`, `Rejected`, `Superseded`, `Deprecated` +4. **Reference valid dates** — ISO 8601 format (YYYY-MM-DD) +5. **Have sequential numbering** — no gaps in the index +6. **Be linked from this index** — every ADR in `docs/adr/` must appear in the table + +--- + +## Tools + +* **Validate locally:** `npx @adr/madr-cli validate docs/adr/` +* **Generate index:** `npx @adr/madr-cli generate-index docs/adr/ > docs/adr/README.md` + +--- + +## Related Documentation + +* [Contributing Guide](../CONTRIBUTING.md) — includes ADR process +* [Architecture Overview](../architecture.md) — high-level system design +* [CI Workflow](../../.github/workflows/adr-validate.yml) — validation rules \ No newline at end of file diff --git a/docs/adr/template.md b/docs/adr/template.md new file mode 100644 index 00000000..60fc8746 --- /dev/null +++ b/docs/adr/template.md @@ -0,0 +1,139 @@ +# Architecture Decision Record Template + +> This template follows the [MADR](https://adr.github.io/madr/) (Markdown Architecture Decision Records) format. + +--- + +# ADR : + +> **Status:** `Proposed` | `Accepted` | `Rejected` | `Superseded` | `Deprecated` +> +> **Date:** YYYY-MM-DD +> +> **Deciders:** <names/roles> +> +> **Technical Story:** <link to issue/PR> + +--- + +## Context and Problem Statement + +<Describe the context and problem that motivates this decision. 2-3 sentences max.> + +--- + +## Decision Drivers + +* <Driver 1: e.g., regulatory requirement, performance target, team expertise> +* <Driver 2> +* <Driver 3> + +--- + +## Considered Options + +### Option 1: <Name> + +<Description of the option.> + +**Pros:** +* <Pro 1> +* <Pro 2> + +**Cons:** +* <Con 1> +* <Con 2> + +--- + +### Option 2: <Name> + +<Description of the option.> + +**Pros:** +* <Pro 1> +* <Pro 2> + +**Cons:** +* <Con 1> +* <Con 2> + +--- + +### Option 3: <Name> (if applicable) + +<Description of the option.> + +**Pros:** +* <Pro 1> +* <Pro 2> + +**Cons:** +* <Con 1> +* <Con 2> + +--- + +## Decision Outcome + +**Chosen option:** `<Option N: Name>` + +<Brief rationale for the choice. Reference the drivers.> + +--- + +## Consequences + +### Positive + +* <Positive consequence 1> +* <Positive consequence 2> + +### Negative + +* <Negative consequence 1> +* <Negative consequence 2> + +### Risks + +* <Risk 1 and mitigation> +* <Risk 2 and mitigation> + +--- + +## Implementation Notes + +* <Implementation detail 1> +* <Implementation detail 2> +* <Link to implementation PR> + +--- + +## Validation + +This ADR must be validated by: + +- [ ] Code review approval from at least one architect +- [ ] CI check passes (`adr-validate.yml`) +- [ ] Added to ADR index (`docs/adr/README.md`) + +--- + +## References + +* <Link to related ADR, issue, PR, or external resource> +* <Link to another ADR this supersedes (if applicable)> + +--- + +## Changelog + +| Date | Author | Change | +|------------|--------|---------------------------------| +| YYYY-MM-DD | <Name> | Initial version | + +--- + +> **Template version:** 1.0 +> **Location:** `docs/adr/template.md` +> **CI validation:** `.github/workflows/adr-validate.yml` \ No newline at end of file