Member-only story
Clean-up repository on GitHub self-hosted Runner
Recently I came across a scenario where out-of-the-box GitHub checkout action failed with below error related to submodules
Error:
No url found for submodule path ‘xxx’ in .gitmodules
The process ‘/usr/bin/git’ failed with exit code 128
Root cause: I removed couple of npm packages from package.json file and ran npm audit fix which updated the dependencies and submodules for my api. However the self-hosted github runner cached the submodules in .git folder and since my package.json file got updated with latest package versions, the submodules were kind of orphan lying in the github runner cache.
Solution: I cleaned up the runner cache by adding below step before the checkout
steps:
- name: 'Cleanup build folder'
run: |
ls -la ./
rm -rf ./* || true
rm -rf ./.??* || true
ls -la ./
- uses: actions/checkout@v2
The trick is to delete all .??*
files as well, since rm -rf ./*
won't remove files that start with dot, which means 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.