Skip to content

Commit

Permalink
Add path: support
Browse files Browse the repository at this point in the history
  • Loading branch information
tianon committed Jan 9, 2025
1 parent 803ab5c commit 82af2a1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/checkout.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,17 @@ jobs:
exit 1
fi
- run: ls -l checkout/checkout.sh .git # files we know should exist, to make sure the checkout actually worked

# test path:
- uses: ./
with:
fetch-depth: 2
path: test/checkout/subdirectory
- run: ls -l test/checkout/subdirectory/checkout/checkout.sh
- run: touch test/checkout/subdirectory/is-it-writeable
- run: |
commits="$(git -C test/checkout/subdirectory log --oneline | wc -l)"
if [ "$commits" -gt 2 ]; then
echo >&2 'error: depth is busted'
exit 1
fi
2 changes: 2 additions & 0 deletions checkout/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ inputs:
token:
default: ${{ github.token }}

path: {}

fetch-depth:
description: 'number of commits; 0 for all'
default: 1
Expand Down
25 changes: 14 additions & 11 deletions checkout/checkout.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,31 @@ set -Eeuo pipefail -x
# TODO add "debug-env" input or something?
#env | sort

: repository "${INPUT_REPOSITORY:=$GITHUB_REPOSITORY}"
: ref "${FETCH_REF:=${INPUT_REF:-$GITHUB_SHA}}"
: fetch-depth "${depth:=${INPUT_FETCH_DEPTH:-1}}"

: host "${host:=${GITHUB_SERVER_URL%/}}"

uid="$(id -u)"
if [ "$uid" = 0 ]; then
# must be a Docker action running in a container
# must be a Docker action running in a container 🙃
# https://docs.github.com/en/actions/sharing-automations/creating-actions/dockerfile-support-for-github-actions#user
chown="$(stat --format '%u:%g' "$PWD")"
else
chown=
fi

: repository "${INPUT_REPOSITORY:=$GITHUB_REPOSITORY}"
: ref "${FETCH_REF:=${INPUT_REF:-$GITHUB_SHA}}"
: fetch-depth "${depth:=${INPUT_FETCH_DEPTH:-1}}"

: host "${host:=${GITHUB_SERVER_URL%/}}"
path="$PWD${PATH:+/${PATH#/}}"

git --version

: set-safe-directory "${INPUT_SET_SAFE_DIRECTORY=true}"
case "${INPUT_SET_SAFE_DIRECTORY,,}" in
true|yes|1) git config --global --add safe.directory "$PWD" ;;
true|yes|1) git config --global --add safe.directory "$path" ;;
esac

git init --quiet "$PWD"
mkdir -p "$path"
git init --quiet "$path"
git remote add origin "$host/${INPUT_REPOSITORY%.git}.git"
git config --local gc.auto 0

Expand Down Expand Up @@ -57,8 +60,8 @@ git fetch "${fetchArgs[@]}" "$FETCH_REF":
git checkout --progress --force FETCH_HEAD # TODO make a branch

if [ -n "$chown" ]; then
echo "::group::chown $chown $PWD"
chown --recursive --changes "$chown" "$PWD"
echo "::group::chown $chown $path"
chown --recursive --changes "$chown" "$path"
echo '::endgroup::'
fi

Expand Down

0 comments on commit 82af2a1

Please sign in to comment.