简体   繁体   English

有没有办法删除 github 工作流

[英]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.所以我尝试在.github/workflows目录中放置一个docker-compose.yml文件,当然它试图将其拾取并运行它......但没有成功。 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.否则即使您删除了已触发它的 YAML 文件,它仍然存在。

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:例如,以下python脚本使用 GitHub API:

Before you start, you need to define three things:在开始之前,您需要定义三件事:

  1. PAT : create a new personal access GitHub token; PAT :创建一个新的个人访问 GitHub 令牌;
  2. your repo name你的回购名称
  3. your action name (even you got deleted it already, just hover over the action on the actions page):您的操作名称(即使您已经将其删除,只需 hover 覆盖操作页面上的操作):
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.不要忘记预先运行pip install PyGithub

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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