Skip to content

Commit

Permalink
Fix the active branch (#3)
Browse files Browse the repository at this point in the history
* if there's nothing to diff, don't try to output a diff

* modify how we're checking the diff

* add an ACTIVE_BRANCH environment variable

* check if active branch is the same as the default branch
override if it's not

* restore the code to what it was before
we don't need to do diff output twice

* but we still need to use BRANCH rather than DEFAULT_BRANCH

* add an echo

* add quotes
  • Loading branch information
jazzsequence committed Jul 12, 2023
1 parent 1c1f16a commit 1c7b794
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ runs:
DEFAULT_BRANCH: ${{ inputs.default-branch }}
GH_TOKEN: ${{ github.token }}
THIS_REPO: ${{ github.repository }}
ACTIVE_BRANCH: ${{ github.ref }}
22 changes: 15 additions & 7 deletions bin/dependency-check-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ main() {

if [[ ${DRY_RUN} == "false" ]]; then
git push origin "${BRANCH}"

PR_BODY="Bumps [${NAME}](https://github.com/${REPO}/releases/tag/${LATEST_TAG}) from ${CURRENT_TAG} to ${LATEST_TAG}."

create_label_if_not_exists "dependencies" "#207de5" "Dependencies"
create_label_if_not_exists "automation" "#207de5" "Automation"
create_label_if_not_exists "automation" "#207de5" "Automation"
NEW_PR=$(gh pr create -l dependencies,automation -t "${PR_TITLE}" -b "${PR_BODY}" -R "${THIS_REPO}")

git checkout -
Expand All @@ -99,13 +99,21 @@ main() {
fi
echo
done
if [[ ${DRY_RUN} == "true" ]]; then
if [[ "${DRY_RUN}" == "true" ]]; then
echo "Dry run requested...checking the diff...🤔"
diff_output=$(git diff --color=always -U0 "${DEFAULT_BRANCH}"...HEAD)

# If we're doing a dry-run, let's output something so we can see that it did something.
echo "$diff_output"
BRANCH="${DEFAULT_BRANCH}"
if [[ "${ACTIVE_BRANCH}" != "${BRANCH}" ]]; then
echo "Default branch is ${BRANCH}, but active branch is ${ACTIVE_BRANCH}. We'll check out ${ACTIVE_BRANCH} instead."
BRANCH="${ACTIVE_BRANCH}"
fi
# If we're doing a dry-run, let's output a diff so we can see that it did something.
if git rev-parse --verify HEAD >/dev/null 2>&1; then
diff_output=$(git diff --color=always -U0 "${BRANCH}"...HEAD)
echo "$diff_output"
else
echo "No commits found for diff."
fi
fi
echo "✨ Done"
}

Expand Down

0 comments on commit 1c7b794

Please sign in to comment.