-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sébastien HOUZÉ
committed
Jan 2, 2021
1 parent
d35083c
commit 22030d6
Showing
2 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,17 @@ | ||
# sparse-checkout | ||
github action to sparse checkout a repository | ||
# Sparse checkout composite action | ||
|
||
This action allows to sparse checkout a git repository, aims to speedup cloning time on mono repositories. | ||
|
||
## Inputs | ||
|
||
### `patterns` | ||
|
||
**Required** The patterns to sparse checkout into the repository. Default `"*"`. | ||
|
||
## Example usage | ||
|
||
```yaml | ||
- uses: gogaille/sparse-checkout | ||
with: | ||
patterns: 'some_directory some_other_directory' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: "Sparse Checkout" | ||
description: "Sparse checkout a git repository, especially to speedup mono-repositories clone time" | ||
|
||
inputs: | ||
patterns: | ||
description: > | ||
Git sparse checkout patterns. | ||
[Learn more by reading git documentation](https://git-scm.com/docs/git-sparse-checkout#Documentation/git-sparse-checkout.txt-emsetem) | ||
default: "*" | ||
required: true | ||
token: | ||
description: > | ||
Personal access token (PAT) used to fetch the repository. The PAT is configured | ||
with the local git config, which enables your scripts to run authenticated git | ||
commands. The post-job step removes the PAT. | ||
We recommend using a service account with the least permissions necessary. | ||
Also when generating a new PAT, select the least scopes necessary. | ||
[Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets) | ||
default: ${{ github.token }} | ||
required: true | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: "⚙ configure git" | ||
shell: bash | ||
run: | | ||
git version | ||
git config --global gc.auto 0 | ||
- name: "⚡ git sparse checkout latest branch commit" | ||
shell: bash | ||
run: | | ||
REPO="https://${GITHUB_ACTOR}:${{ inputs.token }}@github.com/${GITHUB_REPOSITORY}.git" | ||
BRANCH="${GITHUB_REF/#refs\/heads\//}" | ||
git clone --filter=blob:none --no-checkout --depth 1 --sparse $REPO . | ||
git sparse-checkout init --cone | ||
git sparse-checkout set ${{ inputs.patterns }} | ||
git -c protocol.version=2 fetch --no-tags --prune --progress --depth=1 origin +${GITHUB_SHA}:refs/remotes/origin/${BRANCH} | ||
git checkout --progress --force -B $BRANCH refs/remotes/origin/$BRANCH | ||
- name: "👨💻 show what has been checked out" | ||
shell: bash | ||
run: | | ||
git log | ||
ls -lha |