Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to actually clean up the repository on self-hosted runner after GitHub Actions completes?

At the end of my workflow in GitHub actions, a "hidden" "post" job seems to run, and I can't seem to figure out how to ignore or overwrite it. For example, the actions/checkout@v2 action seems to run the following when it's complete:

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

However, I just want to simply remove the entire repository from my self-hosted runner. Just a simple rm -rf in the directory.

I tried to just add this as a step in my .yml file, but that seems to break the actions/checkout@v2 step that runs after my entire workflow is finished.

How can I clean up the repository entirely on the self-hosted running after the workflow is complete?

like image 335
LewlSauce Avatar asked Dec 03 '25 15:12

LewlSauce


1 Answers

I was able to remove the entire repository before actions/checkout@v2 using this:

   steps:

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

    - uses: actions/checkout@v2

I've added the ls -la ./ before and after, so I could double-check in the action log if everything was really gone.

The trick is to delete all .??* files as well, since rm -rf ./* won't remove files that start with dot, which meas the .git folder won't be deleted.

By running rm -rf ./.??* we remove all hidden files that have a dot as first character, including the .git folder, and then actions/checkout@v2 will clone the repository properly, just like when running on github runners.

-H

like image 75
Roberto Hradec Avatar answered Dec 06 '25 10:12

Roberto Hradec