GitHub Actions |How to remove all Failed Actions | PWSH ⚡ + GitHub API
Tags: powershell, github, automation, git
Published: 2020-10-14 00:02:19

---
title: GitHub Actions |How to remove all Failed Actions  | PWSH ⚡ + GitHub API
published: true
date: 2020-10-13 23:41:37 UTC
tags: powershell,github,automation,git
canonical_url: 
---

![](https://cdn-images-1.medium.com/max/1000/1*0x-T6XNmsyb-i5EwqTwHCg.png)

Hello everyone, thank you very much for accessing this content, if you are here, you also use GitHub Actions and, of course, when you write an action sometimes that action fails, the action history grows and you need to remove it one by one of that history, it’s a boring task and you need to do it. What could facilitate this task? Okay, come on, we can make this task easier with PWSH7.

I wrote some Actions to automate tasks on my raspberry , my raspberry now it’s my [Self Hosted Runner](https://docs.github.com/en/free-pro-team@latest/actions/hosting-your-own-runners), In GitHub Actions you be able to use runners on plataform MacOS,Windows,Linux or Self Hosted in this particular mode, you need to management everything about admin tasks.

Before you need to have some things:

1. Create a token on GitHub for connect on RestAPI (if you won’t provide this token you can’t interact with your GitHub Actions)
2. [PowerShell 7](https://github.com/PowerShell/PowerShell/releases/tag/v7.0.3)
3. [Secrests Managment](https://www.powershellgallery.com/packages/Microsoft.PowerShell.SecretManagement/0.5.3-preview4)(not mandatory but it’s cool to know)

Steps for create a token:

![Click on your Avatar and select Settings](https://cdn-images-1.medium.com/max/1024/1*l9gh4v7pK-HU6x8cfUx0Rw.png)<figcaption>Click on your Avatar and select Settings</figcaption>

![When open you profile ,select Developer Settings.](https://cdn-images-1.medium.com/max/1024/1*cfgfShoVttz5V4iBVxeGGg.png)<figcaption>When open you profile ,select *Developer Settings*.</figcaption>

![Personal access tokens  after click on Generate new token](https://cdn-images-1.medium.com/max/1024/1*-0iaNeN9oZAVR9E4554Xmw.png)<figcaption>Click on <strong>Personal access tokens</strong> after click on <strong>Generate new token</strong></figcaption>

![Flag those options](https://cdn-images-1.medium.com/max/1024/1*Z1BB35Pt0gUg-15AwMGIEQ.png)<figcaption>Flag those options</figcaption>

![And apply these configurations](https://cdn-images-1.medium.com/max/1024/1*a73qcpsmDqIChhb4axeuyA.png)<figcaption>And apply these configurations</figcaption>

Now I show you the code 😃:It’s very simple after you had your personal access token, you need to know wich repository you want to make cleanup and that’s it 😃:

![All workflows](https://cdn-images-1.medium.com/max/1024/1*wwKjogNEyfoOjq5qE52qFA.png)<figcaption>All workflows</figcaption>

![After run script remove jobs with failure status](https://cdn-images-1.medium.com/max/740/1*IWVz2uul9PPJlJTO7EJunw.png)<figcaption>After run script remove jobs with failure status</figcaption>

![cleanup is done](https://cdn-images-1.medium.com/max/1024/1*hHoPe4qrj3yld6WSquBRAQ.png)<figcaption>cleanup is done</figcaption>

PowerShell Script:

{% gist https://gist.github.com/EwertonJordao/5c5a7eed7f25212ad9f6d0d4ccdb6cbc.js %}

That’s it. I really wish you appreciate this content, if you liked that content share with all. See you at next opportunity.