|
| 1 | +name: AWF Config Drift Detection |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 8 * * 1' # Weekly on Mondays at 08:00 UTC |
| 6 | + pull_request: |
| 7 | + paths: |
| 8 | + - 'pkg/workflow/**' |
| 9 | + - 'actions/setup/**' |
| 10 | + - 'specs/awf-config-sources-spec.md' |
| 11 | + workflow_dispatch: {} |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + issues: write |
| 16 | + |
| 17 | +jobs: |
| 18 | + drift-detection: |
| 19 | + name: AWF Config Drift Detection |
| 20 | + runs-on: ubuntu-latest |
| 21 | + timeout-minutes: 15 |
| 22 | + permissions: |
| 23 | + contents: read |
| 24 | + issues: write |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout gh-aw |
| 28 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 29 | + with: |
| 30 | + fetch-depth: 1 |
| 31 | + |
| 32 | + - name: Fetch AWF canonical sources |
| 33 | + id: fetch-sources |
| 34 | + env: |
| 35 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 36 | + run: | |
| 37 | + echo "## AWF Config Drift Detection" >> "$GITHUB_STEP_SUMMARY" |
| 38 | + echo "" >> "$GITHUB_STEP_SUMMARY" |
| 39 | + echo "Fetching canonical sources from gh-aw-firewall..." >> "$GITHUB_STEP_SUMMARY" |
| 40 | +
|
| 41 | + mkdir -p /tmp/awf-drift |
| 42 | +
|
| 43 | + # Attempt to fetch published schema from gh-aw-firewall |
| 44 | + # Note: requires read access to github/gh-aw-firewall |
| 45 | + if gh api repos/github/gh-aw-firewall/contents/docs/awf-config.schema.json \ |
| 46 | + --jq '.content' 2>/dev/null | base64 -d > /tmp/awf-drift/published-schema.json; then |
| 47 | + echo "✅ Fetched docs/awf-config.schema.json" >> "$GITHUB_STEP_SUMMARY" |
| 48 | + else |
| 49 | + echo "⚠️ Could not fetch docs/awf-config.schema.json (repo may be private or inaccessible)" >> "$GITHUB_STEP_SUMMARY" |
| 50 | + echo '{}' > /tmp/awf-drift/published-schema.json |
| 51 | + fi |
| 52 | +
|
| 53 | + if gh api repos/github/gh-aw-firewall/contents/src/awf-config-schema.json \ |
| 54 | + --jq '.content' 2>/dev/null | base64 -d > /tmp/awf-drift/runtime-schema.json; then |
| 55 | + echo "✅ Fetched src/awf-config-schema.json" >> "$GITHUB_STEP_SUMMARY" |
| 56 | + else |
| 57 | + echo "⚠️ Could not fetch src/awf-config-schema.json" >> "$GITHUB_STEP_SUMMARY" |
| 58 | + echo '{}' > /tmp/awf-drift/runtime-schema.json |
| 59 | + fi |
| 60 | +
|
| 61 | + - name: Extract schema property inventory |
| 62 | + id: extract-inventory |
| 63 | + run: | |
| 64 | + # Extract all unique property keys from both schema files |
| 65 | + jq -r '[.. | objects | keys[]] | unique | sort[]' \ |
| 66 | + /tmp/awf-drift/published-schema.json \ |
| 67 | + /tmp/awf-drift/runtime-schema.json 2>/dev/null | sort -u \ |
| 68 | + > /tmp/awf-drift/schema-keys.txt || true |
| 69 | +
|
| 70 | + echo "Schema property count: $(wc -l < /tmp/awf-drift/schema-keys.txt)" >> "$GITHUB_STEP_SUMMARY" |
| 71 | + echo "" >> "$GITHUB_STEP_SUMMARY" |
| 72 | +
|
| 73 | + - name: Compare against gh-aw implementation |
| 74 | + id: compare |
| 75 | + run: | |
| 76 | + DRIFT_FOUND=false |
| 77 | + DRIFT_REPORT="" |
| 78 | +
|
| 79 | + # Extract property references from gh-aw source |
| 80 | + grep -rh \ |
| 81 | + 'apiProxy\|awf-config\|awf_config\|AWF_CONFIG\|AWF_AUTH\|anthropicAutoCache\|anthropicCacheTailTtl\|dockerHostPathPrefix' \ |
| 82 | + pkg/workflow/ actions/setup/ 2>/dev/null | sort -u \ |
| 83 | + > /tmp/awf-drift/ghaw-refs.txt || true |
| 84 | +
|
| 85 | + # Check each known drift-prone property category |
| 86 | + CATEGORIES=("apiProxy" "container" "network" "model" "auth") |
| 87 | + for cat in "${CATEGORIES[@]}"; do |
| 88 | + SCHEMA_COUNT=$(grep -c "\"${cat}" /tmp/awf-drift/schema-keys.txt 2>/dev/null || echo 0) |
| 89 | + GHAW_COUNT=$(grep -c "${cat}" /tmp/awf-drift/ghaw-refs.txt 2>/dev/null || echo 0) |
| 90 | +
|
| 91 | + if [ "$SCHEMA_COUNT" -gt 0 ] && [ "$GHAW_COUNT" -eq 0 ]; then |
| 92 | + DRIFT_FOUND=true |
| 93 | + DRIFT_REPORT="${DRIFT_REPORT}\n- ❌ **Missing in gh-aw**: \`${cat}.*\` (${SCHEMA_COUNT} schema properties, 0 gh-aw references)" |
| 94 | + fi |
| 95 | + done |
| 96 | +
|
| 97 | + if [ "$DRIFT_FOUND" = "true" ]; then |
| 98 | + echo "drift_found=true" >> "$GITHUB_OUTPUT" |
| 99 | + echo "### ❌ Drift Detected" >> "$GITHUB_STEP_SUMMARY" |
| 100 | + echo "" >> "$GITHUB_STEP_SUMMARY" |
| 101 | + echo -e "$DRIFT_REPORT" >> "$GITHUB_STEP_SUMMARY" |
| 102 | + echo "" >> "$GITHUB_STEP_SUMMARY" |
| 103 | + echo "**Corrective action required**: Open a PR to add coverage for missing properties per \`specs/awf-config-sources-spec.md\` Section 4.2." >> "$GITHUB_STEP_SUMMARY" |
| 104 | + else |
| 105 | + echo "drift_found=false" >> "$GITHUB_OUTPUT" |
| 106 | + echo "### ✅ No Drift Detected" >> "$GITHUB_STEP_SUMMARY" |
| 107 | + echo "" >> "$GITHUB_STEP_SUMMARY" |
| 108 | + echo "All checked AWF config property categories have corresponding gh-aw implementation references." >> "$GITHUB_STEP_SUMMARY" |
| 109 | + fi |
| 110 | +
|
| 111 | + - name: Create tracking issue on scheduled drift |
| 112 | + if: > |
| 113 | + steps.compare.outputs.drift_found == 'true' && |
| 114 | + github.event_name == 'schedule' |
| 115 | + env: |
| 116 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 117 | + run: | |
| 118 | + DATE=$(date -u +%Y-%m-%d) |
| 119 | + TITLE="AWF Config Drift Detected — ${DATE}" |
| 120 | +
|
| 121 | + # Check if an open drift issue already exists |
| 122 | + EXISTING=$(gh issue list \ |
| 123 | + --label awf-config-drift \ |
| 124 | + --state open \ |
| 125 | + --json number,title \ |
| 126 | + --jq '.[0].number' 2>/dev/null || echo "") |
| 127 | +
|
| 128 | + if [ -n "$EXISTING" ]; then |
| 129 | + echo "Adding comment to existing issue #${EXISTING}" |
| 130 | + gh issue comment "$EXISTING" \ |
| 131 | + --body "### Drift re-detected on ${DATE} |
| 132 | +
|
| 133 | +Scheduled drift detection found AWF config property categories with no coverage in gh-aw. See the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for the full drift report. |
| 134 | + |
| 135 | +**Action required**: Review and address per \`specs/awf-config-sources-spec.md\` Section 4.2 and 5.3." |
| 136 | + else |
| 137 | + echo "Creating new tracking issue" |
| 138 | + gh issue create \ |
| 139 | + --title "$TITLE" \ |
| 140 | + --label awf-config-drift \ |
| 141 | + --body "### AWF Config Drift Detected |
| 142 | + |
| 143 | +The scheduled AWF config drift detection workflow found property categories present in the canonical AWF config schemas (\`github/gh-aw-firewall\`) with no corresponding coverage in \`github/gh-aw\`. |
| 144 | + |
| 145 | +**Detection Date**: ${DATE} |
| 146 | +**Workflow Run**: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 147 | + |
| 148 | +### Required Actions |
| 149 | + |
| 150 | +1. Review the drift report in the workflow run summary. |
| 151 | +2. For each missing category, add coverage per \`specs/awf-config-sources-spec.md\` Section 4.2 (Step-by-Step Procedure). |
| 152 | +3. Open a corrective PR per CR-05 in \`specs/awf-config-sources-spec.md\`. |
| 153 | + |
| 154 | +### References |
| 155 | + |
| 156 | +- Spec: \`specs/awf-config-sources-spec.md\` |
| 157 | +- Procedure: Section 4.2 (Step-by-Step Procedure) |
| 158 | +- Safeguards: Section 5" |
| 159 | + fi |
| 160 | + |
| 161 | + - name: Fail on PR drift |
| 162 | + if: > |
| 163 | + steps.compare.outputs.drift_found == 'true' && |
| 164 | + github.event_name == 'pull_request' |
| 165 | + run: | |
| 166 | + echo "❌ AWF config drift detected. This PR touches AWF config handling but drift was found." |
| 167 | + echo "See the step summary for details and required corrective actions." |
| 168 | + exit 1 |
0 commit comments