misc.python.materialize.build_context

Build context providing a partial facade to git utilities and buildkite utilities.

 1# Copyright Materialize, Inc. and contributors. All rights reserved.
 2#
 3# Use of this software is governed by the Business Source License
 4# included in the LICENSE file at the root of this repository.
 5#
 6# As of the Change Date specified in that file, in accordance with
 7# the Business Source License, use of this software will be governed
 8# by the Apache License, Version 2.0.
 9
10"""Build context providing a partial facade to git utilities and buildkite utilities."""
11import os
12
13from materialize import buildkite, git
14
15
16def is_on_main_branch() -> bool:
17    return get_branch_name() == "main"
18
19
20def get_branch_name() -> str | None:
21    if buildkite.is_in_buildkite():
22        return os.getenv("BUILDKITE_BRANCH")
23    else:
24        return git.get_branch_name()
25
26
27def is_on_release_version() -> bool:
28    # this is known to work both locally and on Buildkite
29    return git.is_on_release_version()
def is_on_main_branch() -> bool:
17def is_on_main_branch() -> bool:
18    return get_branch_name() == "main"
def get_branch_name() -> str | None:
21def get_branch_name() -> str | None:
22    if buildkite.is_in_buildkite():
23        return os.getenv("BUILDKITE_BRANCH")
24    else:
25        return git.get_branch_name()
def is_on_release_version() -> bool:
28def is_on_release_version() -> bool:
29    # this is known to work both locally and on Buildkite
30    return git.is_on_release_version()