checkout icon indicating copy to clipboard operation
checkout copied to clipboard

[bug] Setting clean to false still removes contents

Open SReject opened this issue 2 years ago • 4 comments

Context

I'm currently attempting a duel repo setup where one builds nightlies for the other.

I checkout the nightly-builder repo into ./nightly I checkout the main repo into './' with the clean option set to false

Expected behavior:

./nightly directory to exist after checking out main repo

Current Behavior:

./nightly directory is deleted

Relevant workflow.yml parts

jobs:

  getInfo:
    name: Get build Info
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.getinfo.outputs.version }}
      patchnotes: ${{ steps.getinfo.outputs.patchnotes }}
    steps:
      - name: Checkout crowbartools/firebot-nightly
        uses: actions/checkout@v3
        with:
          path: './nightly/'

      - name: Checkout crowbartools/firebot
        uses: actions/checkout@v3
        with:
          clean: false
          fetch-depth: 0
          repository: 'crowbartools/firebot'
          ref: 'v5'
          path: '.'

      - name: Get Firebot info
        id: getinfo
        # This errors because /nightly directory has been deleted
        run: node ./nightly/scripts/get-info.js $GITHUB_OUTPUT

SReject avatar Mar 06 '23 16:03 SReject

Please check that the check-out directory contains the .git directory. Please check whether the output log has. "To create a local Git repository instead, add Git 2.18 or higher to the PATH"

zh3305 avatar Mar 11 '23 06:03 zh3305

I have a similar situation where I restore artifacts from a cache to the artifacts subdirectory and afterwards run the checkout action with clean: false. This causes the artifacts subdirectory to disappear.

ermshiperete avatar Jun 03 '24 08:06 ermshiperete

A simple repro would be:

name: "Checkout bug #1201"
on:
  workflow_dispatch:
jobs:
  test:
    runs-on: ubuntu-latest

    steps:
    - name: Restore artifacts
      run: |
        mkdir artifacts/
        echo "Hello world" > artifacts/hello

    - name: Checkout
      uses: actions/checkout@v4
      with:
        fetch-depth: 0
        clean: false

    - name: Verify
      run: |
        ls -al
        ls -al artifacts/

ermshiperete avatar Jun 03 '24 08:06 ermshiperete

The explanation given in PR #561 still holds:

https://github.com/actions/checkout/blob/6d193bf28034eafb982f37bd894289fe649468fc/src/git-directory-helper.ts#L27-L32

At present, if the repository directory doesn't contain a .git directory then the action always erases the entire repository directory, regardless of the "clean" setting.

PR #561, opened in Aug 2021 and still open in Sep 2024, proposed a change to respect clean input setting when the repository directory doesn't contain a .git directory.

This also indicates the current (v4.1.7) doc of clean input is over-simplified hence misleading.

muzimuzhi avatar Sep 12 '24 23:09 muzimuzhi

any news on that or a workaround?

I also have a multi step build pipeline, that later tries to upload the packages from the Build.ArtifactStagingDirectory but it keeps getting deleted, even if the steps.clean property is set to false


Resolved: this is by design: https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/azure-repos-git?view=azure-devops&tabs=yaml#clean-build

... Note that the $(Build.ArtifactStagingDirectory) and ... are always deleted and recreated prior to every build regardless of any of these settings.

Instead $(Build.BinariesDirectory) should be used to store and persist build binaries

ghost avatar Dec 02 '24 10:12 ghost

Any update or workaround for this ?

sanduluca avatar Dec 11 '24 14:12 sanduluca

any update on this?

aryhan-upupapp avatar Dec 12 '24 16:12 aryhan-upupapp

seems to still be a problem

alex-3881 avatar Dec 19 '24 10:12 alex-3881

This is still a problem

justAdevTV avatar Jan 30 '25 18:01 justAdevTV

Any workaround for this? 👎 I'm working with sub-modules and it's a problem. To fix it I manually download both repositories and do some magic moving the folders inside the vm.

andrelo86 avatar Feb 05 '25 01:02 andrelo86