Files
prautoblogger/.github/workflows/ci.yml
peptiderepo 923f7124c3 ci: add PRAUTOBLOGGER_* constants guard (scripts/check-constants.php)
Wires a new required CI step — 'Check PRAUTOBLOGGER_* constants' — that
fails the build when any PRAUTOBLOGGER_* constant referenced in the
shipped plugin PHP is neither:
  (a) define()d in prautoblogger.php (including conditional OPIK defines), nor
  (b) protected by a defined() guard at the reference site.

This closes the regression class that caused the v0.19.0 admin-500 incident:
PR #156 deleted three constants from prautoblogger.php; CI stayed green because
tests/bootstrap.php holds fallback copies, masking the gap until prod boot.

Deliverables:
  - scripts/check-constants.php (212 lines, no Composer deps, PHP 8.1+)
  - .github/workflows/ci.yml: new 'check-constants' job
  - CHANGELOG.md: one-line note under [Unreleased - Internal]

No plugin version bump (CI-only; shipped artifact unchanged).

AC-1 verified locally (Python3 equivalent logic):
  - HEAD passes clean (0 violations)
  - Remove PRAUTOBLOGGER_DEFAULT_RUN_CEILING_USD -> 2 violations caught
  - Remove PRAUTOBLOGGER_DEFAULT_REQUEST_JSON_RETENTION_DAYS -> 3 violations caught
  - Remove PRAUTOBLOGGER_DEFAULT_REASONING_MAX_TOKENS -> 1 violation caught

Agent-Session: ci-constants-guard-20260614
2026-06-14 12:40:04 +00:00

129 lines
4.6 KiB
YAML

name: CI — Lint & Test
# Runs on every PR and every push to main. Validates PHPUnit tests + lint +
# coding standards before deploy can happen. deploy.yml on main continues to
# run its own validate job as a belt-and-suspenders check, but this CI workflow
# is what gives PRs an immediate signal so fixes happen before merge.
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: read
jobs:
php-lint:
name: PHP Lint (${{ matrix.php }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.2', '8.3']
steps:
- uses: actions/checkout@v4
- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
- name: Syntax check all PHP files
# Exclude .github/mu-plugins — those run on the production server (PHP 8+)
# and may use PHP 8+ syntax (union types etc.) that older versions reject.
run: |
set -e
find . -name '*.php' \
-not -path './vendor/*' \
-not -path './node_modules/*' \
-not -path './.git/*' \
-not -path './.github/*' \
-print0 | xargs -0 -n1 -P4 php -l > /dev/null
phpcs:
name: PHPCS (WordPress standards)
runs-on: ubuntu-latest
continue-on-error: false # strict after PHPCS cleanup in v0.8.3
permissions:
contents: write # allows phpcbf auto-fix commits back to the PR branch
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref || github.ref_name }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
coverage: none
tools: composer:v2, phpcs
- name: Install WordPress Coding Standards
run: |
composer global config --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer global require --no-interaction \
"dealerdirect/phpcodesniffer-composer-installer:^1.0" \
"wp-coding-standards/wpcs:^3.0" \
"phpcsstandards/phpcsutils:^1.0" \
"phpcsstandards/phpcsextra:^1.0"
- name: Auto-fix with phpcbf (commit back to branch if changed)
# phpcbf exits 1 when it makes fixes, 0 when nothing to fix — both are success here.
# Commits made via GITHUB_TOKEN do not trigger a new CI run (GitHub prevents loops).
run: |
phpcbf --standard=phpcs.xml \
--extensions=php \
--ignore=vendor/*,tests/*,node_modules/* \
includes/ prautoblogger.php uninstall.php || true
if ! git diff --quiet; then
git config user.name "peptiderepo"
git config user.email "peptiderepo@users.noreply.github.com"
git add -A
git commit -m "style: auto-fix PHPCS violations via phpcbf"
git push
fi
- name: Run PHPCS (only non-auto-fixable violations can fail here)
run: |
phpcs --standard=phpcs.xml \
--extensions=php \
--ignore=vendor/*,tests/*,node_modules/* \
--warning-severity=0 \
--report=full \
includes/ prautoblogger.php uninstall.php
phpunit:
name: PHPUnit (PHP ${{ matrix.php }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.2', '8.3']
steps:
- uses: actions/checkout@v4
- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
tools: composer:v2
- name: Install composer dependencies
run: composer install --no-progress --no-interaction --prefer-dist
- name: Run PHPUnit (Brain Monkey — no WP install required)
run: vendor/bin/phpunit --testdox
check-constants:
name: Check PRAUTOBLOGGER_* constants
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup PHP 8.1
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
coverage: none
- name: Check PRAUTOBLOGGER_* constants
# Fails if any PRAUTOBLOGGER_* constant referenced in the shipped
# plugin PHP is neither defined in prautoblogger.php nor guarded
# by defined() at the reference site. Prevents the v0.19.0 incident
# class (constant deleted from bootstrap, test fallback masks the gap).
run: php scripts/check-constants.php