Meta Agent #1228
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| name: Meta Agent | |
| on: | |
| workflow_dispatch: | |
| pull_request: | |
| branches: [develop] | |
| paths: | |
| - "**/*.md" | |
| - ".github/labels.yml" | |
| - ".github/labeler.yml" | |
| - ".github/issue-types.yml" | |
| - ".github/agents/**" | |
| push: | |
| branches: [develop] | |
| paths: | |
| - "**/*.md" | |
| - ".github/labels.yml" | |
| - ".github/labeler.yml" | |
| - ".github/issue-types.yml" | |
| - ".github/agents/**" | |
| schedule: | |
| - cron: "0 3 * * 1" # weekly metrics roll-up (Mon 03:00 UTC) | |
| concurrency: | |
| group: "meta-${{ github.ref }}" | |
| cancel-in-progress: true | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| front-matter-validate: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v7 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "22.22.1" | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Validate frontmatter freshness | |
| run: | | |
| if [ "${GITHUB_EVENT_NAME}" = "pull_request" ]; then | |
| BASE_REF="${{ github.event.pull_request.base.sha }}" | |
| HEAD_REF="${{ github.event.pull_request.head.sha }}" | |
| elif [ "${GITHUB_EVENT_NAME}" = "push" ]; then | |
| BASE_REF="${{ github.event.before }}" | |
| HEAD_REF="${{ github.sha }}" | |
| else | |
| BASE_REF="HEAD~1" | |
| HEAD_REF="${{ github.sha }}" | |
| fi | |
| npm run validate:frontmatter:changed -- --base "$BASE_REF" --head "$HEAD_REF" | |
| lint-and-links: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v7 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "22.22.1" | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Lint changed Markdown | |
| run: | | |
| set -euo pipefail | |
| if [ "${GITHUB_EVENT_NAME}" = "pull_request" ]; then | |
| BASE_SHA="${{ github.event.pull_request.base.sha }}" | |
| HEAD_SHA="${{ github.event.pull_request.head.sha }}" | |
| elif [ "${GITHUB_EVENT_NAME}" = "push" ]; then | |
| BASE_SHA="${{ github.event.before }}" | |
| HEAD_SHA="${{ github.sha }}" | |
| else | |
| echo "Skipping markdown lint for event ${GITHUB_EVENT_NAME}" | |
| exit 0 | |
| fi | |
| # Get changed markdown files, excluding files with deferred formatting | |
| FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" -- '*.md' '*.mdx' | \ | |
| sed '/^AWESOME_GITHUB_MAPPING_STRATEGY\.md$/d' | \ | |
| sed '/^docs\/MIGRATION\.md$/d' | \ | |
| sed '/^\.github\/reports\//d' | \ | |
| tr '\n' ' ') | |
| if [ -z "$FILES" ]; then | |
| echo "No Markdown files to lint (all changed files are in ignore list)." | |
| exit 0 | |
| fi | |
| npx markdownlint-cli2 $FILES | |
| - name: Collect Link Targets | |
| id: link_targets | |
| run: | | |
| set -euo pipefail | |
| if [ "${GITHUB_EVENT_NAME}" = "pull_request" ]; then | |
| BASE_SHA="${{ github.event.pull_request.base.sha }}" | |
| HEAD_SHA="${{ github.event.pull_request.head.sha }}" | |
| elif [ "${GITHUB_EVENT_NAME}" = "push" ]; then | |
| BASE_SHA="${{ github.event.before }}" | |
| HEAD_SHA="${{ github.sha }}" | |
| else | |
| echo "files=" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| CHANGED_FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" -- '*.md' '*.mdx' | \ | |
| grep -v '^\.github/instructions/\.archive/' | \ | |
| grep -v '^\.github/reports/') | |
| if [ -z "$CHANGED_FILES" ]; then | |
| echo "files=" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| LINK_FILES="" | |
| while IFS= read -r file; do | |
| [ -z "$file" ] && continue | |
| if grep -Eq 'https?://|www\.|mailto:|^\[[^]]+\]:\s*https?://' "$file"; then | |
| LINK_FILES="${LINK_FILES}${file} " | |
| fi | |
| done <<EOF | |
| $CHANGED_FILES | |
| EOF | |
| echo "files=${LINK_FILES}" >> "$GITHUB_OUTPUT" | |
| - name: Check Links | |
| if: steps.link_targets.outputs.files != '' | |
| uses: lycheeverse/lychee-action@v2 | |
| with: | |
| args: --no-progress --verbose ${{ steps.link_targets.outputs.files }} | |
| apply-meta: | |
| if: ${{ github.event_name != 'pull_request' }} | |
| needs: [front-matter-validate, lint-and-links] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "22.22.1" | |
| - name: Run Meta Agent | |
| env: | |
| META_SKIP_README: "true" | |
| run: | | |
| node scripts/agents/meta.agent.js | |
| - name: Commit changes (content-only) | |
| run: | | |
| git config user.name "lightspeed-bot" | |
| git config user.email "ops@lightspeedwp.agency" | |
| git add -A | |
| if ! git diff --cached --quiet; then | |
| git commit -m "chore(meta): apply frontmatter/badges/references/footer [skip ci]" | |
| git push | |
| fi | |
| metrics-update: | |
| needs: [apply-meta] | |
| if: ${{ (success() || failure()) && github.event_name != 'pull_request' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v7 | |
| with: | |
| ref: ${{ github.ref }} | |
| fetch-depth: 2 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "22.22.1" | |
| - name: Fetch latest changes | |
| run: | | |
| git checkout ${{ github.ref_name }} | |
| git pull origin ${{ github.ref_name }} | |
| - name: Update Metrics Snapshot | |
| run: | | |
| mkdir -p .github/metrics | |
| # Read metrics from meta agent output (meta-metrics.json) | |
| if [ -f .github/metrics/meta-metrics.json ]; then | |
| node -e " | |
| const fs = require('fs'); | |
| const m = JSON.parse(fs.readFileSync('.github/metrics/meta-metrics.json', 'utf8')); | |
| m.ts = new Date().toISOString(); | |
| fs.writeFileSync('.github/metrics/meta.json', JSON.stringify(m, null, 2)); | |
| const logLine = \`| \${m.ts} | coverage:\${m.coverage} | changes:\${m.changes} | errors:\${m.errors} | optouts:\${m.optouts} |\n\`; | |
| fs.appendFileSync('.github/metrics/meta-log.md', logLine); | |
| " | |
| else | |
| echo "Warning: .github/metrics/meta-metrics.json not found. Writing zeroed metrics." | |
| node -e " | |
| const fs = require('fs'); | |
| let m = { ts: new Date().toISOString(), coverage: 0, changes: 0, errors: 0, optouts: 0 }; | |
| fs.writeFileSync('.github/metrics/meta.json', JSON.stringify(m, null, 2)); | |
| const logLine = \`| \${m.ts} | coverage:0 | changes:0 | errors:0 | optouts:0 |\n\`; | |
| fs.appendFileSync('.github/metrics/meta-log.md', logLine); | |
| " | |
| fi | |
| - name: Commit metrics | |
| run: | | |
| git config user.name "lightspeed-bot" | |
| git config user.email "ops@lightspeedwp.agency" | |
| git add .github/metrics/meta.json .github/metrics/meta-log.md | |
| if ! git diff --cached --quiet; then | |
| git commit -m "chore(meta): update metrics snapshot [skip ci]" | |
| git push origin ${{ github.ref_name }} | |
| fi |