3
0
Fork 0
mirror of https://github.com/tj-actions/changed-files synced 2024-12-17 23:44:46 +00:00
changed-files/get-base-sha.sh

36 lines
1.2 KiB
Bash
Raw Normal View History

2022-09-24 23:49:47 +00:00
#!/usr/bin/env bash
set -eu
if [[ -n $INPUT_PATH ]]; then
REPO_DIR="$GITHUB_WORKSPACE/$INPUT_PATH"
echo "Resolving repository path: $REPO_DIR"
if [[ ! -d "$REPO_DIR" ]]; then
echo "::error::Invalid repository path: $REPO_DIR"
exit 1
fi
cd "$REPO_DIR"
fi
if [[ -n "$INPUT_SINCE" ]]; then
BASE_SHA=$(git log --format="%H" --date=local --since="$INPUT_SINCE" --reverse | head -n 1)
if [[ -z "$BASE_SHA" ]]; then
echo "::warning::The BASE_SHA for date '$INPUT_SINCE' couldn't be determined."
fi
echo "::set-output name=base_sha::$BASE_SHA"
elif [[ -n "$INPUT_BASE_SHA" ]]; then
echo "::set-output name=base_sha::$INPUT_BASE_SHA"
elif [[ "$INPUT_SINCE_LAST_REMOTE_COMMIT" == "true" ]]; then
2022-09-24 23:49:47 +00:00
LAST_REMOTE_COMMIT="$GITHUB_EVENT_BEFORE"
if [[ -z "$LAST_REMOTE_COMMIT" || "$LAST_REMOTE_COMMIT" == "0000000000000000000000000000000000000000" ]]; then
2022-09-25 01:59:18 +00:00
echo "::debug::First commit detected"
2022-09-24 23:49:47 +00:00
LAST_REMOTE_COMMIT=$(git rev-parse "$(git branch -r --sort=-committerdate | head -1)")
fi
if [[ "$INPUT_SHA" == "$LAST_REMOTE_COMMIT" ]]; then
LAST_REMOTE_COMMIT=$(git rev-parse "$INPUT_SHA^1")
fi
echo "::set-output name=base_sha::$LAST_REMOTE_COMMIT"
2022-09-25 01:11:18 +00:00
fi