简体   繁体   中英

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?

是的,您可以删除要删除的工作流中运行的所有工作流,然后该工作流将消失。

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 been 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 of runs, it might worth running a simple script. For example, the following python script uses GitHub API:

Before you start, you need to define three things:

  1. PAT : create a new personal access GitHub token;
  2. your repo name
  3. your action name (even 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_name=action).get_runs():
    response = requests.delete(url=run.url, headers=headers)
    if response.status_code == 204:
        print(f"Run {run.id} got deleted")

Don't forget to run pip install PyGithub upfront.

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM