name: Update README with ADR Index on: push: branches: - main paths: - 'decisions/**.md' - '.gitea/workflows/update-adr-readme.yaml' workflow_dispatch: jobs: update-readme: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 1 - name: Generate ADR table and update README run: | set -euo pipefail TABLE_HEADER="| # | Decision | Status | Date |" TABLE_SEPARATOR="|---|----------|--------|------|" TABLE_ROWS="" TOTAL=0 ACCEPTED=0 PROPOSED=0 SUPERSEDED=0 DEPRECATED=0 for file in decisions/[0-9][0-9][0-9][0-9]-*.md; do [ -f "$file" ] || continue # Extract ADR number from filename num=$(basename "$file" | grep -oP '^\d+') # Skip the template [ "$num" = "0000" ] && continue # Parse title from first heading line title=$(head -1 "$file" | sed 's/^#\s*//') # Parse status: "* Status: accepted" status=$(grep -m1 -iP '^\*\s*Status:\s*' "$file" \ | sed 's/^\*\s*Status:\s*//i' | xargs) # Parse date: "* Date: 2026-02-04" date=$(grep -m1 -iP '^\*\s*Date:\s*' "$file" \ | sed 's/^\*\s*Date:\s*//i' | xargs) # Status emoji case "$(echo "$status" | tr '[:upper:]' '[:lower:]')" in accepted) badge="✅" ; ACCEPTED=$((ACCEPTED+1)) ;; proposed) badge="📝" ; PROPOSED=$((PROPOSED+1)) ;; superseded*) badge="♻️" ; SUPERSEDED=$((SUPERSEDED+1)) ;; deprecated) badge="⛔" ; DEPRECATED=$((DEPRECATED+1)) ;; *) badge="❓" ;; esac TOTAL=$((TOTAL+1)) TABLE_ROWS="${TABLE_ROWS}| ${num} | [${title}](${file}) | ${badge} ${status} | ${date} |\n" done # Build the full table block ADR_TABLE=$(printf '%s\n%s\n%s' "$TABLE_HEADER" "$TABLE_SEPARATOR" "$(echo -e "$TABLE_ROWS")") # Build badge line (shields.io static badge) BADGE_LINE="![ADR Count](https://img.shields.io/badge/ADRs-${TOTAL}_total-blue?logo=bookstack) ![Accepted](https://img.shields.io/badge/accepted-${ACCEPTED}-brightgreen) ![Proposed](https://img.shields.io/badge/proposed-${PROPOSED}-yellow)" # Replace the ADR badges marker if grep -q '' README.md; then sed -i '//,//c\\n'"${BADGE_LINE}"'\n' README.md else echo "::warning::Missing marker in README.md" fi # Replace the ADR table marker if grep -q '' README.md; then # Use awk to replace content between markers (handles multi-line) awk -v table="$ADR_TABLE" ' // { print; print table; skip=1; next } // { skip=0 } !skip { print } ' README.md > README.md.tmp && mv README.md.tmp README.md else echo "::warning::Missing marker in README.md" fi # Update the "Last updated" date TODAY=$(date +%Y-%m-%d) sed -i "s|^\*Last updated:.*\*$|*Last updated: ${TODAY}*|" README.md - name: Check for changes id: changes run: | git diff --quiet README.md && echo "changed=false" >> "$GITHUB_OUTPUT" || echo "changed=true" >> "$GITHUB_OUTPUT" - name: Commit and push if: steps.changes.outputs.changed == 'true' run: | git config user.name "Gitea Actions" git config user.email "actions@daviestechlabs.io" git add README.md git commit -m "docs: auto-update ADR index in README [skip ci]" git push