Action Outputs¶
Set outputs and manage PATH for subsequent workflow steps.
API Reference¶
set_output(name, value)¶
Sets a step’s output parameter by writing to GITHUB_OUTPUT environment file. Note that the step will need an id to be defined to later retrieve the output value.
GitHub Actions Docs: set_output
example:
>> from github_action_toolkit import set_output
>> set_output("my_output", "test value")
add_path(path)¶
Prepends a directory to the system PATH for all subsequent actions in the current job. The newly added path is available in the current action and all subsequent actions.
example:
>> from github_action_toolkit import add_path
>> from pathlib import Path
>> # Add using string path
>> add_path("/usr/local/bin")
>> # Add using pathlib.Path
>> add_path(Path("/opt/custom-tools/bin"))
Note: The path must be an absolute path. Relative paths will raise a ValueError.
Examples and Best Practices¶
Structured JSON Output¶
import json
from github_action_toolkit import set_output
results = {
'status': 'success',
'tests_run': 42,
'tests_passed': 40,
'tests_failed': 2,
}
# Set as JSON string
set_output('results', json.dumps(results))
# Access in workflow:
# ${{ fromJSON(steps.test.outputs.results).status }}
File Path Outputs¶
from pathlib import Path
from github_action_toolkit import set_output
# Always use absolute paths for outputs
report_path = Path('reports/coverage.html').resolve()
set_output('report-path', str(report_path))