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: debug INPUT envs #8

Merged
merged 3 commits into from
Feb 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 41 additions & 25 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ inputs:
pr_allow_empty:
description: Create PR even if no changes
required: false
debug:
description: Enable debug output
required: false
default: false

outputs:
pr_url:
Expand All @@ -53,10 +49,22 @@ outputs:
description: 'Boolean string indicating whether a PR was created'
value: ${{ steps.pr-creation.outputs.pr_created }}


runs:
using: "composite"
steps:
- name: Create Pull Request ⤵️
env:
INPUT_SOURCE_BRANCH: ${{ inputs.source_branch }}
INPUT_DESTINATION_BRANCH: ${{ inputs.destination_branch }}
INPUT_PR_TITLE: ${{ inputs.pr_title }}
INPUT_PR_BODY: ${{ inputs.pr_body }}
INPUT_PR_REVIEWER: ${{ inputs.pr_reviewer }}
INPUT_PR_ASSIGNEE: ${{ inputs.pr_assignee }}
INPUT_PR_LABEL: ${{ inputs.pr_label }}
INPUT_PR_MILESTONE: ${{ inputs.pr_milestone }}
INPUT_PR_DRAFT: ${{ inputs.pr_draft }}
INPUT_PR_ALLOW_EMPTY: ${{ inputs.pr_allow_empty }}
id: pr-creation
run: |
set -e
Expand Down Expand Up @@ -89,38 +97,46 @@ runs:
echo_success() { printf "%b\n" "${color_green}✔ $(printf "%s\n" "$*")${reset_color}"; }
echo_fail() { printf "%b\n" "${color_red}✖ $(printf "%s\n" "$*")${reset_color}"; }
enable_debug() {
if [[ "${INPUT_DEBUG}" == "true" ]]; then
if [[ "${RUNNER_DEBUG}" == "true" ]]; then
echo_info "Enabling debug mode."
set -x
fi
}
disable_debug() {
if [[ "${INPUT_DEBUG}" == "true" ]]; then
if [[ "${RUNNER_DEBUG}" == "true" ]]; then
set +x
fi
}

enable_debug

if [[ $SHELLOPTS == *xtrace* ]]; then
env
fi

# init bool var to check if PR creation should be skipped
skip_pr_creation=false
pr_created=false

echo "::group::Gather Inputs"

if [[ ! -z "$GITHUB_HEAD_REF" && "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
if [[ ! -z "${INPUT_SOURCE_BRANCH}" ]]; then
SOURCE_BRANCH="${INPUT_SOURCE_BRANCH}"
elif [[ ! -z "$GITHUB_HEAD_REF" && "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
SOURCE_BRANCH="$GITHUB_HEAD_REF"
elif [[ ! -z "$INPUT_SOURCE_BRANCH" ]]; then
SOURCE_BRANCH="$INPUT_SOURCE_BRANCH"
elif [[ ! -z "$GITHUB_REF" ]]; then
SOURCE_BRANCH=${GITHUB_REF/refs\/heads\//} # Remove branch prefix
else
echo_fail "Set the INPUT_SOURCE_BRANCH environment variable or trigger from a branch."
echo_fail "Set the inputs.source_branch parameter or trigger from a branch."
exit 1
fi
echo_info "SOURCE_BRANCH=$SOURCE_BRANCH"

DESTINATION_BRANCH="${INPUT_DESTINATION_BRANCH:-"main"}"
if [[ ! -z "${INPUT_DESTINATION_BRANCH}" ]]; then
DESTINATION_BRANCH="${INPUT_DESTINATION_BRANCH}"
else
DESTINATION_BRANCH="main"
fi
echo_info "DESTINATION_BRANCH=$DESTINATION_BRANCH"

echo "::endgroup::"
Expand All @@ -147,7 +163,7 @@ runs:

# skip pr creation if there are no file differences, this avoids PRs with just a merge commit and no content
LINES_CHANGED=$(git diff --name-only "$DESTINATION_BRANCH" "$SOURCE_BRANCH" -- | wc -l | awk '{print $1}')
if [[ "$LINES_CHANGED" = "0" ]] && [[ ! "${{ inputs.pr_allow_empty }}" == "true" ]]; then
if [[ "$LINES_CHANGED" = "0" ]] && [[ ! "${INPUT_PR_ALLOW_EMPTY}" == "true" ]]; then
echo_info "No file changes detected between source and destination branches and pr_allow_empty is not set to true. Skipping PR creation."
skip_pr_creation=true
fi
Expand All @@ -166,33 +182,33 @@ runs:
declare -a COMMAND
COMMAND+=(gh pr create --base $DESTINATION_BRANCH --head $SOURCE_BRANCH --no-maintainer-edit)

if [[ ! -z "${{ inputs.pr_title }}" ]]; then
COMMAND+=(--title "${{ inputs.pr_title }}")
if [[ ! -z "${INPUT_PR_TITLE}" ]]; then
COMMAND+=(--title "${INPUT_PR_TITLE}")
else
COMMAND+=(--fill)
fi

if [[ ! -z "${{ inputs.pr_body }}" ]]; then
COMMAND+=(--body "${{ inputs.pr_body }}")
if [[ ! -z "${INPUT_PR_BODY}" ]]; then
COMMAND+=(--body "${INPUT_PR_BODY}")
fi

if [[ ! -z "${{ inputs.pr_reviewer }}" ]]; then
COMMAND+=(--reviewer "${{ inputs.pr_reviewer }}")
if [[ ! -z "${INPUT_PR_REVIEWER}" ]]; then
COMMAND+=(--reviewer "${INPUT_PR_REVIEWER}")
fi

if [[ ! -z "${{ inputs.pr_assignee }}" ]]; then
COMMAND+=(--assignee "${{ inputs.pr_assignee }}")
if [[ ! -z "${INPUT_PR_ASSIGNEE}" ]]; then
COMMAND+=(--assignee "${INPUT_PR_ASSIGNEE}")
fi

if [[ ! -z "${{ inputs.pr_label }}" ]]; then
COMMAND+=(--label "${{ inputs.pr_label }}")
if [[ ! -z "${INPUT_PR_LABEL}" ]]; then
COMMAND+=(--label "${INPUT_PR_LABEL}")
fi

if [[ ! -z "${{ inputs.pr_milestone }}" ]]; then
COMMAND+=(--milestone "${{ inputs.pr_milestone }}")
if [[ ! -z "${INPUT_PR_MILESTONE}" ]]; then
COMMAND+=(--milestone "${INPUT_PR_MILESTONE}")
fi

if [[ "${{ inputs.pr_draft }}" == "true" ]]; then
if [[ "${INPUT_PR_DRAFT}" == "true" ]]; then
COMMAND+=(--draft)
fi

Expand Down