Skip to content

Commit

Permalink
Implement clean: input
Browse files Browse the repository at this point in the history
  • Loading branch information
tianon committed Jan 10, 2025
1 parent bf1bfa9 commit 20e1a39
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/checkout.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ jobs:
- uses: ./.github/tmp/checkout
with:
fetch-depth: 3
# "Error: Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under '/home/runner/work/tianon-actions/tianon-actions/.github/tmp/checkout'. Did you forget to run actions/checkout before running your local action?" 😂
clean: false
# (if we let this "checkout" run the "clean" bits, it deletes our original checkout and thus the post-run step fails 🤦)
- run: ls -laFh
- run: git log --oneline
- run: touch is-it-writeable checkout/is-it-writeable
Expand All @@ -66,3 +69,13 @@ jobs:
echo >&2 'error: depth is busted'
exit 1
fi
# test clean:
- uses: ./checkout
with:
fetch-depth: 1
path: test/checkout/subdirectory
- run: |
if [ -e test/checkout/subdirectory/is-it-writeable ]; then
echo >&2 'error: clean is busted'
exit 1
fi
3 changes: 3 additions & 0 deletions checkout/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ inputs:

path: {}

clean:
default: true

fetch-depth:
description: 'number of commits; 0 for all'
default: 1
Expand Down
11 changes: 11 additions & 0 deletions checkout/checkout.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,20 @@ case "${INPUT_SET_SAFE_DIRECTORY,,}" in
true|yes|1) git config --global --add safe.directory "$path" ;;
esac

: clean "${INPUT_CLEAN=true}"
case "${INPUT_CLEAN,,}" in
true|yes|1)
# https://github.com/actions/checkout/blob/cbb722410c2e876e24abbe8de2cc27693e501dcb/src/git-directory-helper.ts#L90-L124
if [ -e "$path" ] && { ! git -C "$path" clean -ffdx || ! git -C "$path" reset --hard HEAD; }; then
find "$path" -mindepth 1 -delete
fi
;;
esac

mkdir --parents --verbose "$path"
git init --quiet "$path"
cd "$path"
git remote remove origin || :
git remote add origin "$host/${INPUT_REPOSITORY%.git}.git"
git config --local gc.auto 0

Expand Down

0 comments on commit 20e1a39

Please sign in to comment.