|
| 1 | +name: Axe Rules Freshness Check |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Run twice a year: March 20 and September 20 at 09:00 UTC |
| 6 | + - cron: '0 9 20 3 *' |
| 7 | + - cron: '0 9 20 9 *' |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + check_date: |
| 11 | + description: 'Override check date (YYYY-MM-DD, defaults to today)' |
| 12 | + required: false |
| 13 | + type: string |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: read |
| 17 | + issues: write |
| 18 | + |
| 19 | +jobs: |
| 20 | + check-axe-rules-freshness: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - name: Checkout |
| 24 | + uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Setup Node |
| 27 | + uses: actions/setup-node@v4 |
| 28 | + with: |
| 29 | + node-version: '24' |
| 30 | + cache: 'npm' |
| 31 | + |
| 32 | + - name: Install dependencies |
| 33 | + run: npm ci |
| 34 | + |
| 35 | + - name: Check axe rules data freshness |
| 36 | + id: freshness |
| 37 | + shell: bash |
| 38 | + run: | |
| 39 | + CHECK_DATE="${{ inputs.check_date }}" |
| 40 | + if [[ -z "$CHECK_DATE" ]]; then |
| 41 | + CHECK_DATE=$(date -u +%Y-%m-%d) |
| 42 | + fi |
| 43 | + echo "check_date=$CHECK_DATE" >> "$GITHUB_OUTPUT" |
| 44 | +
|
| 45 | + node --input-type=module <<'EOF' |
| 46 | + import { getAxeImpactMetadata, isAxeImpactDataStale } from './src/data/axe-impact-loader.js'; |
| 47 | +
|
| 48 | + const checkDate = process.env.CHECK_DATE || new Date().toISOString().slice(0, 10); |
| 49 | + const metadata = getAxeImpactMetadata(); |
| 50 | + const stale = isAxeImpactDataStale(checkDate); |
| 51 | +
|
| 52 | + console.log('YAML axe_version: ', metadata.axe_version); |
| 53 | + console.log('YAML last_updated: ', metadata.last_updated); |
| 54 | + console.log('YAML next_review_date: ', metadata.next_review_date); |
| 55 | + console.log('Check date: ', checkDate); |
| 56 | + console.log('Is stale: ', stale); |
| 57 | +
|
| 58 | + if (stale) { |
| 59 | + console.log('::warning::Axe impact rules data in src/data/axe-impact-rules.yaml is past its review date. Please review and update the YAML data.'); |
| 60 | + process.exitCode = 1; |
| 61 | + } else { |
| 62 | + console.log('Axe impact rules data is current. No action needed.'); |
| 63 | + } |
| 64 | + EOF |
| 65 | + env: |
| 66 | + CHECK_DATE: ${{ steps.freshness.outputs.check_date }} |
| 67 | + |
| 68 | + - name: Check for new axe-core rules |
| 69 | + id: new-rules |
| 70 | + if: success() || failure() |
| 71 | + shell: bash |
| 72 | + run: | |
| 73 | + node src/cli/update-axe-rules.js --list-new > /tmp/new-rules-output.txt 2>&1 || true |
| 74 | + cat /tmp/new-rules-output.txt |
| 75 | +
|
| 76 | + if grep -q 'missing from axe-impact-rules.yaml' /tmp/new-rules-output.txt; then |
| 77 | + echo "has_new_rules=true" >> "$GITHUB_OUTPUT" |
| 78 | + # Extract the missing rule IDs |
| 79 | + MISSING=$(grep ' - ' /tmp/new-rules-output.txt | sed 's/ - //' | tr '\n' ', ' | sed 's/,$//') |
| 80 | + echo "missing_rules=${MISSING}" >> "$GITHUB_OUTPUT" |
| 81 | + else |
| 82 | + echo "has_new_rules=false" >> "$GITHUB_OUTPUT" |
| 83 | + fi |
| 84 | +
|
| 85 | + - name: Open issue if axe rules data is stale or has new rules |
| 86 | + if: | |
| 87 | + (failure() && steps.freshness.conclusion == 'failure') || |
| 88 | + steps.new-rules.outputs.has_new_rules == 'true' |
| 89 | + uses: actions/github-script@v7 |
| 90 | + with: |
| 91 | + script: | |
| 92 | + const { data: issues } = await github.rest.issues.listForRepo({ |
| 93 | + owner: context.repo.owner, |
| 94 | + repo: context.repo.repo, |
| 95 | + labels: 'axe-rules-review', |
| 96 | + state: 'open' |
| 97 | + }); |
| 98 | +
|
| 99 | + if (issues.length > 0) { |
| 100 | + console.log('An open axe rules review issue already exists:', issues[0].html_url); |
| 101 | + return; |
| 102 | + } |
| 103 | +
|
| 104 | + const hasNewRules = '${{ steps.new-rules.outputs.has_new_rules }}' === 'true'; |
| 105 | + const missingRules = '${{ steps.new-rules.outputs.missing_rules }}'; |
| 106 | + const metadata_section = hasNewRules |
| 107 | + ? `\n\n### New Rules Detected\n\nThe following axe-core rules do not yet have policy narrative entries in \`src/data/axe-impact-rules.yaml\`:\n\n\`\`\`\n${missingRules}\n\`\`\`\n\nAdd entries for these rules following the existing YAML structure in \`src/data/axe-impact-rules.yaml\`.` |
| 108 | + : ''; |
| 109 | +
|
| 110 | + const { data: issue } = await github.rest.issues.create({ |
| 111 | + owner: context.repo.owner, |
| 112 | + repo: context.repo.repo, |
| 113 | + title: 'Bi-annual review: Update axe-core rule impact data', |
| 114 | + labels: ['axe-rules-review'], |
| 115 | + body: `## Axe Rules Impact Data Review Required |
| 116 | +
|
| 117 | + The scheduled freshness check has detected that the axe-core rule impact data in [\`src/data/axe-impact-rules.yaml\`](../blob/main/src/data/axe-impact-rules.yaml) needs review. |
| 118 | +
|
| 119 | + ### Action Required |
| 120 | +
|
| 121 | + 1. Check the latest axe-core rule documentation: |
| 122 | + - [axe-core rules reference](https://dequeuniversity.com/rules/axe/html/4.11) |
| 123 | + - Compare with the installed version by running: \`node src/cli/update-axe-rules.js --check --list-new\` |
| 124 | +
|
| 125 | + 2. Update \`src/data/axe-impact-rules.yaml\`: |
| 126 | + - Update \`metadata.axe_version\` to match the installed axe-core version |
| 127 | + - Update \`metadata.last_updated\` to today's date |
| 128 | + - Update \`metadata.next_review_date\` to 6 months from today |
| 129 | + - Add or update \`technical_summary\` for any changed rules |
| 130 | + - Add \`policy_narrative\` entries for any new rules${metadata_section} |
| 131 | +
|
| 132 | + 3. Run \`npm test\` to verify no tests are broken. |
| 133 | +
|
| 134 | + See [\`src/data/axe-impact-rules.yaml\`](../blob/main/src/data/axe-impact-rules.yaml) for the current version and review dates. |
| 135 | + ` |
| 136 | + }); |
| 137 | +
|
| 138 | + console.log('Created issue:', issue.html_url); |
0 commit comments