154

I create a couple workflows in the .github/workflows folder of my repository to experiment with GitHub Actions. I have since learned quite a bit and deleted said "experimental" workflows from my repo. After deleting the "experimental" workflow yaml files and committing the deletions, when I go to the Actions tab of my repository I STILL see the workflows that I have since deleted.

I see no option to delete and start from scratch?! Is this not possible? Is it maybe possible through GitHub API? Hmm.

camille
  • 16,432
  • 18
  • 38
  • 60
skålfyfan
  • 4,931
  • 5
  • 41
  • 59
  • 4
    I made this tool to easily delete workflow runs from bash: https://github.com/jv-k/delete-workflow-runs – jv-k Jun 28 '22 at 15:33
  • 1
    The issue is that that workflow, even if deleted from `~/.github/workflows` **still has runs under it**. GitHub's feature is to preserve the workflow as long as it has some run metadata in it. So you need to delete all the runs under the workflow and it'll disappear from your Worflows tab. – josemrivera Jul 23 '22 at 09:59
  • 1
    you can vote here https://github.com/community/community/discussions/26256 for this feature on UI – pbaranski Oct 27 '22 at 03:08

32 Answers32

124

As of July 7, 2020, you can now delete the results of individual workflow runs. To do this, navigate to your workflow, find the workflow run that you want to delete, and select the "..." menu. In this menu, select "Delete workflow run".

The workflow run and its logs will be removed.

Delete workflow run

Currently, you must do this for each workflow run individually.

edit: As of 2021 Feb it seems that after all workflow runs are deleted the workflow it self disappears. One comment below also seems to confirm this.

Peter Lamberg
  • 8,151
  • 3
  • 55
  • 69
Edward Thomson
  • 74,857
  • 14
  • 158
  • 187
  • 91
    I'm looking forward to that feature. In the meantime, when getting Actions set up, I recommend doing it in another repo so that all the detritus you create experimenting doesn't haunt you. Sadly, for anyone reading this, it's likely too late. – Matt Simerson Sep 14 '19 at 23:12
  • 1
    A feature no one complains about is likely useless:) Actions seem useful, but workflow runs seem weirdly implemented. Wouldn't the normal actions available for a top level user data object like this be "Create, Read, Update, Destroy"? Workflow runs only seem to support read and update (re-run) at this time. Apparently creating them or deleting them only happens automatically and can not be done manually. – Stuart R. Jefferys Nov 16 '19 at 22:45
  • 4
    it is important that it is possible to delete action logs, to prevent spreading of credentials and/or confidential information when a logging error is done in one of the actions/code being tested... – jactor-rises Mar 04 '20 at 09:47
  • 1
    @jactor-rises Indeed, that is a very good point! I will now be very careful about experimenting with my builds in public repos. – MEMark Apr 10 '20 at 16:28
  • 4
    Just did this and it removed the workflow label from the sidebar too. I first disabled the workflow, then deleted all its runs from the UI. Workflow is now gone :) – mattwad Jan 07 '21 at 18:00
  • 2
    but if the workflow is empty, then file remove from repo. There will be no way to remove the workflow. because cannot remove any run in the workflow – Xin Meng Jul 15 '21 at 13:45
  • 1
    This doesn't work for me. I deleted all workflow runs, deleted the workflow yml file, not other tags or branches just main. Still the workflow shows in the UI. – DarVar Oct 07 '22 at 09:42
  • yes, the workflow disappears when we delete all workflow runs associated with that workflow – Karan Tikku Feb 15 '23 at 12:53
79

It doesn't seem that there is currently a way to delete those workflows - this makes no sense - but it appears that once one makes the mistake of creating one they are stuck with it forever. The only solution so far I found is to disable these workflows.

So if I go to the Actions tab (edit the url to match your repo), I can then click on a workflow and disable it via [...] in the right top corner of that tab as in the snapshot below:

enter image description here

To delete all workflow results at once

To delete the records here is the solution I found here with slight modifications from the original:

user=GH_USERNAME repo=REPO_NAME; gh api repos/$user/$repo/actions/runs \
--paginate -q '.workflow_runs[] | select(.head_branch != "master") | "\(.id)"' | \
xargs -n1 -I % gh api repos/$user/$repo/actions/runs/% -X DELETE

Replace GH_USERNAME and REPO_NAME with the desired github username and repo name correspondingly.

This will delete all the old workflows that aren't on the master branch. You can further tweak this to do what you need.

Prerequisites:

  • You will find the latest gh version here.

Notes:

  • You may have to gh auth login if this is your first time using it
  • You may further change the command to gh api --silent if you prefer not to see the verbose output.
  • For the final xargs part of the command chain - the original used -J instead of -I, which is not supported by GNU xargs. -J results in a single command, and -I will execute the command for each records, so it's a bit slower.

Thank you to the OP on the community forum for sharing this in first place.

stason
  • 5,409
  • 4
  • 34
  • 48
  • 5
    you should add a `--silent` modifier to the delete action like so: `gh api --silent repos/$user/$repo/actions/runs/% -X DELETE` – jaecktec Dec 02 '20 at 18:17
  • Thanks, you inspired my solution at https://stackoverflow.com/a/65374631/376587 – Giampaolo Rodolà Dec 19 '20 at 21:28
  • 2
    For starters: you need to install the `jq` package too. And probably the latest `gh` version as the link above. The one coming from apt-get doesn't have the 'api' command, for now. After that, you need to login, using `gh auth login`. One more note: you may have to run this several times because of API limit. – franzbischoff Mar 03 '21 at 21:40
  • Thank you, @franzbischoff and Coco. I updated the instructions. – stason Mar 04 '21 at 21:39
  • No need for jq anymore, and paging has been built in. I updated the answer – Worthy7 Jun 14 '21 at 09:55
  • Thank you for the improvement, @Worthy7 - do you want to edit from which version of `gh` pagination is supported? If it has been out there for awhile, then it's probably ok as it is. – stason Jun 14 '21 at 19:03
  • 1
    I don't really wnat to leave old/unneeded info in the answer, but it looks like it was since March https://github.com/cli/cli/releases/tag/v1.7.0 – Worthy7 Jun 15 '21 at 09:27
  • 1
    Amazing Answer ;) – Omar Hasan Jun 27 '21 at 08:28
  • 1
    Thank you very much, detailed and working instruction to remove all workflow – Zakhar Rodionov Jul 22 '21 at 08:59
  • Does this delete only runs for disabled workflows? – Merlin -they-them- May 11 '22 at 14:53
  • It works. Thank you. I got a warning: xargs: warning: options --max-args and --replace/-I/-i are mutually exclusive, ignoring previous --max-args value – shin Sep 12 '22 at 21:34
  • 1
    The same command in Windows is: `set "user=GH_USERNAME" & set "repo=REPO_NAME" & for /f "usebackq" %a in (\`gh api repos/%user%/%repo%/actions/runs --paginate -q ".workflow_runs[] | """"\(.id)"""""\`) do gh api repos/%user%/%repo%/actions/runs/%a -X DELETE` – Ross Smith II Sep 21 '22 at 15:13
  • You could add `-P` followed by any number (be careful with rate limiting) to the `xargs` command to run the delete query in parallel. I set it to `10` (_e.g._: `-P10`). This makes the script much faster without getting `403 Forbidden` due to rate limiting. – Vincent C. Jan 11 '23 at 06:35
  • The `gh run delete` command is now available, for an easier removal: `gh run list --workflow "experimental" --json databaseId --jq ".[].databaseId" | xargs -n1 gh run delete` – zessx Jul 12 '23 at 08:03
60

Based on the @Giampaolo Rodolà answer (which worked for me), I created this simple shell script that does the job.

Disable the workflow you want to delete (via Github console) before executing this script.

org=<your org>
repo=<your repo>

# Get workflow IDs with status "disabled_manually"
workflow_ids=($(gh api repos/$org/$repo/actions/workflows --paginate | jq '.workflows[] | select(.["state"] | contains("disabled_manually")) | .id'))

for workflow_id in "${workflow_ids[@]}"
do
  echo "Listing runs for the workflow ID $workflow_id"
  run_ids=( $(gh api repos/$org/$repo/actions/workflows/$workflow_id/runs --paginate | jq '.workflow_runs[].id') )
  for run_id in "${run_ids[@]}"
  do
    echo "Deleting Run ID $run_id"
    gh api repos/$org/$repo/actions/runs/$run_id -X DELETE >/dev/null
  done
done

Outcome:

Listing runs for the workflow ID 5261185
Deleting Run ID 507553125
Deleting Run ID 507548002
Listing runs for the workflow ID 5261568
Deleting Run ID 525274011
Deleting Run ID 525264327
Deleting Run ID 525247443

Ensure to have Github client installed and required token permissions in Github.

Petr Hurtak
  • 2,239
  • 1
  • 19
  • 18
Ribeiro
  • 851
  • 6
  • 7
  • 1
    Worked perfectly (after a multiple runs, to get around the batch limit of the API only returning a subset of runs for each workflow). Thank you! – Mitch Ware May 17 '21 at 21:04
  • 3
    Exactly @MitchWare, for these cases, we can do something like `while :; do clear; source script.sh; sleep 10; done`. – Ribeiro May 20 '21 at 11:56
  • 1
    Awesome solution. – backslash-f Jul 28 '21 at 20:49
  • 4
    You can add --paginate to the run_ids line which will save you from having to run it multiple times. From the gh help documentation: ``` **--paginate Make additional HTTP requests to fetch all pages of results** ``` So the updated line in the script would be: **run_ids=( $(gh api repos/$org/$repo/actions/workflows/$workflow_id/runs --paginate | jq '.workflow_runs[].id') )** – Terry Sposato Aug 11 '21 at 13:37
  • 1
    @TerrySposato adding `--paginate` works perfectly, thank you. – mturatti Aug 14 '21 at 08:57
  • 1
    @TerrySposato thank you very much! I've updated the script with your nice suggestion. – Ribeiro Aug 18 '21 at 07:58
  • 1
    Is there a way to run this in parallel? (I'm not sure if GitHub request rate limit makes it worthwhile or not) – Blademaster Oct 25 '21 at 19:22
  • 1
    I had to add --paginate in the first url GET to get the entire list of my actions. Seems like they only return first 30. – Teebu Apr 22 '22 at 05:33
  • Thanks! `gh api repos/$org/$repo/actions/runs/$run_id -X DELETE >/dev/null &;` Send the gh api calls to background else the script would take forever. It took 12 mins to delete 200 runs, and 1-2 minute to delete 250 with background. – fzn Oct 28 '22 at 11:49
  • update: The answer as such didn't work because github outputs as json now so pipe to jq fails. gh has a `--jq` flag which is a drop-in replacement. I also updated to pass shell-check (this is Bash 4.4+ (latest) method. see https://www.shellcheck.net/wiki/SC2207. no space for whole solution, partial: `mapfile -t workflow_ids < <(gh api repos/$org/$repo/actions/workflows --jq '.workflows[] | select(.["state"] | contains("disabled_manually")) | .id')` – Carlos Soriano Feb 22 '23 at 19:51
  • saved me couple of hours !!! thank you – Arjun K R Jun 13 '23 at 03:41
53

Here's a few commands to quickly clean up your workflows.

You'll need the xargs, gh and jq CLI tools.

OWNER=<your user/org name>
REPO=<repo name>

# list workflows
gh api -X GET /repos/$OWNER/$REPO/actions/workflows | jq '.workflows[] | .name,.id'

# copy the ID of the workflow you want to clear and set it
WORKFLOW_ID=<workflow id>

# list runs
gh api -X GET /repos/$OWNER/$REPO/actions/workflows/$WORKFLOW_ID/runs --paginate | jq '.workflow_runs[] | .id'

# delete runs
gh api -X GET /repos/$OWNER/$REPO/actions/workflows/$WORKFLOW_ID/runs --paginate | jq '.workflow_runs[] | .id' | xargs -I{} gh api -X DELETE /repos/$OWNER/$REPO/actions/runs/{} --silent
Matthew Simoneau
  • 6,199
  • 6
  • 35
  • 46
Samuel Müller
  • 1,167
  • 1
  • 10
  • 12
19

I managed to fix this (currently not possible via UI) by using "gh" CLI tool and reading REST API docs.

First, get all your workflows (these are the ones shown in the web UI -> Actions -> left column):

$ gh api repos/$YOUR_USER/$YOUR_REPO/actions/workflows
{
  "total_count": 2,
  "workflows": [
    {
      "id": 3611607,
      "name": "FreeBSD",
      ...
    },
    {
      "id": 4336318,
      "name": "MacOS",
      ...
    }
  ]
}

Use the ID of the workflow you want to delete (say 3611607) to get all of its individual runs:

$ gh api repos/$YOUR_USER/$YOUR_REPO/actions/workflows/3611607/runs
{
  "total_count": 17,
  "workflow_runs": [
    {
      "id": 363876785,
      "name": "FreeBSD",
      ...
    },
    {
      "id": 363876786,
      "name": "FreeBSD",
      ...
    },
    {
      "id": 363876787,
      "name": "FreeBSD",
      ...
    },
}

For each run id (let's say 363876785), delete it with:

$ gh api repos/$YOUR_USER/$YOUR_REPO/actions/runs/363876785 -X DELETE

After this, the undeletable Action in the left column of the web UI should disappear.

Giampaolo Rodolà
  • 12,488
  • 6
  • 68
  • 60
  • 1
    Didn't work for me; already had 0 runs against the action. Also, the individual runs _are_ deletable directly in the web ui, so no need to do it via api calls unless you have a lot to loop through. – jarekwg Dec 20 '20 at 21:25
  • In my case for some reason they were not displayed in the UI – Giampaolo Rodolà Dec 21 '20 at 22:23
  • Thanks, worked for me! The UI reflected no runs since they had been deleted but inspecting the workflow via API showed 2 runs. Deleting those made the stuck workflow disappear – davidstoker Jan 21 '21 at 18:40
18

Delete all runs from a certain workflow

An improved version of @Sheece Gardazi's answer that supports selecting a certain workflow:

export OWNER="my-user"
export REPOSITORY="my-repo"
export WORKFLOW="My Workflow"

gh api -X GET /repos/$OWNER/$REPOSITORY/actions/runs --paginate \
  | jq '.workflow_runs[] | select(.name == '\"$WORKFLOW\"') | .id' \
  | xargs -t -I{} gh api -X DELETE /repos/$OWNER/$REPOSITORY/actions/runs/{}

(The -t option to xargs prints each workflow run deletion request to the terminal.)

It requires GitHub CLI:

brew install gh
gh auth login

and jq:

brew install jq

*Note: don't forget to remove the the workflow file from the main branch after running the script if you want to completely get rid of it.

David Miguel
  • 12,154
  • 3
  • 66
  • 68
  • 5
    why isn't this an accepted answer? this works exaclty as expected – dark_ruby Jan 08 '22 at 21:24
  • This is spot on. It can take a minute or two before the deletions start, so be patient. – Roly Aug 09 '22 at 10:19
  • Option to add `--silent` to the DELETE call to continue execution of the script otherwise it gets stuck on the first one. – Etienne Marais Feb 27 '23 at 07:20
  • Only improvement would be to add `-P 30` before `gh api` in order to send 30 requests in parallel, instead of 1 deletion at a time. – Rishav Aug 18 '23 at 23:55
9

Until GitHub implements a "Delete all workflow runs", you have to rely on the API. With the CLI tools gh and jq installed on your workstation, you can run the following commands to delete all runs of that workflow. Once all runs are removed, it won't show up anymore in the UI.

cd /path/to/your/repo

gh workflow list # Pick-up the workflow ID for which you want to delete all runs
WORKFLOW_ID=<the workflow id> # Change this line!

# List last 10 runs of the workflow you picked to double check the id
gh run list -L 10 -w $WORKFLOW_ID

# Some set up
REPO_INFO=$(gh repo view --json name,owner)
REPO_FULL_NAME="$(echo $REPO_INFO | jq '.owner.login' -r)/$(echo $REPO_INFO | jq '.name' -r)"

# Ready? Let's delete some runs!
gh api -X GET "/repos/$REPO_FULL_NAME/actions/workflows/$WORKFLOW_ID/runs?per_page=100" | jq '.workflow_runs[] | .id' -r | xargs -t -I{} gh api --silent -X DELETE /repos/$REPO_FULL_NAME/actions/runs/{}

The last command will delete the last 100 runs (limit from GitHub API). If you have more, run it multiple times to delete all.

Sébastien Saunier
  • 1,787
  • 2
  • 19
  • 28
7

Delete all jobs belonged to your workflow and your workflow will be gone

enter image description here

P/s: in the case you have thousand of jobs to delete, then using API is a good way to go with: https://docs.github.com/en/rest/reference/actions#workflow-runs

Duc Trung Mai
  • 2,141
  • 1
  • 24
  • 23
4

Following to the Github Actions document: https://docs.github.com/en/actions/managing-workflow-runs/deleting-a-workflow-run

It should be easy to delete a workflow which you don't need any more, like showing in this image enter image description here

If you don't see that delete option but the disable workflow instead, then it's because that workflow still have some workflow runs. You need to delete those workflow runs and then the delete option will appears :)

enter image description here

ThaiPD
  • 3,503
  • 3
  • 30
  • 48
  • yup, that worked for me although after deleting all the runs the workflow disappeared as well. I guess it's because that workflow no longer existed in the repo. – matzar Nov 28 '22 at 13:34
3

And a PowerShell implementation (thanks to the other respondents), which also requires the gh cli.

$user = "your user"
$repo = "repo"

(gh api repos/$user/$repo/actions/runs | ConvertFrom-Json).workflow_runs |
 %{ $_.id } |
 %{ gh api repos/$user/$repo/actions/runs/$_ -X DELETE }

Re-run the "one-liner" until you have no more; it currently pages to 30 results.

msanford
  • 11,803
  • 11
  • 66
  • 93
2

I had 600+ actions that I wanted deleted so there were multiple pages. I had to run the command in for loop:

# install following packages 
sudo snap install jq gh
# To authenticate github cli
gh auth login

# for reference path to your code repository: https://github.com/$OWNER/$REPOSITORY
export OWNER=<OWNER_NAME/ORGANIZATIONS_NAME>
export REPOSITORY=<REPOSITORY_NAME>

# repeat command 30 times, if there are 30 pages of workflow history 
for i in {1..30}; do gh api -X GET /repos/$OWNER/$REPOSITORY/actions/runs | jq '.workflow_runs[] | .id' | xargs -I{} gh api -X DELETE /repos/$OWNER/$REPOSITORY/actions/runs/{}; done
Sheece Gardazi
  • 480
  • 6
  • 14
2

I wasn't able to delete the workflow inspite of all the answers in this post.. What worked for me was that I first authenticated myself using "gh auth login" and the used the below command to get the details of the workflow that you want delete. If you do not know the workflow id, then just run "gh api repos/$org/$repo/actions/workflows/" to see all the workflows. Once you run this, you will know the branch where you need to delete the workflow from. In our case, the work flow existed in the "develop" branch. You can see this in the "html_url". Once I deleted the workflow file from the develop branch, the workflow vanished from everywhere. Also, when you run the "gh api repos/$org/$repo/actions/workflows/$workflow_id", you will notice that the state will be changed to "deleted".

$> gh api repos/$org/$repo/actions/workflows/$workflow_id

{
  "id": 6,
  "node_id": "blah",
  "name": "Run Unit Tests",
  "path": ".github/workflows/unittests.yml",
  "state": "active",
  "created_at": "2021-05-15T00:25:19.000-07:00",
  "updated_at": "2022-03-10T13:02:43.000-08:00",
  "url": "blah",
  "html_url": "https://company-name/workspace/project/blob/develop/.github/workflows/unittests.yml",
  "badge_url": "blah"
}
sgowd
  • 946
  • 3
  • 10
  • 27
2

I created this command line tool to conveniently select multiple entries and delete them together from a navigable list:

https://github.com/jv-k/delete-gh-workflow-runs

jv-k
  • 618
  • 5
  • 20
2

I made some minor adjustments to @david-miguel's answer which offloads the filtering to github's api instead of doing it locally.

#!/bin/sh

OWNER="user-name|org-name"
REPOSITORY="repository-name"
WORKFLOW="workflow-human-friendly-name"

gh run list --repo "$OWNER/$REPOSITORY" -w "$WORKFLOW" --json databaseId \
    | jq '.[].databaseId' \
    | xargs -I{} gh api -X DELETE /repos/$OWNER/$REPOSITORY/actions/runs/{}
SidewaysGravity
  • 562
  • 5
  • 14
  • I haven't tried this with a large workflow so it's possible his answer which has pagination might work better. I found it took a long time to run because it was iterating through all the runs from other workflows and skipping them. My update only iterates through the specified workflow. – SidewaysGravity Jul 26 '22 at 00:18
  • This is indeed faster in most cases, however, when I ran it, I found that only successful workflows were deleted, while the other script above was able to remove all workflows of the name. – Eric Chen Aug 03 '22 at 05:21
1

For anyone wondering, deleting the workflow.yml files within .github/workflows works BUT you need to make sure it is deleted in all branches. If master/main still has the workflow files then GitHub will hold onto them.

  • Surprised this is downvoted so much given its an extension to the top voted answer. You can delete all runs and the workflow will disappear but that's not very feasible with 100+ runs. Its easier just to go to each branch and delete the workflow.yaml file. Ewerton's solution also works as long as you do this for all branches in the repository. – Error - Syntactical Remorse Apr 27 '21 at 12:27
1

It should be automatically be removed once you remove all related workflow runs.

1

Deleting the workflows runs via the CLI was only part of the solution in my case. GitHub still refused to show any workflows I tried to add again afterwards.

I solved it by using the "New workflow" button in GH and to create a workflow from template. I pasted the content of my original YML file and renamed the file so that everything looked like before. Lastly, I committed via web - and GitHub showed again my workflow.

el_sim
  • 11
  • 1
1

If you want to delete multiple workflow runs, you should use the GitHub Action API to get the run ids you want to delete, then send DELETE request with a header containing personal access token to delete the workflow run.
Try this python script to delete all workflow runs.
https://github.com/wh201906/garage/blob/master/Python/DeleteGithubAction/delete.py
It uses grequests to make multi requests at once, and this script doesn't require gh and jq.

wh201906
  • 91
  • 1
  • 1
  • 7
  • 1
    A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](//meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it is there, then quote the most relevant part of the page you are linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](/help/deleted-answers) – Luca Kiebel Mar 03 '22 at 09:35
  • 1
    @LukaKiebel Ok. I will add more information there. – wh201906 Mar 03 '22 at 10:09
1

Here is another option to delete all logs from a Github actions workflow automatically, using Ritchie CLI.

All you need to do is:

  • run rit github delete workflow-logs
  • inform your github username and token
  • inform the repo owner and name
  • select the repo workflow to clean

An example can be seen here. Note that you need to import this repository using the Ritchie CLI tool for the command to work.

GuiFalourd
  • 15,523
  • 8
  • 44
  • 71
1
  1. Install the Ritchie CLI: https://docs.ritchiecli.io/

  2. Run rit add repo

? Select your provider: Github
? Repository name: formulas-github
? Repository URL: https://github.com/GuillaumeFalourd/formulas-github
? Is a private repository? no
? Select a tag version: {latest}
? Set the priority: 1
  1. Run rit set formula-runner
? Select a default formula run type: docker
The default formula runner has been successfully configured!
  1. Start Docker Desktop

  2. Go to https://github.com/settings/tokens, add generate a GitHub Personal Access Token (use the "workflow" scope)

  3. Run rit github delete workflow-logs

  4. Enter your GitHub username, GitHub token, GitHub owner, GitHub repository name and select the workflow for which you want the runs to be deleted

  5. Revoke your PAT

0

For the people who deleted the workflow and can't delete the workflow run (404) ?

After finding this thread, i still did spent quite some time to make my workflows run fade away...

The answer provided by @ribeiro is correct, however for people that have DELETED their workflows, they won't be able to delete the runs, it will resolve into a 404!

How to delete workflows run that doesn't have workflows anymore I've tried many things, in the end, only this worked for me:

  1. For each workflows you deleted, create the yml file with the same name that the previous one(filename.yml and the name property in the workflow must be the same as the previous one). This way github will see them as 'existing'.
  2. Create a .sh file and input the following (i will use the answer provided by Ribeiro, however, i will remove the state filter because i wish to delete them all)
OWNER="aOwner"
REPO="aRepo"

workflow_ids=($(gh api repos/$OWNER/$REPO/actions/workflows | jq '.workflows[] | .id'))

for workflow_id in "${workflow_ids[@]}"
do
 echo "Listing runs for the workflow ID $workflow_id"
 run_ids=( $(gh api repos/$OWNER/$REPO/actions/workflows/$workflow_id/runs --paginate | jq '.workflow_runs[].id') )
 for run_id in "${run_ids[@]}"
 do
   echo "Deleting Run ID $run_id"
   gh api repos/$OWNER/$REPO/actions/runs/$run_id -X DELETE >/dev/null
 done
done
  1. Run the sh file. You should see workflows run deleted (it does take some times tho)
DarioRega
  • 992
  • 4
  • 13
0

Update 1/3/2023:

I found something new, if I add test.yml back, the history will be back.

To "truly" delete the workflow history, please refer to other answers.


As of Dec 31, 2022, assume you have a workflow .github/workflows/test.yml.

Once you delete this workflow file and merge into main branch, the workflow on the side menu plus all workflow run history will be gone.

You can verify by manually go to the old workflow link https://github.com/[username]/[repo]/actions/workflows/test.yml

enter image description here

This is the current result.

Hongbo Miao
  • 45,290
  • 60
  • 174
  • 267
0

Here is an answer that just uses the GitHub CLI (you need to install and authenticate re: https://github.com/cli/cli#installation) and awk:

OWNER="repoOwner"
REPO="repoName"

gh run list --repo <[HOST/]OWNER/REPO> -workflow <string> | \
  awk -F '\t' '{ if ($2 == "failure") { print $7 } }' | \
  while read id; do gh api repos/$OWNER/$REPO/runs/$id -X DELETE; done
Steven
  • 691
  • 3
  • 10
  • 26
0
  1. Remove the workflow file from the default branch.

  2. Delete the workflow runs:

owner=exampleowner
repo=examplerepo
workflow=exampleworkflow.yml
gh api repos/"$owner"/"$repo"/actions/workflows/"$workflow"/runs --paginate -q .workflow_runs[].id | while read -r id; do
    echo "$id"
    gh api -X DELETE repos/"$owner"/"$repo"/actions/runs/"$id"
done
Paul Draper
  • 78,542
  • 46
  • 206
  • 285
0

I had some issues where I deleted the workflow .yml file before deleting the workflow runs which left workflows with no runs still dangling.

I was able to remove these by re-adding a workflow .yml file with the same name in one commit and following up with delete in another commit

0

If you are looking for a shell script to delete all the workflow_runs histories from all the repositories in org/user, you can use the below script

org=<your-org/user-name>
repos=($(gh repo list $org --json name -q '.[].name'))

for repo in "${repos[@]}"
do
  echo "Removing runs for the repo => $repo"
  $(gh api repos/$org/$repo/actions/runs --paginate | jq 
  '.workflow_runs[] | .id' | xargs -t -I{} gh api -X DELETE 
  /repos/$org/$repo/actions/runs/{})
  echo "Done removing for repo => $repo"
  echo "-------------------------------------"
done
0

gh CLI 2.27.0 (Apr. 2023) now include the command gh run delete

# Delete a specific run
$ gh run delete 12345

See PR 7254.

For now, it only deletes one run and not all runs for a given workflow, as mentioned in #6449.
So you still need gh run list as in Steven's answer.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
-1

I did find a way of doing this. You can go to .github/workflows or wherever your workflow is set and then commit deleting of the file(workflow file) which will finally delete it.

-2

Update your local branch from to sync with master , then delete the github/workflows. Commit and push your changes . Wokflow should be deleted in master

Limbo
  • 3
  • 2
-2

Your workflows are *.yml files saved in your repo in the folder /.github/workflows/

Just delete them!

Ewerton
  • 4,046
  • 4
  • 30
  • 56
  • 2
    Not sure why this got downvoted, it does actually work if you delete the workflows and commit your repository. – GideonleGrange Oct 06 '20 at 11:01
  • 5
    @GideonleGrange I'm not sure what you mean. I deleted a workflow YAML, committed, and pushed, but it's still there in the Actions tab. – Dominick Pastore Oct 28 '20 at 03:00
  • @DominickPastore - the change (removal) has to be on master – slajma Dec 18 '20 at 11:18
  • 1
    The problem with this solution is that OP was asking about deleting workflow runs not the action itself. Removing the file will delete the action but old workflows will stil stay and need to be deleted by hand. But this was exactly what I've needed, to delete the action so it don't trigger again. I've found the path in workflow and searched how to delete the action. – jcubic Jan 21 '21 at 21:50
-4

I tried deleting yml file from this location .github/workflows/ and it worked like a charm.

KNS
  • 51
  • 9
-5

you can delete the file from the Code tab in github as it was added as a normal commit

enter image description here

click on the file and then click delete icon:

enter image description here

Jan Feyen
  • 535
  • 3
  • 13
  • 3
    That's already mentioned in the question and this does not delete runs for that workflow: After deleting the "experimental" workflow yaml files and committing the deletions, when I go to the Actions tab of my repository I STILL see the workflows that I have since deleted. – riezebosch Feb 14 '20 at 14:39
  • yes, it won't remove the workflow label. even if we reset the branch. – Burhan Mubarok Feb 23 '20 at 09:44
  • This works for me as well. This is starting to seem like a bug that might have been fixed in github since the time the question was originally posted. I deleted workflow runs before trying this solution so I don't know if it would do that automatically, but if not, try manually deleting all previous workflow runs and following this poster's suggestion (deleting the yaml workflow descriptor file itself from `.github/workflows`) – mouselabs Aug 01 '20 at 03:25