repomatic.metadata.git module¶
Git commit-range logic of Metadata.
Resolves the commit range an event bundles, the release commits inside it, what those commits changed, and the per-commit matrices. Every read goes through the git object store, so the checkout and the working tree never move.
- repomatic.metadata.git.version_at(ref)[source]¶
Return the version bump-my-version manages, as committed at ref.
Reads
BUMPVERSION_SOURCESfrom the object store, so a past commit is read without a checkout. A file that is absent at ref, or does not parse, is skipped like a file without the key.
- repomatic.metadata.git.commit_matrix(shas)[source]¶
Pre-compute a matrix of commits, in the order given.
Each entry carries the long and short SHA, and the version the commit declares, read by
version_at(). Returns a ready-to-use matrix structure, here for a release push listing its commits oldest first:{ "commit": [ "346ce664f055fbd042a25ee0b7e96702e95", "6f27db47612aaee06fdf08744b09a9f5f6c2", ], "include": [ { "commit": "346ce664f055fbd042a25ee0b7e96702e95", "short_sha": "346ce66", "current_version": "2.0.0", }, { "commit": "6f27db47612aaee06fdf08744b09a9f5f6c2", "short_sha": "6f27db4", "current_version": "2.0.1.dev0", }, ], }
- class repomatic.metadata.git.GitMetadata[source]¶
Bases:
objectCommit ranges, changed files, and the per-commit matrices.
A concern mixin of
Metadata: never instantiated on its own, and reads sibling concerns throughself.- property changed_files: tuple[str, ...] | None[source]¶
Returns the files changed in the current event’s commit range.
Diffs the trees of the two ends of
commit_range. An end that is missing from a shallow clone is fetched first, on its own: the diff needs that commit’s tree, not the history in between.Returns
Nonewhen the range is unknown: outside CI, on a push that creates a branch or a tag (its start isNULL_SHA), or when git cannot produce an end of the range.
- property binary_affecting_paths: tuple[str, ...][source]¶
Path prefixes that affect compiled binaries for this project.
Combines the static
BINARY_AFFECTING_PATHS(common files likepyproject.toml,uv.lock,tests/) with the project’s source directories, from two places:The top-level package of each
[project.scripts]entry point. A project withmpm = "meta_package_manager.__main__:main"addsmeta_package_manager/.The
[tool.repomatic] workflow.source-pathsdirectories, or the import name they default to. This is what covers asrc/layout, whose package does not sit at the root the entry point names.
This makes the check reusable across downstream repositories without hardcoding source directories.
- property head_commit_message: str[source]¶
Returns
github.event.head_commit.messagefrom the event payload.Set for
pushevents. Empty string for events that do not carry a head commit (pull_request,schedule,workflow_dispatch).
- property yaml_changed: bool[source]¶
Whether the current event’s commit range touches a YAML file.
Lets per-job lint gates short-circuit on pushes / PRs that don’t touch YAML. Falls back to “repo contains any YAML file” when the commit range is unavailable (
workflow_dispatch), preserving the existing behavior of those manual runs.
- property shfmt_changed: bool[source]¶
Whether the current event’s commit range touches a
shfmt_filesfile.Gates the ShellCheck lint job, which reads the files
shfmtformats. Falls back to “repo contains any such file” when the commit range is unavailable.
- property zsh_changed: bool[source]¶
Whether the current event’s commit range touches a Zsh file.
Falls back to “repo contains any Zsh file” when the commit range is unavailable.
- property workflows_changed: bool[source]¶
Whether the current event’s commit range touches a GitHub workflow file.
Falls back to “repo contains any workflow file” when the commit range is unavailable.
- property skip_binary_build: bool[source]¶
Returns
Trueif binary builds should be skipped for this event.Binary builds are expensive and time-consuming. This property identifies contexts where the changes cannot possibly affect compiled binaries, allowing workflows to skip Nuitka compilation jobs.
Three mechanisms are checked:
Branch name: PRs from known non-code branches (documentation,
.mailmap,.gitignore, etc.) are skipped.Version-bump commit: Push events whose head commit is a user-initiated version bump (
Bump (major|minor) version to) are skipped: the bump merge changes only version strings anduv.lock, so the new binary differs from the previous one only in the baked-in version string. The[changelog] Post-release bumpprefix is deliberately not checked here: theprepare-releasemerge bundles the release commit with the post-release-bump commit, and the release commit must still produce its binary.Changed files: Push events where all changed files fall outside
binary_affecting_pathsare skipped. This avoids ~2h of Nuitka builds for documentation-only commits tomain.
- property commit_range: tuple[str | None, str] | None[source]¶
Range of commits bundled within the triggering event.
A workflow run is triggered by a singular event, which might encapsulate one or more commits. This means the workflow will only run once on the last commit, even if multiple new commits were pushed.
This is critical for releases where two commits are pushed together:
[changelog] Release vX.Y.Z: the release commit[changelog] Post-release bump vX.Y.Z → vX.Y.Z: the post-release bump
Without extracting the full commit range, the release commit would be missed since
github.event.head_commitonly exposes the post-release bump.This property also enables processing each commit individually when we want to keep a carefully constructed commit history. The typical example is a pull request that is merged upstream but we’d like to produce artifacts (builds, packages, etc.) for each individual commit.
The default
GITHUB_SHAenvironment variable is not enough as it only points to the last commit. We need to inspect the commit history to find all new ones. New commits need to be fetched differently inpushandpull_requestevents.See also
See also
Pull request events on GitHub are a bit complex, see: The Many SHAs of a GitHub Pull Request.
- property current_commit_matrix: Matrix | None[source]¶
Pre-computed matrix with long and short SHA values of the current commit.
- property new_commits: tuple[Commit, ...] | None[source]¶
Returns list of all
Commitobjects bundled within the triggering event.This extracts all commits from the push event, not just
head_commit. For releases, this typically includes both the release commit and the post-release bump commit, allowing downstream jobs to process each one.Commits are returned in chronological order (oldest first, most recent last).
A shallow clone is completed as far as the range needs: both ends are fetched, then the clone is deepened until they share history. See
deepen_until_related()for why both ends being present is not enough.
- property new_commits_matrix: Matrix | None[source]¶
Pre-computed matrix with long and short SHA values of new commits.
- property release_commits: tuple[Commit, ...] | None[source]¶
Returns list of
Commitobjects to be tagged within the triggering event.This filters
new_commitsto find release commits that need special handling: tagging, PyPI publishing, and GitHub release creation.This is essential because when a release is pushed,
github.event.head_commitonly exposes the post-release bump commit, not the release commit. By extracting all commits from the event (vianew_commits) and filtering for release commits here, we ensure the release workflow can properly identify and process the[changelog] Release vX.Y.Zcommit.We cannot identify a release commit based on the presence of a
vX.Y.Ztag alone. That’s because the tag is not present in theprepare-releasepull request produced by thechangelog.yamlworkflow. The tag is created later by therelease.yamlworkflow, when the pull request is merged tomain.Our best option is to identify a release based on the full commit message, using the template from the
changelog.yamlworkflow.
- property release_commits_matrix: Matrix | None[source]¶
Pre-computed matrix with long and short SHA values of release commits.
- property is_release_push: bool[source]¶
Whether the event lands release commits on the release branch.
The test every job that tags, attests or publishes runs before it acts: a release commit reached through another ref (a manual run on a feature branch) must not publish anything.
- property release_commit: str | None[source]¶
The commit a job checks out to work on the tree being released.
A rebase-merged release pull request pushes the freeze commit and the post-release bump together, so the event’s own commit already carries the next
.devNversion. This is the newest release commit of the event, and the event’s own commit when it carries none.release_commitslists the commits oldest first, so the newest one is the last.