build_context.py 893 B

1234567891011121314151617181920212223242526272829
  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. """Build context providing a partial facade to git utilities and buildkite utilities."""
  10. import os
  11. from materialize import buildkite, git
  12. def is_on_main_branch() -> bool:
  13. return get_branch_name() == "main"
  14. def get_branch_name() -> str | None:
  15. if buildkite.is_in_buildkite():
  16. return os.getenv("BUILDKITE_BRANCH")
  17. else:
  18. return git.get_branch_name()
  19. def is_on_release_version() -> bool:
  20. # this is known to work both locally and on Buildkite
  21. return git.is_on_release_version()