'Delete a workflow from GitHub Actions

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.



Solution 1:[1]

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.

Solution 2:[2]

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.

Solution 3:[3]

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

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

Depending on how many runs you have you'll have to execute the delete step multiple times because the GH API endpoints are paginated.

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 | jq '.workflow_runs[] | .id'

# delete runs (you'll have to run this multiple times if there's many because of pagination)
gh api -X GET /repos/$OWNER/$REPO/actions/workflows/$WORKFLOW_ID/runs | jq '.workflow_runs[] | .id' | xargs -I{} gh api -X DELETE /repos/$OWNER/$REPO/actions/runs/{}

Solution 4:[4]

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 | 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.

Solution 5:[5]

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.

Solution 6:[6]

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.

Solution 7:[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

Solution 8:[8]

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 -I{} gh api -X DELETE /repos/$OWNER/$REPOSITORY/actions/runs/{}

It requires GitHub CLI:

brew install gh
gh auth login

and jq:

brew install jq

Solution 9:[9]

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.

Solution 10:[10]

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

Solution 11:[11]

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"
}

Solution 12:[12]

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.

Solution 13:[13]

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

Solution 14:[14]

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.

Solution 15:[15]

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

Solution 16:[16]

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.

Solution 17:[17]

  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

Solution 18:[18]

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

Solution 19:[19]

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.

Solution 20:[20]

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.