github
frequenz.repo.config.github ¤
Utilities to work with GitHub.
abort()
to print an error message using GitHub Actions commands and exit.require_env()
to get an environment variable or exit with an error if it is not defined.get_tags()
to get the tags of a repository.get_branches()
to get the branches of a repository.configure_logging()
to configure logging for GitHub Actions.
Classes¤
frequenz.repo.config.github.GitHubActionsFormatter ¤
Bases: Formatter
A formatter for GitHub Actions.
Source code in frequenz/repo/config/github.py
Attributes¤
level_mapping
class-attribute
instance-attribute
¤
level_mapping: dict[int, str] = {
CRITICAL: "error",
ERROR: "error",
WARNING: "warning",
INFO: "notice",
DEBUG: "debug",
}
The mapping from logging levels to GitHub Actions levels.
Functions¤
format ¤
Format the record using GitHub Actions commands.
PARAMETER | DESCRIPTION |
---|---|
record |
The record to format.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The formatted record. |
Source code in frequenz/repo/config/github.py
Functions¤
frequenz.repo.config.github.abort ¤
abort(
message: str,
title: str | None = None,
file: str | None = None,
col: int | None = None,
end_column: int | None = None,
line: int | None = None,
end_line: int | None = None,
use_subprocess: bool = False,
error_code: int = 1,
) -> NoReturn
Print an error message using GitHub Actions commands and exit.
PARAMETER | DESCRIPTION |
---|---|
message |
The message of the error.
TYPE:
|
title |
The title of the error.
TYPE:
|
file |
The file where the error occurred.
TYPE:
|
col |
The column where the error occurred.
TYPE:
|
end_column |
The end column where the error occurred.
TYPE:
|
line |
The line where the error occurred.
TYPE:
|
end_line |
The end line where the error occurred.
TYPE:
|
use_subprocess |
Whether to use subprocess to print the error.
TYPE:
|
error_code |
The error code to exit with.
TYPE:
|
Source code in frequenz/repo/config/github.py
frequenz.repo.config.github.configure_logging ¤
configure_logging(level: int | None = None) -> None
Configure logging for GitHub Actions.
The
GitHubActionsFormatter
is used to format the logs, using GitHub Action
commands.
PARAMETER | DESCRIPTION |
---|---|
level |
The logging level to use. If
TYPE:
|
Source code in frequenz/repo/config/github.py
frequenz.repo.config.github.get_branches ¤
Get the branches of the repository.
This function uses the BRANCHES
environment variable if it is defined. If it
is not defined, it uses the GitHub gh
CLI tool to get them. This means the
tool needs to be properly configured and have at least read access over
repository
.
PARAMETER | DESCRIPTION |
---|---|
repository |
The repository to get the branches of.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[str]
|
The branches of the repository. |
Source code in frequenz/repo/config/github.py
frequenz.repo.config.github.get_repo_version_info ¤
get_repo_version_info() -> RepoVersionInfo
Get the repository version information.
This function uses the GITHUB_REPO
, GIT_REF
, and GIT_SHA
environment
variables to get the repository information. If these variables are not
defined, it raises a ValueError
.
It also uses the BRANCHES
and TAGS
environment variables to get the
branches and tags of the repository. If they are not defined, the GitHub gh
CLI tool is used to get them. This means the tool needs to be properly
configured and have at least read access over repository
.
RETURNS | DESCRIPTION |
---|---|
RepoVersionInfo
|
The repository version information. |
Source code in frequenz/repo/config/github.py
frequenz.repo.config.github.get_tags ¤
Get the tags of the repository.
This function uses the TAGS
environment variable if it is defined. If it is
not defined, it uses the GitHub gh
CLI tool to get them. This means the tool
needs to be properly configured and have at least read access over
repository
.
PARAMETER | DESCRIPTION |
---|---|
repository |
The repository to get the tags of.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[str]
|
The tags of the repository. |
Source code in frequenz/repo/config/github.py
frequenz.repo.config.github.require_env ¤
Get the environment variable.
PARAMETER | DESCRIPTION |
---|---|
name |
The name of the environment variable.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The environment variable. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the environment variable is not defined. |