3
0
Fork 0
mirror of https://github.com/tj-actions/changed-files synced 2025-01-05 09:35:54 +00:00
changed-files/get-base-sha.sh
2022-10-12 15:14:35 -05:00

24 lines
666 B
Bash

#!/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 "base_sha=$BASE_SHA" >> "$GITHUB_OUTPUT"
elif [[ -n "$INPUT_BASE_SHA" ]]; then
echo "base_sha=$INPUT_BASE_SHA" >> "$GITHUB_OUTPUT"
fi