checkout: Newly added sparse checkout functionality is not cleaning up after itself

Thanks @dscho for contributing #1369 . We have started using it and noticed the following issue

repo-a / .github/workflows/workflow-a.yml

jobs:
  job-1:
    runs-on: internal-runner

- uses: actions/checkout@v3
  with:
    sparse-checkout: |
      .github
      src

running just the above works as expected. But consider another workflow in the same repo

repo-a / .github/workflows/workflow-b.yml

jobs:
  job-12:
    runs-on: internal-runner

- uses: actions/checkout@v3
- run: ls ./not-src

When running workflow-a, then workflow workflow-b, workflow-b will not find any files in ./not-src.

This is because workflow workflow-b runs in the same _work directory as workflow-a. On the first run of workflow-a, we have polluted the repo in a way this action doesn’t know about (and thus can’t clean up).

Notice that, even in workflow-b:

git config --list will show core.sparseCheckout true git sparse-checkout list will still include the listed paths and a simple ls will only show the sparse directories for workflow-a

It seems that - similar to the auth cleanup (and other pre-run steps) this action does - we need to disable sparse checkout in the pre steps of this action

Note: this is likely only an issue for self-hosted runners which dont get the same cleaning/re-init process github-hosted runners get

Similar-ish issue to recently reported https://github.com/actions/checkout/commit/47fbe2df0ad0e27efb67a70beac3555f192b062f (for submodules, instead of sparse checkout). @megamanics

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 5
  • Comments: 17 (5 by maintainers)

Commits related to this issue

Most upvoted comments

We are looking to use such a workaround in the interim, but it seems this is something that should be fixed here within actions/checkout, no?

this is likely only an issue for self-hosted runners

Indeed.

The working directory’s path typically contains the workflow name, e.g. D:\a\_work\repo-a\repo-a, but not the workflow name.

A solid work-around would be to scorch the worktree (if it exists), right before the actions/checkout step.

A more surgical work-around would be to use a shell script like this:

- shell: bash
  run: |
    if test true = "$(git config --type bool core.sparsecheckout)"
    then
      rm "$(git rev-parse --git-path info/sparse-checkout)" &&
      git sparse-checkout disable
    fi

git config core.sparseCheckout false

This is the current way to fix this issue since newer versions of git require GitHub Authentication, and I’m not usually logged in to my GitHub account on my production machines. (hello world 🙄) It would really be nice if this could be fixed.

If I add another step in the action where I run git sparse-checkout disable then it works.