xenoterracide
xenoterracide

Reputation: 16865

Is there a way to delete a github workflow

So I tried to put a docker-compose.yml file in the .github/workflows directory, of course it tried to pick that up and run it... which didn't work. However now this always shows up as a workflow, is there any way to delete it?

Upvotes: 6

Views: 4600

Answers (5)

Yury Kirienko
Yury Kirienko

Reputation: 2029

To delete a particular workflow on your Actions page, you need to delete all runs which belong to this workflow. Otherwise, it persists even if you have deleted the YAML file that had triggered it.

If you have just a couple of runs in a particular action, it's easier to delete them manually. But if you have a hundred runs, it might be worth running a simple script. For example, the following python script uses GitHub API:

Before you start, you need to install the PyGithub package (like pip install PyGithub) and define three things:

  1. PAT: create a new personal access GitHub token;
  2. your repo name
  3. your action name (even if you got deleted it already, just hover over the action on the actions page):
from github import Github
import requests

token = "ghp_1234567890abcdefghij1234567890123456" # your PAT
repo = "octocat/my_repo"
action = "my_action.yml"

g = Github(token)
headers = {'Accept': 'application/vnd.github.v3',
           'Authorization': f'token {token}'}

for run in g.get_repo(repo).get_workflow(id_or_file_name=action).get_runs():
    response = requests.delete(url=run.url, headers=headers)
    if response.status_code == 204:
        print(f"Run {run.id} got deleted")

After all the runs are deleted, the workflow automatically disappears from the page.

Upvotes: 4

hsingh
hsingh

Reputation: 1

GitHub cli

GitHub Actions/Manage workflow runs/Deleting a workflow run

# GitHub CLI api
# https://cli.github.com/manual/gh_api

gh api \
  --method DELETE \
  -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  /repos/OWNER/REPO/actions/runs/RUN_ID/logs

Upvotes: 0

Phani Rithvij
Phani Rithvij

Reputation: 4507

https://docs.github.com/en/rest/reference/actions#delete-a-workflow-run

To delete programmatically

Example (from the docs)

curl \
  -X DELETE \
  -H "Authorization: token <PERSONAL_ACCESS_TOKEN>"
  -H "Accept: application/vnd.github.v3+json" \
  https://api.github.com/repos/octocat/hello-world/actions/runs/42

Upvotes: 2

HUAN XIE
HUAN XIE

Reputation: 225

Yes, you can delete all the workflow runs in the workflow which you want to delete, then this workflow will disappear.

Upvotes: 2

jidicula
jidicula

Reputation: 3989

Yes, you can delete the results of a run. See the documentation for details.

Upvotes: 1

Related Questions