report_project_versions
Report which task template version each configured project is actually on.
Projects are deployed independently, so no single workflow run or git tag describes what every project holds. This script reads each project's state from the hub and compares it against the config directory the deployment workflow reads.
Task templates are the only part of this with real versioning: the hub assigns a
monotonic integer per owner/slug, and a project's latest task definition names the
one it is rendered from. Template variables have no version of their own, so they are
compared by a digest of their resolved values.
Example usage: python -m bitfount.runners.report_project_versions report \ task_templates/project-config-production-public --username myuser \ --password mypass --json-output report-bitfount.json
Render one markdown table from the per-account reports:
python -m bitfount.runners.report_project_versions summarise \ report-bitfount.json report-bitfount-testing.json
Module
Functions
compute_changes
def compute_changes( before: list[ProjectVersionRow], after: list[ProjectVersionRow],) ‑> list[ProjectChange]:Find what a deployment changed, by comparing two reports.
The comparison is of two hub snapshots, so it reports the state the hub holds and needs nothing from the update path itself.
Arguments
before: The rows reported before the deployment.after: The rows reported after it.
Returns One entry per project that moved, in project id order.
diff
def diff( before: str, after: str, markdown_output: str | None = None, slack_output: str | None = None, title: str = 'Production deployment', context: str = '', channel: str | None = None, run_url: str | None = None,) ‑> None:Report what changed between two merged reports.
Arguments
before: The merged report written before the deployment.after: The merged report written after it.markdown_output: Optional path to write the markdown summary to.slack_output: Optional path to write a Slack blocks payload to.title: The heading for the summary.context: A line of provenance, such as the tag and filters deployed.channel: The Slack channel to post to.run_url: Optional link to the workflow run holding the full detail.
diff_variables
def diff_variables( before: dict[str, Any] | None, after: dict[str, Any] | None,) ‑> list[VariableChange] | None:Compare two sets of template variables key by key.
Arguments
before: The variables on one side, or None if they are not known.after: The variables on the other side, or None if they are not known.
Returns One entry per key that differs, in key order, or None if either side is unknown. None is distinct from an empty list: it means the question cannot be answered, not that the answer is "nothing changed".
fail_on_drift
def fail_on_drift(*json_files: str) ‑> None:Exit non-zero if any reported project disagrees with the config.
Shares DRIFT_STATUSES and the drift acknowledgements with the report
itself, so the workflow gate and the table cannot disagree about what
counts.
Arguments
json_files: The JSON reports written byreport.
latest_template_version
def latest_template_version( task_owner: str, task_slug: str, hub: BitfountHub, hub_url: str, cache: dict[str, int | None],) ‑> int | None:The newest version of a task template, or None if it cannot be read.
Asking per project would repeat the same lookup for every project sharing a
template, so results are cached by owner/slug for the run.
Arguments
task_owner: The template owner.task_slug: The template slug.hub: The hub connection object.hub_url: The hub URL.cache: The per-run cache, keyed byowner/slug.
Returns The newest version, or None if the template could not be read.
render_unapplied_lines
def render_unapplied_lines( changes: list[VariableChange] | None, budget: int = 80,) ‑> list[str]:Render what the config asked for against what the project holds.
A digest says a deployment did not land; this says which variables, what was asked for, and what is there instead.
Arguments
changes: The diff from the configured variables to the ones the project holds, or None if the hub did not report its variables.budget: How many characters of each value to show.
Returns One line per key, or a single line saying the diff is unavailable.
render_value
def render_value(value: Any, budget: int = 80) ‑> str:Render one variable value short enough to sit in a message.
Arguments
value: The value as configured, of whatever type the config gave it.budget: How many characters of the value to show.
Returns
The value as compact JSON, truncated with its full size if it is too long,
or _unset_ for a key that is absent from one side.
render_variable_lines
def render_variable_lines( changes: list[VariableChange] | None, budget: int = 80,) ‑> list[str]:Render a variables diff as message lines.
Arguments
changes: The diff, or None if the hub did not report its variables.budget: How many characters of each value to show.
Returns One line per changed key, or a single line saying the diff is unavailable.
report
def report( config_file: str, username: str, password: str | None = None, project_id: str | None = None, task_slug: str | None = None, trial_name: str | None = None, json_output: str | None = None, git_ref: str | None = None, fail_on_drift: bool = False, variable_update_mode: str | None = None,) ‑> None:Report what each configured project is actually on.
Arguments
config_file: Path to the project config directory, or one file in it.username: The username to authenticate as. Only projects this user owns are reported; the others belong to another account's run.password: Optional password. Falls back to the device code flow.project_id: Only report this project id.task_slug: Only report projects using this task slug.trial_name: Only report projects whosetrial_namevariable is this.json_output: Optional path to write the report to as JSON, for a later step to render or post.git_ref: The git ref the config was read from, recorded in the report as the provenance of the desired state.fail_on_drift: Exit non-zero if any reported project has drifted.variable_update_mode: The mode the deployment was told to use instead of the configured one, recorded so the report says what it was. Requiresproject_id, matching the deployment it reports on.
slack_summary
def slack_summary( *json_files: str, slack_output: str, title: str = 'Production project task template versions', context: str = '', channel: str | None = None, run_url: str | None = None,) ‑> None:Write a Slack payload describing the current state of every project.
Arguments
json_files: The per-account JSON reports written byreport.slack_output: Where to write the payload JSON.title: The message header.context: Optional provenance line shown under the header.channel: The Slack channel to post to.run_url: Optional link to the workflow run holding the full detail.
summarise
def summarise( *json_files: str, markdown_output: str | None = None, json_output: str | None = None,) ‑> None:Render one markdown table from the per-account JSON reports.
Arguments
json_files: The JSON reports written byreport.markdown_output: Optional path to write the markdown to. Written to stdout either way, so a workflow can append it to the job summary.json_output: Optional path to write the merged rows to, fordiffto read as one side of a comparison.
variables_digest
def variables_digest(variables: dict[str, Any]) ‑> str:A short, stable digest of a set of template variables.
Template variables carry no version, so a digest of their resolved values is the only way to say whether two sets are the same one. Keys are sorted so that a reordering of the config does not read as a change.
Arguments
variables: The variable names and values.
Returns
The first few hex characters of the digest, or empty for no variables.
write_slack_payload
def write_slack_payload( path: str, title: str, summary: str, entries: list[SlackEntry] | None = None, context: str = '', max_entries: int = 10, channel: str | None = None, run_url: str | None = None, status: str = 'drift',) ‑> None:Write a Slack chat.postMessage payload for a workflow step to send.
Each project gets its own section block, so a report of several projects reads as a list rather than as one paragraph. Slack's block and character limits are enforced here, because a rejected message is the same to a reader as no message.
Arguments
path: Where to write the payload JSON.title: The message header, shown after the outcome emoji.summary: The one-line result, also used as the notification fallback text. Slack shows this in the sidebar and in push notifications.entries: One entry per project; truncated tomax_entrieswith a count of what is left out.context: Optional provenance line shown under the header.max_entries: How many projects to detail before falling back to a count.channel: The Slack channel to post to. Written into the payload so the workflow step does not have to merge it in.run_url: Optional link to the workflow run, whose job summary holds the full, untruncated detail.status: The message outcome, one ofdeployed,cleanordrift.
Classes
ProjectChange
class ProjectChange( project_id: str, project_owner: str, task_slug: str, template_before: str, template_after: str, variables_before: str | None, variables_after: str | None, status_before: str, status_after: str, project_name: str | None = None, variable_values_before: dict[str, Any] | None = None, variable_values_after: dict[str, Any] | None = None, variable_values_requested: dict[str, Any] | None = None, variable_update_mode: str = 'reset', variable_update_mode_overridden: bool = False, known_drift_reason: str | None = None, drift_acknowledged: bool = False,):What one deployment changed about one project.
Variables
display_name : str- The project named and identified, or identified alone if it has no name.
-
drift_acknowledged : bool
-
has_unapplied_changes : bool- Whether the deployment left the project short of what the config asks.An unreported set on either side leaves the question unanswerable, which is distinct from an answer of "no".
-
known_drift_reason : str | None
moved : bool- Whether the project itself changed, as opposed to staying put.
-
project_id : str
-
project_name : str | None
-
project_owner : str
-
reportable_in_slack : bool- Whether this belongs in the message rather than only in the summary.An acknowledged project that stayed put is the condition the config already records, so repeating it every deployment would bury the projects that did move. One that moves is news whatever was acknowledged.
-
status_after : str
-
status_before : str
-
task_slug : str
-
template_after : str
-
template_before : str
template_changed : bool- Whether the project moved to a different task template version.
-
unapplied_changes : list[VariableChange] | None- What the config asked for that the project does not hold afterwards.A variable only the project has is not something the config asked for, so under
overrideandkeepit is the mode working as intended rather than a shortfall. Underresetthe task is rendered from the config alone, so one surviving means the update did not take.
-
unapplied_is_expected : bool- Whether leaving the config unapplied is what the mode asks for.Under
keepthe project's own variables win by design, so a difference is the configured outcome rather than a failed deployment.
variable_changes : list[VariableChange] | None- The key-level diff of the variables, if both sides reported them.
-
variable_update_mode : str
-
variable_update_mode_overridden : bool
-
variable_values_after : dict[str, typing.Any] | None
-
variable_values_before : dict[str, typing.Any] | None
-
variable_values_requested : dict[str, typing.Any] | None
-
variables_after : str | None
-
variables_before : str | None
-
variables_changed : bool- Whether the project's variables changed.An unreported digest on either side leaves the question unanswerable, which is distinct from an answer of "no".
Methods
describe
def describe(self) ‑> str:One line saying what moved, for a report or a Slack message.
ProjectVersionRow
class ProjectVersionRow( project_id: str, project_owner: str, desired_task_slug: str, desired_template_version: str, desired_variables_digest: str, actual_task_slug: str | None = None, actual_template_version: int | None = None, latest_template_version: int | None = None, actual_variables_digest: str | None = None, status: str = 'unreadable', detail: str = '', desired_variables: dict[str, Any] | None = None, actual_variables: dict[str, Any] | None = None, project_name: str | None = None, variable_update_mode: str = 'reset', variable_update_mode_overridden: bool = False, known_drift_reason: str | None = None, known_drift_digest: str | None = None,):One project's desired and actual state, as reported.
Variables
actual_label : str- Theslug@versionlabel for what the project is actually on.
-
actual_task_slug : str | None
-
actual_template_version : int | None
-
actual_variables : dict[str, typing.Any] | None
-
actual_variables_digest : str | None
-
desired_task_slug : str
-
desired_template_version : str
-
desired_variables : dict[str, typing.Any] | None
-
desired_variables_digest : str
-
detail : str
display_name : str- The project named and identified, or identified alone if it has no name.
-
drift_acknowledged : bool- Whether this project's drift is acknowledged in the config.An acknowledgement naming a digest holds only while the project still holds it, so a project that moves underneath one is reported again.
-
known_drift_digest : str | None
-
known_drift_reason : str | None
-
latest_template_version : int | None
-
project_id : str
-
project_name : str | None
-
project_owner : str
-
status : str
-
variable_update_mode : str
-
variable_update_mode_overridden : bool
ReportStatus
class ReportStatus(*args, **kwds):What the hub says about a project relative to the config.
Variables
- static
BEHIND_LATEST
- static
MATCHES
- static
NO_TASK_DEFINITION
- static
PINNED_BEHIND
- static
TEMPLATE_DIFFERS
- static
UNREADABLE
- static
VARIABLES_DIFFER
SlackEntry
class SlackEntry(headline: str, status_line: str, detail_lines: list[str] = []):One project's part of a Slack message, rendered as its own section block.
VariableChange
class VariableChange(name: str, kind: str, before: Any | None, after: Any | None):One template variable that differs between two sets.
VersionReport
class VersionReport( account: str, config_file: str, git_ref: str | None = None, rows: list[ProjectVersionRow] = [],):Every row gathered for one account.
Methods
drifted
def drifted(self) ‑> list[ProjectVersionRow]:The rows a reader needs to act on.
A pinned-behind row is where the config puts it, so it is reported in the
table but is not counted as drift. Neither is a row whose drift the config
acknowledges, until the project moves off the acknowledged digest.