checkout icon indicating copy to clipboard operation
checkout copied to clipboard

Support checkout of subdirectory into working directory

Open srgoni opened this issue 2 years ago • 6 comments

GitHub Actions are somewhat limited in what paths can be used in which tasks.

With run: steps, it's possible to set a custom working directory with the working-directory option, but this is not supported for uses: steps.

The only ways to make a custom container run in a subtree of a checkout are

  • with custom container options (which the container must support in some way)
  • by manually moving all relevant files from the checkout to the root of the workspace

Neither option is very convenient (and sometimes even impossible) or robust.

One possible solution to this problem could be to support working-directory in uses: steps, or the checkout action could support checking out only a subtree of a repository.

This can be implemented with git write-tree and git read-tree -um, as described here: https://stackoverflow.com/questions/30239659/git-clone-only-a-subdirectory-at-the-root-of-the-current-directory/30244250#30244250 Or a sparse checkout could be done and the contents of the subtree moved to the root of the working directory.

Note that this is the opposite of the path: option of the checkout action.

srgoni avatar Aug 15 '23 10:08 srgoni

+1, would make using actions with monorepos a lot easier. Currently having to use sparse-checkout and sparse-checkout-cone-mode and then moving directories, e.g. (Inspired by https://github.com/actions/checkout/issues/483):

jobs:
  eas-preview:
    name: EAS preview
    runs-on: ubuntu-latest
    steps:
      # Checkout project code
      # Use sparse checkout to only select files in mobile app directory
      # Turning off cone mode ensures that files in the project root are not included during checkout
      - uses: actions/checkout@v3
        with:
          sparse-checkout: 'frontend/mobile'
          sparse-checkout-cone-mode: false

      # This step is needed because expo-github-action does not support paths.
      # Therefore all mobile app assets should be moved to the project root.
      - name: Move mobile app files to root
        run: |
          ls -lah
          shopt -s dotglob
          mv frontend/mobile/* .
          rm -rf frontend
          ls -lah

danial-k avatar Oct 10 '23 21:10 danial-k

+1, this would be great.

MarkBNinetyOne avatar May 21 '24 12:05 MarkBNinetyOne

+1

Shion1305 avatar Jun 13 '24 09:06 Shion1305

+1

thatguyinabeanie avatar Aug 03 '24 13:08 thatguyinabeanie

+1

DiogoLobo122 avatar Aug 16 '24 12:08 DiogoLobo122

+1

Lemminkyinen avatar Aug 23 '24 08:08 Lemminkyinen

+1

bknowles-apld avatar Apr 22 '25 21:04 bknowles-apld