Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bug with force pushed commits #651

Merged
merged 3 commits into from Sep 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions action.yml
Expand Up @@ -158,6 +158,7 @@ runs:
env:
GITHUB_WORKSPACE: ${{ github.workspace }}
GITHUB_EVENT_BEFORE: ${{ github.event.before }}
GITHUB_EVENT_FORCED : ${{ github.event.forced }}
# INPUT_<VARIABLE_NAME> is not available in Composite run steps
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#example-specifying-inputs
INPUT_SINCE: ${{ inputs.since }}
Expand Down Expand Up @@ -190,6 +191,7 @@ runs:
GITHUB_WORKSPACE: ${{ github.workspace }}
GITHUB_PULL_REQUEST_BASE_SHA: ${{ github.event.pull_request.base.sha }}
GITHUB_EVENT_BEFORE: ${{ github.event.before }}
GITHUB_EVENT_FORCED : ${{ github.event.forced }}
# INPUT_<VARIABLE_NAME> is not available in Composite run steps
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#example-specifying-inputs
INPUT_SHA: ${{ steps.sha.outputs.sha }}
Expand Down
7 changes: 5 additions & 2 deletions diff-sha.sh
Expand Up @@ -62,10 +62,13 @@ if [[ -z $GITHUB_BASE_REF ]]; then
CURRENT_BRANCH=$TARGET_BRANCH && exit_status=$? || exit_status=$?

if [[ -z $INPUT_BASE_SHA ]]; then
PREVIOUS_SHA=$GITHUB_EVENT_BEFORE
PREVIOUS_SHA=""

if [[ "$GITHUB_EVENT_FORCED" == "false" ]]; then
PREVIOUS_SHA=$GITHUB_EVENT_BEFORE
fi

if [[ -z "$PREVIOUS_SHA" || "$PREVIOUS_SHA" == "0000000000000000000000000000000000000000" ]]; then
echo "::debug::First commit detected"
PREVIOUS_SHA=$(git rev-parse "$(git branch -r --sort=-committerdate | head -1 | xargs)")
fi

Expand Down
7 changes: 5 additions & 2 deletions get-base-sha.sh
Expand Up @@ -22,10 +22,13 @@ if [[ -n "$INPUT_SINCE" ]]; then
elif [[ -n "$INPUT_BASE_SHA" ]]; then
echo "::set-output name=base_sha::$INPUT_BASE_SHA"
elif [[ "$INPUT_SINCE_LAST_REMOTE_COMMIT" == "true" ]]; then
LAST_REMOTE_COMMIT="$GITHUB_EVENT_BEFORE"
LAST_REMOTE_COMMIT=""

if [[ "$GITHUB_EVENT_FORCED" == "false" ]]; then
LAST_REMOTE_COMMIT=$GITHUB_EVENT_BEFORE
fi

if [[ -z "$LAST_REMOTE_COMMIT" || "$LAST_REMOTE_COMMIT" == "0000000000000000000000000000000000000000" ]]; then
echo "::debug::First commit detected"
LAST_REMOTE_COMMIT=$(git rev-parse "$(git branch -r --sort=-committerdate | head -1 | xargs)")
fi
if [[ "$INPUT_SHA" == "$LAST_REMOTE_COMMIT" ]]; then
Expand Down