diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..4f35913 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,28 @@ +# Weekly update PRs, one per ecosystem, so no dependency sits on a known +# vulnerability or a deprecated version for long. All of these are build and CI +# tooling: none of them ship in the plugin zip (see .distignore). +version: 2 +updates: + - package-ecosystem: npm + directory: / + schedule: + interval: weekly + groups: + npm: + patterns: [ '*' ] + + - package-ecosystem: composer + directory: / + schedule: + interval: weekly + groups: + composer: + patterns: [ '*' ] + + - package-ecosystem: github-actions + directory: / + schedule: + interval: weekly + groups: + actions: + patterns: [ '*' ] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5b7c1ea..7b4e979 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,6 +9,11 @@ on: permissions: contents: read +# A new push to a pull request supersedes the run for the previous one. +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + jobs: php-lint: name: PHP ${{ matrix.php }} syntax @@ -18,26 +23,27 @@ jobs: matrix: # Floor is the plugin's "Requires PHP"; ceiling is the newest release, which # is where the PHP 8 breakage fixed in 3.4.0 would have shown up first. - php: [ '7.4', '8.0', '8.2', '8.4', '8.5' ] + # Behavioural differences between versions are phpcs's job (PHPCompatibility). + php: [ '7.4', '8.0', '8.2', '8.4', '8.5', '8.6' ] steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 - uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} coverage: none - name: Lint every PHP file run: | - find . -path ./vendor -prune -o -path ./node_modules -prune -o -name '*.php' -print \ + find . -path ./vendor -prune -o -path ./node_modules -prune -o -path ./build -prune -o -name '*.php' -print \ | xargs -n1 -P4 php -l phpcs: name: WordPress coding standards runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 - uses: shivammathur/setup-php@v2 with: - php-version: '8.2' + php-version: '8.5' coverage: none tools: composer - run: composer install --prefer-dist --no-progress @@ -47,10 +53,10 @@ jobs: name: Minified assets are current runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - uses: actions/checkout@v7 + - uses: actions/setup-node@v7 with: - node-version: '20' + node-version: lts/* cache: npm - run: npm ci # Catches the case where fancybox.css is edited but the .min is not rebuilt - @@ -61,14 +67,14 @@ jobs: name: Package builds cleanly runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - uses: actions/checkout@v7 + - uses: actions/setup-node@v7 with: - node-version: '20' + node-version: lts/* # Also asserts the plugin header, FBFW_VERSION, readme Stable tag and # package.json all agree, and that no dev file leaked into the zip. - run: npm run package - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@v7 with: name: plugin-zip path: build/*.zip @@ -81,10 +87,10 @@ jobs: # Lets the action post its findings as a PR comment. pull-requests: write steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - uses: actions/checkout@v7 + - uses: actions/setup-node@v7 with: - node-version: '20' + node-version: lts/* cache: npm - run: npm ci diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ef3ee8e..8c5b975 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -7,8 +7,14 @@ name: Deploy to WordPress.org # said 3.4.0. Releasing from a tag makes git the source of truth and removes the # manual SVN step where that drift crept in. # -# Requires two repository secrets: SVN_USERNAME and SVN_PASSWORD (a WordPress.org -# account with commit access to the plugin). +# The Publish job is opt-in. It runs only when the repository variable +# WPORG_SVN_DEPLOY is `true` and needs two repository secrets, SVN_USERNAME and +# SVN_PASSWORD (a WordPress.org account with commit access to the plugin). +# +# Until then releases go to SVN by hand from the GitHub release zip, and every tag +# push still runs Pre-flight. Without the switch, each release turned this workflow +# red at the credentials step, which taught everyone to ignore a red deploy. The +# "WordPress.org matches git" workflow checks the published result either way. on: push: @@ -29,10 +35,10 @@ jobs: name: Pre-flight runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - uses: actions/checkout@v7 + - uses: actions/setup-node@v7 with: - node-version: '20' + node-version: lts/* cache: npm - run: npm ci @@ -54,14 +60,24 @@ jobs: exit 1 fi + - name: Say how this tag reaches WordPress.org + if: startsWith(github.ref, 'refs/tags/') && vars.WPORG_SVN_DEPLOY != 'true' + run: | + { + echo "### Publishing is manual" + echo "WPORG_SVN_DEPLOY is not \`true\`, so this run does not publish to WordPress.org." + echo "Commit the GitHub release zip to SVN trunk and tags/${GITHUB_REF#refs/tags/}." + echo "The *WordPress.org matches git* workflow checks the result daily." + } >> "$GITHUB_STEP_SUMMARY" + deploy: name: Publish needs: verify runs-on: ubuntu-latest - if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'push' + if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'push' && vars.WPORG_SVN_DEPLOY == 'true' environment: wordpress-org steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 # Without this the run dies deep inside the SVN step with an authentication # error that does not say what is actually wrong. diff --git a/.github/workflows/release-check.yml b/.github/workflows/release-check.yml new file mode 100644 index 0000000..190d949 --- /dev/null +++ b/.github/workflows/release-check.yml @@ -0,0 +1,67 @@ +name: WordPress.org matches git + +# Daily: the version WordPress.org serves must have a git tag, and both its +# WordPress.org download and its GitHub release zip must contain exactly what that +# tag builds. Releases reach SVN by hand, which is where 3.3.7 (never committed to +# git) and 3.4.1 (shipped while master said 3.4.0) drifted. A readme-only SVN edit, +# such as bumping "Tested up to", also fails this until it is committed to git and +# the release is re-tagged. + +on: + schedule: + - cron: '23 6 * * *' + workflow_dispatch: + inputs: + version: + description: 'Version to check (default: the one WordPress.org serves)' + required: false + +permissions: + contents: read + +jobs: + compare: + name: Published release matches its tag + runs-on: ubuntu-latest + steps: + - name: Find the version to check + id: version + env: + REQUESTED: ${{ inputs.version }} + run: | + VERSION="$REQUESTED" + if [ -z "$VERSION" ]; then + VERSION=$(curl -fsS https://api.wordpress.org/plugins/info/1.0/fancybox-for-wordpress.json | jq -r .version) + fi + if ! printf '%s' "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then + echo "::error::Not a version number: '$VERSION'" + exit 1 + fi + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + + # The checker comes from master so an older tag is judged by the current rules. + - uses: actions/checkout@v7 + with: + path: tools + sparse-checkout: bin/verify-release.mjs + sparse-checkout-cone-mode: false + + - name: Check out the release tag + env: + VERSION: ${{ steps.version.outputs.version }} + run: | + if ! git clone --quiet --depth 1 --branch "$VERSION" "https://github.com/${GITHUB_REPOSITORY}.git" release; then + echo "::error::WordPress.org serves $VERSION, but git has no $VERSION tag." + exit 1 + fi + + - uses: actions/setup-node@v7 + with: + node-version: lts/* + + - name: Compare WordPress.org and the GitHub release with the tag + working-directory: release + env: + GITHUB_TOKEN: ${{ github.token }} + VERSION: ${{ steps.version.outputs.version }} + run: node ../tools/bin/verify-release.mjs "$VERSION" diff --git a/CLAUDE.md b/CLAUDE.md index 7e8fe13..a22e028 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -16,7 +16,8 @@ npm run verify:assets # fail if a .min file is stale — this is what CI enfo npm run i18n # regenerate .pot, .mo and .l10n.php (needs wp-cli on PATH) npm run package # build build/fancybox-for-wordpress-.zip npm run release:check # verify:assets + composer lint + package -composer phpcs # escaping, sanitisation, nonces, i18n, PHP 7.4–8.5 compatibility +npm run verify:release # from a tag checkout: WordPress.org zip and GitHub release asset == the tag's build +composer phpcs # escaping, sanitisation, nonces, i18n, PHP 7.4+ compatibility composer lint # php -l across every file ``` @@ -29,7 +30,15 @@ Two guards worth knowing about, because both encode mistakes that actually happe ### Releasing -Push a version tag and `.github/workflows/deploy.yml` publishes that commit to WordPress.org SVN. It needs the `SVN_USERNAME` / `SVN_PASSWORD` repository secrets. **Do not release by hand** — 3.3.7 shipped to WordPress.org and was never committed to git, and 3.4.1 shipped while `master` still said 3.4.0. Releasing from a tag makes git the source of truth and removes the step where that drift occurred. +Git is the source of truth. 3.3.7 shipped to WordPress.org and was never committed to git, and 3.4.1 shipped while `master` still said 3.4.0, so the release order is fixed: merge to `master`, `gh release create X --target master --latest` (zip built from `master`, no `v` prefix), and only then commit **that release zip's contents** to SVN trunk and `tags/X` in one revision. Never copy the repo root into SVN. + +The SVN step is manual for now. `.github/workflows/deploy.yml` runs a pre-flight on every tag push (assets current, versions agree, tag equals version), but its Publish job runs only when the repository variable `WPORG_SVN_DEPLOY` is `true` and the `SVN_USERNAME` / `SVN_PASSWORD` secrets exist. Neither is set, which keeps a tag push green instead of failing at the credentials step on every release. + +`.github/workflows/release-check.yml` ("WordPress.org matches git") runs daily. It rebuilds the version WordPress.org serves from its git tag and compares it file by file with the WordPress.org download and the GitHub release asset (`bin/verify-release.mjs`). A readme-only SVN edit, such as bumping `Tested up to` in a tag, fails it until the change is in git and released. Run it by hand after an SVN commit, once the WordPress.org zip has regenerated. + +PHP cross-version checks use **PHPCompatibility 10 (alpha)**. The stable 9.3.5 knows nothing after PHP 7.4, so it passed a PHP 8.1 behaviour change (`html_entity_decode()` default flags) that 10 caught. Move to 10.0 stable when it ships; the `@alpha` flags in `composer.json` are the only reason the alpha resolves. PHP_CodeSniffer stays on 3.x until WPCS supports 4. + +Dependabot (`.github/dependabot.yml`) opens weekly grouped PRs for npm, Composer and Actions. All of them are build tooling; the runtime libraries (DOMPurify, fancyBox, the jQuery UI stylesheet) are vendored files and must be updated by hand. `phpcs.xml.dist` deliberately runs a **subset** of the WordPress standard. The full `WordPress` ruleset reports 293 violations here, all of them whitespace, array alignment or missing docblocks, and zero security/i18n/compatibility problems. The rules kept are the ones that catch real defects; see the file's own `` for how to adopt full formatting later. @@ -113,7 +122,7 @@ Minified files ship by default; `SCRIPT_DEBUG` switches to the readable sources | Source | Minified | Regenerate with | | --- | --- | --- | | `assets/js/jquery.fancybox.js` | `jquery.fancybox.min.js` | `npx terser@5 --compress --mangle --comments '/^!\|licen[cs]e\|fancyBox v/i' -o ` | -| `assets/css/fancybox.css` | `fancybox.min.css` | `npx clean-css-cli@5 -O2 -o ` | +| `assets/css/fancybox.css` | `fancybox.min.css` | `node bin/minify-css.mjs ` (the clean-css library at level 2, byte-identical to `cleancss -O2`) | | `assets/js/purify.js` | `purify.min.js` | ship both dist files from `npm pack dompurify@`, stripping the `sourceMappingURL` comments | After minifying, verify the namespace survived and the selector counts match: @@ -139,7 +148,7 @@ Field markup follows a consistent pattern — an `.epsilon-toggle` block for boo Releases 3.3.4 – 3.4.0 were dominated by security fixes. The risky code is structural: -- **Caption/title XSS.** DOMPurify (currently **3.4.17**, bundled) is a hard dependency of the `fancybox-for-wp` script handle. The generated `caption`, `afterLoad` and title-copy JS all route user HTML through `jQuery.fancyboxforwp.sanitize()`, which applies the `elementHtmlRules` allow-list and falls back to `jQuery("
").text(x).html()`. Do not go back to DOMPurify's plain `html` profile: it keeps `