Open dabrahams opened 8 months ago
For download caching to make any sense, you need to somehow have it "closer" to where you need it. So for a public build runner, that gets reset every time and only have access to anything via internet, downloading it from the "cache" or downloading it from the source is about the same thing.
So you need to have a self-hosted action runner where you have a drive/share/folder that survives between builds.
- name: Update git cache
run: |
set -e
mkdir -p $REPO_CACHE/${{ github.repository }}
if [ ! -f "$REPO_CACHE/${{ github.repository }}/HEAD" ]; then
rm -rf $REPO_CACHE/${{ github.repository }}
git -c credential.helper='!f() { sleep 1; echo "username=${{github.repository_owner}}"; echo "password=$GITHUB_TOKEN"; }; f' clone --mirror https://github.com/${{github.repository}} $REPO_CACHE/${{ github.repository }}
fi
pushd $REPO_CACHE/${{ github.repository }}
git -c credential.helper='!f() { sleep 1; echo "username=${{github.repository_owner}}"; echo "password=$GITHUB_TOKEN"; }; f' fetch origin
popd
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Checkout
run: |
set -e
git clone --no-checkout $REPO_CACHE/${{ github.repository }} .
git checkout --progress --force ${{ github.sha }}
For obvious reasons this is a major security issue if you don't trust all jobs running on your runner to not have read access to all other repos implicitly.
I have to check out the same large repository (LLVM) in two different jobs and many matrix configurations in my workflow, and it's nearly always checked out at the same commit. If I could use a cache for that repo, it would speed up CI considerably.
git ls-remote https://github.com/llvm/llvm-project.git -t llvmorg-$LLVM_VERSION | cut -f 1
could be used as a cache key. I may be able to figure out how to get this to work on my own, but it would be awesome if the functionality were built in.Thanks!