workflow example

This commit is contained in:
2026-03-04 13:49:14 -06:00
parent 9414ee34e2
commit 4df156f210
9 changed files with 865 additions and 112 deletions

52
actions/flaky_fail.py Normal file
View File

@@ -0,0 +1,52 @@
#!/usr/bin/env python3
"""
Flaky Fail Action - Python Example Pack
A Python action that randomly fails with a configurable probability.
Useful for testing error handling, retry logic, and workflow failure paths.
Actions receive parameters as JSON on stdin and write results to stdout.
"""
import json
import random
import sys
def main():
# Read parameters from stdin (JSON format)
params = json.loads(sys.stdin.readline())
failure_probability = float(params.get("failure_probability", 0.1))
# Clamp to valid range
failure_probability = max(0.0, min(1.0, failure_probability))
roll = random.random()
failed = roll < failure_probability
if failed:
print(
json.dumps(
{
"error": "Random failure triggered",
"failure_probability": failure_probability,
"roll": round(roll, 6),
}
),
file=sys.stderr,
)
sys.exit(1)
print(
json.dumps(
{
"message": "Success! Did not fail this time.",
"failure_probability": failure_probability,
"roll": round(roll, 6),
}
)
)
if __name__ == "__main__":
main()