This Delete-WorkflowRuns
function, now available in multiple programming languages (PowerShell, Python, JavaScript, and Bash), is used to automate the deletion of GitHub Actions workflow runs in a specified repository. It interacts with GitHub's REST API using the GitHub CLI (gh
) to fetch and delete workflow runs by their IDs.
-
Parameters:
- username: The GitHub username or organization name.
- reponame: The name of the repository from which to delete workflow runs.
-
Logic:
- The function first checks if both
username
andreponame
parameters are provided. If either is missing, it outputs a usage message and exits. - It then uses the
gh
command-line tool to fetch a list of workflow runs for the specified repository via the GitHub API. - If workflow runs are found, it iterates over each run ID and sends a DELETE request to remove the corresponding workflow run.
- If no workflow runs are found, it outputs a message indicating there are no runs to delete.
- After processing, the function outputs a message confirming the deletion of all workflow runs.
- The function first checks if both
This function is useful for GitHub repository maintainers or administrators who want to:
- Clean up old or unused workflow runs.
- Automate the deletion process for multiple repositories.
- Reduce clutter and improve repository management by managing workflow runs programmatically.
- GitHub CLI (
gh
): This tool is required for the function to work. The CLI provides an interface to interact with GitHub APIs. - Permissions: The user executing the script must have appropriate permissions (e.g., admin or maintain rights) to delete workflow runs in the repository.
- PowerShell: The original script, ideal for Windows environments or platforms supporting PowerShell.
- Python: Suitable for cross-platform automation, using the
subprocess
module to execute GitHub CLI commands. - JavaScript (Node.js): A common choice for web developers who may want to integrate this script with other Node.js automation tools.
- Bash: Best for Unix-based systems, such as Linux and macOS, where Bash scripting is widely used for automation tasks.
Each version of the function behaves similarly and serves the same purpose, with syntax adapted to the corresponding language.