Files
wp-asciiplayer/.github/workflows/ci.yml

257 lines
10 KiB
YAML

name: Build and WordPress integration
on:
pull_request:
push:
branches: ['main', 'codex/**']
# GitHub tag filters are globs, not SemVer validators. Validate before building.
tags: ['**']
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref_type != 'tag' }}
jobs:
release-validation:
name: Validate release tag and version metadata
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
if: github.ref_type == 'tag'
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0
if: github.ref_type == 'tag'
with:
node-version: '24.18.0'
package-manager-cache: false
- name: Require a tag commit already included in main
if: github.ref_type == 'tag'
run: |
if ! git merge-base --is-ancestor HEAD origin/main; then
echo '::error::Release tags must point to a commit already merged into main.'
exit 1
fi
- name: Validate strict SemVer and matching plugin metadata
id: version
if: github.ref_type == 'tag'
env:
RELEASE_TAG: ${{ github.ref_name }}
run: node scripts/release-version.mjs
php-compatibility:
needs: release-validation
name: PHP ${{ matrix.php }} syntax and regression tests
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
php: ['7.4', '8.3']
steps:
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
- name: Check syntax and execute PHP regression tests
run: |
docker run --rm -v "$PWD:/app" -w /app "php:${{ matrix.php }}-cli" sh -ec '
find . -type f -name "*.php" -not -path "./node_modules/*" -print0 | xargs -0 -n1 php -l
php tests/php/run.php
'
# Only this job publishes the installable package. No WordPress containers or
# downloaded plugins run here, and the artifact is immutable once uploaded.
build:
needs: release-validation
name: Build and publish pristine package
runs-on: ubuntu-latest
timeout-minutes: 15
outputs:
package-artifact-id: ${{ steps.package.outputs.artifact-id }}
steps:
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0
with:
node-version: '24.18.0'
cache: npm
- name: Use the documented npm toolchain
run: npm install --global [email protected]
- run: npm ci
- run: npm run build
- run: npm test
- run: npm run package
- name: Upload pristine installable ZIP
id: package
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: wp-asciiplayer-package-${{ github.run_id }}-${{ github.run_attempt }}
path: dist/wp-asciiplayer.zip
if-no-files-found: error
retention-days: 14
wordpress:
needs: build
name: WordPress ${{ matrix.wordpress }} / PHP ${{ matrix.php }}
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
include:
- wordpress: 'latest'
php: '8.2'
- wordpress: '6.3'
php: '7.4'
steps:
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0
with:
node-version: '24.18.0'
cache: npm
- name: Use the documented npm toolchain
run: npm install --global [email protected]
- run: npm ci
- name: Download the pristine package from this run
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
artifact-ids: ${{ needs.build.outputs.package-artifact-id }}
path: dist
merge-multiple: true
- name: Configure clean WordPress version
env:
WP_TEST_VERSION: ${{ matrix.wordpress }}
WP_TEST_PHP: ${{ matrix.php }}
run: |
node --input-type=module <<'JS'
import fs from 'node:fs';
fs.writeFileSync('.wp-env.override.json', JSON.stringify({
core: process.env.WP_TEST_VERSION === 'latest' ? null : `https://wordpress.org/wordpress-${process.env.WP_TEST_VERSION}.zip`,
phpVersion: process.env.WP_TEST_PHP,
}, null, 2));
JS
- name: Start real WordPress and install only the packaged plugin
run: |
mkdir -p .wp-env-uploads
npx --no-install wp-env start
npx --no-install wp-env run cli wp plugin install /var/www/html/wp-content/asciiplayer-packages/wp-asciiplayer.zip --activate --force
npx --no-install wp-env run cli wp plugin is-active wp-asciiplayer
npx --no-install wp-env run cli wp core version | tee wordpress-version.txt
npx --no-install wp-env run cli wp plugin list
npx --no-install wp-env run cli wp language core install zh_CN
npx --no-install wp-env run cli wp site switch-language en_US
npx --no-install wp-env run cli wp user meta update admin locale en_US
- name: Install Chromium
run: npx --no-install playwright install --with-deps chromium
- name: Exercise editor iframe, saved blocks, Pages, posts and legacy shortcodes
env:
PLAYWRIGHT_HTML_OUTPUT_DIR: playwright-report/en-US
run: npm run test:e2e -- --grep-invert @i18n --output=test-results/en-US
- name: Exercise real en_US and zh_CN site and user locale combinations
env:
PLAYWRIGHT_HTML_OUTPUT_DIR: playwright-report/i18n
run: npm run test:e2e -- --grep @i18n --output=test-results/i18n
- name: Record WordPress and PHP logs
if: always()
run: |
npx --no-install wp-env logs --watch=false > wordpress-logs.txt 2>&1 || true
npx --no-install wp-env run cli sh -c 'test ! -f wp-content/debug.log || cat wp-content/debug.log' > wordpress-debug.txt 2>&1 || true
- name: Upload integration evidence
if: always()
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: wordpress-${{ matrix.wordpress }}-php-${{ matrix.php }}
if-no-files-found: warn
retention-days: 14
path: |
playwright-report/
test-results/
wordpress-version.txt
wordpress-logs.txt
wordpress-debug.txt
- name: Stop WordPress
if: always()
run: npx --no-install wp-env stop
# Plugin Check receives its own disposable copy. It cannot replace the package
# uploaded by build, and this job never republishes files from dist.
plugin-check:
name: Plugin Check (advisory)
needs: build
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0
with:
node-version: '24.18.0'
cache: npm
- name: Use the documented npm toolchain
run: npm install --global [email protected]
- run: npm ci
- name: Download the pristine package from this run
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
artifact-ids: ${{ needs.build.outputs.package-artifact-id }}
path: dist
merge-multiple: true
- name: Start WordPress and install the packaged plugin
run: |
mkdir -p .wp-env-uploads
npx --no-install wp-env start
npx --no-install wp-env run cli wp plugin install /var/www/html/wp-content/asciiplayer-packages/wp-asciiplayer.zip --activate --force
- name: Run Plugin Check (advisory until directory review)
continue-on-error: true
run: |
npx --no-install wp-env run cli wp plugin install plugin-check --activate
npx --no-install wp-env run cli wp plugin get plugin-check --field=version | tee plugin-check-version.txt
npx --no-install wp-env run cli wp plugin check wp-asciiplayer --require=/var/www/html/wp-content/plugins/plugin-check/cli.php --format=json | tee plugin-check-report.txt
- name: Upload Plugin Check evidence only
if: always()
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: plugin-check-${{ github.run_id }}-${{ github.run_attempt }}
if-no-files-found: warn
retention-days: 14
path: |
plugin-check-version.txt
plugin-check-report.txt
- name: Stop WordPress
if: always()
run: npx --no-install wp-env stop
release-draft:
name: Create release draft from the pristine package
if: github.event_name == 'push' && github.ref_type == 'tag'
needs: [release-validation, build, php-compatibility, wordpress, plugin-check]
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write
steps:
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
with:
persist-credentials: false
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0
with:
node-version: '24.18.0'
package-manager-cache: false
- name: Download only the original build artifact
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
artifact-ids: ${{ needs.build.outputs.package-artifact-id }}
path: dist
merge-multiple: true
- name: Generate notes and prepare an unpublished release
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ github.ref_name }}
RELEASE_VERSION: ${{ needs.release-validation.outputs.version }}
run: |
node scripts/release-draft.mjs --tag "$RELEASE_TAG" --version "$RELEASE_VERSION" --commit "$(git rev-parse HEAD)" --zip dist/wp-asciiplayer.zip