Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Last active August 8, 2023 23:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guitarrapc/d56a096d3283cb43da5a0a0017f6eed2 to your computer and use it in GitHub Desktop.
Save guitarrapc/d56a096d3283cb43da5a0a0017f6eed2 to your computer and use it in GitHub Desktop.
git sparse checkout on GitHub Actions
name: "git sparse-checkout (exclude)"
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
jobs:
sparse-checkout:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: sparse checkout
run: |
git clone --filter=blob:none --no-checkout --depth 1 --sparse "https://${{ env.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" .
echo "git sparse-checkout set exclude directory"
git sparse-checkout set --no-cone "${{ env.SPARSECHECKOUT_DIR }}" "/*"
echo "git sparse-checkout without cone" # cone not allow pattern filter, therefore don't use cone.
git sparse-checkout init
echo "git sparse-checkout list"
git sparse-checkout list
echo "git checkout"
git checkout "${GITHUB_SHA}"
# if you have submodules in Private Repo, use PAT instead of secrets.GITHUB_TOKEN
if [[ -f ./.gitmodules ]]; then
echo "replace submodule url"
sed -i -e "s|https://github.com|https://${{ env.GITHUB_TOKEN }}@github.com|g" ./.gitmodules
echo "submodule update"
git submodule update --init --recursive
fi
echo "git reset"
git reset --hard "${GITHUB_SHA}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SPARSECHECKOUT_DIR: "!src/*"
- name: list root folders
run: ls -la
name: "git sparse-checkout (only)"
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
jobs:
sparse-checkout:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: sparse checkout
run: |
git clone --filter=blob:none --no-checkout --depth 1 --sparse "https://${{ env.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" .
echo "git sparse-checkout set only directory"
git sparse-checkout set --no-cone "${{ env.SPARSECHECKOUT_DIR }}"
echo "git sparse-checkout without cone" # cone not allow pattern filter, therefore don't use cone.
git sparse-checkout init
echo "git sparse-checkout list"
git sparse-checkout list
echo "git checkout"
git checkout "${GITHUB_SHA}"
# if you have submodules in Private Repo, use PAT instead of secrets.GITHUB_TOKEN
if [[ -f ./.gitmodules ]]; then
echo "replace submodule url"
sed -i -e "s|https://github.com|https://${{ env.GITHUB_TOKEN }}@github.com|g" ./.gitmodules
echo "submodule update"
git submodule update --init --recursive
fi
echo "git reset"
git reset --hard "${GITHUB_SHA}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SPARSECHECKOUT_DIR: src/*
- name: list root folders
run: ls -la
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment