Print Functions¶
Output messages to the GitHub Actions console with different severity levels.
API Reference¶
echo(message, use_subprocess=False)¶
Prints specified message to the action workflow console.
example:
>> from github_action_toolkit import echo
>> echo("Hello World")
# Output:
# Hello World
info(message, use_subprocess=False)¶
Prints specified message to the action workflow console. (Same function as echo())
example:
>> from github_action_toolkit import info
>> info("Hello World-1")
# Output:
# Hello World-1
debug(message, use_subprocess=False)¶
Prints colorful debug message to the action workflow console. GitHub Actions Docs: debug
example:
>> from github_action_toolkit import debug
>> debug("Hello World")
# Output:
# ::debug ::Hello World
notice(message, title=None, file=None, col=None, end_column=None, line=None, end_line=None, use_subprocess=False)¶
Prints colorful notice message to the action workflow console. GitHub Actions Docs: notice
example:
>> from github_action_toolkit import notice
>> notice(
"test message",
title="test title",
file="abc.py",
col=1,
end_column=2,
line=4,
end_line=5,
)
# Output:
# ::notice title=test title,file=abc.py,col=1,endColumn=2,line=4,endLine=5::test message=
warning(message, title=None, file=None, col=None, end_column=None, line=None, end_line=None, use_subprocess=False)¶
Prints colorful warning message to the action workflow console. GitHub Actions Docs: warning
example:
>> from github_action_toolkit import warning
>> warning(
"test message",
title="test title",
file="abc.py",
col=1,
end_column=2,
line=4,
end_line=5,
)
# Output:
# ::warning title=test title,file=abc.py,col=1,endColumn=2,line=4,endLine=5::test message
error(message, title=None, file=None, col=None, end_column=None, line=None, end_line=None, use_subprocess=False)¶
Prints colorful error message to the action workflow console. GitHub Actions Docs: error
example:
>> from github_action_toolkit import error
>> error(
"test message",
title="test title",
file="abc.py",
col=1,
end_column=2,
line=4,
end_line=5,
)
# Output:
# ::error title=test title,file=abc.py,col=1,endColumn=2,line=4,endLine=5::test message
add_mask(value, use_subprocess=False)¶
Masking a value prevents a string or variable from being printed in the workflow console. GitHub Actions Docs: add_mask
example:
>> from github_action_toolkit import add_mask
>> add_mask("test value")
# Output:
# ::add-mask ::test value
start_group(title, use_subprocess=False) and end_group(use_subprocess=False)¶
Creates an expandable group in the workflow log. GitHub Actions Docs: group
example:
>> from github_action_toolkit import echo, start_group, end_group, group
>> start_group("My Group Title")
>> echo("Hello World")
>> end_group()
# Output:
# ::group ::My Group Title
# Hello World
# ::endgroup::
# ====================
# Using Group Context Manager
# ====================
>> with group("My Group Title"):
... echo("Hello World")
# Output:
# ::group ::My Group Title
# Hello World
# ::endgroup::
Examples and Best Practices¶
Progress Groups¶
from github_action_toolkit import group, info
stages = ['setup', 'build', 'test', 'deploy']
for stage in stages:
with group(f'Stage: {stage}'):
info(f'Starting {stage}...')
# Do work
info(f'Completed {stage}')
Nested Groups¶
from github_action_toolkit import group, info
with group('Build Process'):
info('Starting build...')
with group('Compile Source'):
info('Compiling main.py...')
info('Compiling utils.py...')
with group('Run Tests'):
info('Running unit tests...')
info('Running integration tests...')
info('Build complete!')
Conditional Groups¶
from github_action_toolkit import group, info, get_user_input_as
verbose = get_user_input_as('verbose', bool, default_value=False)
if verbose:
with group('Detailed Information'):
info('Python version: 3.11')
info('Platform: Linux')
info('Working directory: /home/runner/work')