【问题标题】:How to actually clean up the repository on self-hosted runner after GitHub Actions completes?GitHub Actions 完成后,如何真正清理自托管运行器上的存储库?
【发布时间】:2022-01-25 17:38:28
【问题描述】:

在 GitHub 操作的工作流程结束时,“隐藏”“发布”作业似乎正在运行,我似乎无法弄清楚如何忽略或覆盖它。例如,actions/checkout@v2 操作完成后似乎会运行以下内容:

Post job cleanup.
/usr/bin/git version
git version 2.25.1
/usr/bin/git config --local --name-only --get-regexp core\.sshCommand
/usr/bin/git submodule foreach --recursive git config --local --name-only --get-regexp 'core\.sshCommand' && git config --local --unset-all 'core.sshCommand' || :
/usr/bin/git config --local --name-only --get-regexp http\.https\:\/\/github\.com\/\.extraheader
http.https://github.com/.extraheader
/usr/bin/git config --local --unset-all http.https://github.com/.extraheader
/usr/bin/git submodule foreach --recursive git config --local --name-only --get-regexp 'http\.https\:\/\/github\.com\/\.extraheader' && git config --local --unset-all 'http.https://github.com/.extraheader' || :

但是,我只想简单地从我的自托管运行器中删除整个存储库。目录中只是一个简单的rm -rf。

我试图将其作为一个步骤添加到我的 .yml 文件中,但这似乎破坏了在我的整个工作流程完成后运行的 actions/checkout@v2 步骤。

如何在工作流完成后完全清理自托管运行的存储库?

【问题讨论】:

  • 查看结帐操作的来源,我看不到覆盖发布作业的方法,但是如果您真的需要这个,那么您可以分叉该操作并删除发布作业或进行会跳过它的参数。

标签: github github-actions


【解决方案1】:

我能够在actions/checkout@v2 之前使用以下方法删除整个存储库:

   steps:

    - name: 'Cleanup build folder'
      run: |
        ls -la ./
        rm -rf ./* || true
        rm -rf ./.??* || true
        ls -la ./

    - uses: actions/checkout@v2

我在之前和之后添加了ls -la ./,所以如果一切都真的消失了,我可以仔细检查操作日志。

诀窍是同时删除所有.??* 文件,因为rm -rf ./* 不会删除以点开头的文件,这意味着.git 文件夹不会被删除。

通过运行rm -rf ./.??*,我们删除了所有以点为首字符的隐藏文件,包括.git 文件夹,然后actions/checkout@v2 将正确克隆存储库,就像在 github 运行器上运行时一样。

-H

【讨论】:

    猜你喜欢
    • 2020-09-14
    • 2020-07-22
    • 2021-10-17
    • 2021-10-21
    • 2021-11-02
    • 2012-12-10
    • 1970-01-01
    • 2022-07-14
    • 2015-06-15
    相关资源
    最近更新 更多