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: dict[int, str] = {logging.CRITICAL: 'error', logging.ERROR: 'error', logging.WARNING: 'warning', logging.INFO: 'notice', logging.DEBUG: 'debug'}
class-attribute
instance-attribute
¤
The mapping from logging levels to GitHub Actions levels.
Functions¤
format(record)
¤
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(message, title=None, file=None, col=None, end_column=None, line=None, end_line=None, use_subprocess=False, error_code=1)
¤
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(level=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(repository)
¤
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 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(repository)
¤
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(name)
¤
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. |