确保只有一次触发github操作中的工作流程

发布于 2025-01-21 07:08:10 字数 444 浏览 3 评论 0原文

我有更改特定文件时触发的工作流程。是否有可能仅在更改文件时才触发此工作流程?

用例是:

  • 从模板存储库创建一个存储库
  • 来初始化readme和存储库中的其他内容,一旦提交该文件,就可以在JSON配置文件中设置某些变量
  • ,工作流程运行,将从模板中创建readme。等等。

我试图让工作流提交并推动更改的文件之前删除自身。那是行不通的:致命:不在git目录致命:不安全的存储库('/github/workspace'由其他人拥有)

可能有效的是在工作流程结束时将初始化之类的主题添加到回购中,并在工作流程开始时检查该主题的存在。但是,这感觉就像是一个黑客,因为我正在滥用主题,因为他们可能不打算做。

因此,我的问题仍然存在:有没有一个很好的方法可以只运行一次工作流程?

I have workflow that is triggered when a specific file is changed. Is it possible to ensure that this workflow is only triggered the first time that file is changed?

The use case is:

  • a repository is created from a template repository
  • to initialize the README and other things in the repo, some variables can be set in a JSON config file
  • once that file is committed, the workflow runs, creates the README from a template etc.

I have tried to do let the workflow delete itself before it commits and pushes the changed files. That doesn't work: fatal: not in a git directory and fatal: unsafe repository ('/github/workspace' is owned by someone else).

What might work is adding a topic like initialized to the repo at the end of the workflow and check for the presence of this topic at the beginning of the workflow. However, this is feels like a hack in that I'm abusing topics for something they're probably not meant to do.

So my question remains: is there a good way to only run the workflow once?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

微暖i 2025-01-28 07:08:10

在评论的帮助下, Frennky 我设法通过使用 github cli 工作流。

这是工作流程末尾的步骤:

- name: Disable this workflow
  shell: bash
  run: |
    gh workflow disable -R $GITHUB_REPOSITORY "${{ github.workflow }}"
  env:
    GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

With the help of the comment by frennky I managed to do solve this by using the GitHub CLI to disable the workflow.

Here is the step at the end of the workflow that does this:

- name: Disable this workflow
  shell: bash
  run: |
    gh workflow disable -R $GITHUB_REPOSITORY "${{ github.workflow }}"
  env:
    GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文