Github action cleanup step

I use Github actions with a remote runner. The workflow is very simple:

name: My build workflow

on: [push, pull_request]

env:
  BUILD_TYPE: Release

jobs:
  build:
    runs-on: self-hosted
    steps:
    - uses: actions/checkout@v2

    - name: Update dependencies
      shell: bash     
     working-directory: ${{runner.workspace}}/my-repo
      run: ./update

    - name: Build
      working-directory: ${{runner.workspace}}/my-repo
      shell: bash
      run: ./build

But the problem is that after the build finished the code tree is remaining in the _work folder. In my opinion it doesn’t make any sense because actions/checkout@v2 removes the old code tree before cloning the repo. Besides that the repo can be very big and just takes up the server space. So I’ve added another step to remove the code folder:

- name: Clean up	
      run: rm -rf "${{github.workspace}}" 

But since actions/checkout@v2 adds some postbuild step it fails with error:

Post job cleanup.
Error: No such file or directory

Actually I don’t need this postbuild step, I use actions/checkout@v2 to clone the repo only. So how can I remove the repo folder after build?

You could probably do something like:

git checkout --orphan orphan-branch
git branch -D $normal_branch
rm -rf .git/refs/tags/*
git gc

A cleaner, more portable approach would be to write your own action and use post in it:

I believe that it’s LIFO (but you can check), so if you properly order your action relative to the checkout action, you should be able to have your action wipe things out.

@folibis : Were you able to perform cleanup successfully ?
Could you share details, as to what worked for you ?

Best Regards
Ganesh