Skip to content

Make build reuse version-safe via build fingerprints - #321

Open
Biont wants to merge 3 commits into
mainfrom
fix/build-fingerprint
Open

Biont wants to merge 3 commits into
mainfrom
fix/build-fingerprint

Conversation

@Biont

@Biont Biont commented Dec 2, 2026

Copy link
Copy Markdown
Member

Problem

The duplicate-build check in build-and-distribute compared the commit SHA (and, since 0ca4322, a substring of the version) against the tip of the build branch. Two failure modes followed:

  • Wrong version shipped. A release build with an explicit PACKAGE_VERSION (e.g. 8.2.1) on a commit that already had a dev build could reuse that dev build. The substring match lets Version: 8.2.1 match Version: 8.2.1+main.abc1234. Combined with the SVN sync, the public release then carries the auto-generated dev version.
  • Single-slot cache. Because only the tip is checked, alternating inputs for the same commit (dev build ↔ release build) always rebuild each other away.

Changes

build-and-distribute.yml

  • Build fingerprint: a SHA-256 over the commit SHA, the reusable workflow's own revision (job.workflow_sha), the resolved PACKAGE_VERSION, and toJSON(inputs). New inputs are covered automatically. ENV_VARS is deliberately excluded because it is a secret and the fingerprint is public.
  • Build-Key: commit trailer on every build commit. --allow-empty makes sure the key is recorded even when the output is unchanged.
  • History lookup: the whole build branch history is searched for an exact fingerprint match. On a hit, the matching commit is checked out and packaged, and nothing is pushed.
  • New build-commit output: the SHA of the build commit the artifact came from. Downstream steps (tagging, deploying, SVN release) should use it instead of the build branch name, because a reused build is not necessarily the branch tip.
  • Libraries now benefit from build reuse too. The old check relied on the plugin/theme SHA: header.

wordpress-org-release.yml

  • The plugin header version is now compared exactly. Previously only the first x.y.z was extracted, so 8.2.1+main.abc1234 passed as 8.2.1. This guard makes a wrong version fail the release regardless of what happens upstream.

Docs

  • Describe the fingerprint, the history lookup, and the new output (with a GIT_REF: build-commit example for the SVN release).
  • Fix the stale version format: generated versions are {release}+{branch}.{short-sha} (build metadata), not {release}-{branch}.

Rollout notes

  • Release pipelines in consumer repos should pass needs.<build-job>.outputs.build-commit as GIT_REF to wordpress-org-release instead of a branch name.
  • Build branch history must not be rewritten (squash, force-push), or older builds can't be found and are rebuilt.
  • One-time rebuild: existing build branches have no trailers, so the first run per branch rebuilds once. Every change to this repository also changes job.workflow_sha and causes one rebuild per consumer.
  • job.workflow_sha requires runner v2.334.0+ and is not available on GHES. If it is empty, the only effect is that workflow changes don't invalidate old builds.

Testing

  • The fingerprint, the history lookup (including alternating keys and misses), and the new version extraction were checked locally with a script.
  • Not yet run on GitHub Actions, and actionlint has not been run locally.

Follow-up

A stacked PR restructures the workflow into resolve / build / package jobs to remove the SKIP_BUILD conditions and fixes the push race between different commits.

The duplicate check only compared the commit SHA (and later a substring of
the version) against the tip of the build branch. A release build with an
explicit PACKAGE_VERSION on an unchanged commit could therefore reuse the
previous dev build and ship its auto-generated version string.

- Fingerprint each build from the commit SHA, the resolved package version,
  all workflow inputs, and the reusable workflow revision; record it as a
  Build-Key commit trailer.
- Search the whole build branch history for a matching fingerprint, so
  alternating inputs for the same commit don't rebuild each other away.
  On a hit, package the matching commit and push nothing.
- Expose the build commit as a `build-commit` workflow output so downstream
  jobs can reference the exact build instead of the branch name.
- wordpress-org-release: compare the full plugin header version exactly,
  so a build-stamped version like 1.2.3+main.abc1234 no longer passes as 1.2.3.
- Docs: describe the fingerprint and outputs, fix the stale version format.
Biont added 2 commits December 2, 2026 17:43
…er parsing

- Fail the fingerprint step if job.workflow_sha is empty, so a fix to this
  workflow can never silently reuse builds made before it.
- wordpress-org-release: parse headers like WordPress' get_file_data()
  (optional "<?php", "//" comments, case-insensitive, comment closers
  stripped), and read readme.txt's full Stable tag value instead of the
  first x.y.z, so e.g. 1.2.3-rc1 no longer passes as 1.2.3.
- Docs: the publish example only runs for releases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant