Skip to content

Commit e1b26a2

Browse files
authored
[minor] address bug with too much in the PRs (#12)
* address bug with too much in the PRs sets the default branch and checks out the passed branch if it exists uses those as the base previously $BRANCH was not being set * debug the passed branch * more debugging * use the remote default branch if it doesn't exist locally * output the contents of the changed files if we're dry-running this way we can see what's being changed * remove debugging from the test workflow * add newline * move the newline before the cat formats nicer
1 parent a2dd835 commit e1b26a2

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ jobs:
55
runs-on: ubuntu-latest
66
steps:
77
- uses: actions/checkout@v4
8+
with:
9+
fetch-depth: 0
810
- name: Validate Plugin Version
911
uses: ./
1012
with:

bin/validate-plugin-version.sh

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,30 @@ set -euo pipefail
33
IFS=$'\n\t'
44

55
main() {
6+
# Determine the default branch
7+
DEFAULT_BRANCH=$(git remote show origin | grep 'HEAD branch' | cut -d' ' -f5)
8+
echo "Default branch is $DEFAULT_BRANCH"
9+
10+
# Check out the specified branch if $BRANCH is set and not already on it
11+
if [[ -n "${BRANCH:-}" && "$(git rev-parse --abbrev-ref HEAD)" != "$BRANCH" ]]; then
12+
echo "Checking if branch $BRANCH exists."
13+
if ! git show-ref --verify --quiet "refs/heads/$BRANCH"; then
14+
if git show-ref --verify --quiet "refs/remotes/origin/$BRANCH"; then
15+
echo "Branch '$BRANCH' exists on remote. Checking out from remote."
16+
git checkout -b "$BRANCH" "origin/$BRANCH"
17+
else
18+
echo "Error: Branch '$BRANCH' does not exist."
19+
exit 1
20+
fi
21+
else
22+
echo "Checking out branch $BRANCH"
23+
git checkout "$BRANCH"
24+
fi
25+
fi
26+
627
# If $PLUGIN_PATH is defined, echo it.
728
if [[ -n "${PLUGIN_PATH:-}" ]]; then
8-
PLUGIN_PATH=${WORKFLOW_PATH}/${PLUGIN_PATH}
29+
PLUGIN_PATH=${WORKFLOW_PATH}/${PLUGIN_PATH}
930
echo "Plugin path: $PLUGIN_PATH"
1031
else
1132
local PLUGIN_PATH
@@ -89,6 +110,11 @@ main() {
89110
full_path="${PLUGIN_PATH}/${trimmed_filename}"
90111
if [[ -f "$full_path" ]]; then
91112
git add "$full_path"
113+
# If we're dry-running, output the contents of the changed files.
114+
if [[ "${DRY_RUN}" == "true" ]]; then
115+
echo -e "\n"
116+
cat "$full_path"
117+
fi
92118
fi
93119
done
94120

@@ -108,7 +134,11 @@ main() {
108134
git commit -m "Update Tested Up To version to $CURRENT_WP_VERSION"
109135
git push origin "$BRANCH_NAME"
110136

111-
gh pr create --title "Update Tested Up To version to $CURRENT_WP_VERSION" --body "This pull request updates the \"Tested up to\" version in specified files (${FILENAMES}) to match the current WordPress version $CURRENT_WP_VERSION." --base "$BRANCH"
137+
# Determine the base branch for the PR
138+
BASE_BRANCH="${BRANCH:-$DEFAULT_BRANCH}"
139+
140+
echo "Creating a pull request with base branch $BASE_BRANCH."
141+
gh pr create --title "Update Tested Up To version to $CURRENT_WP_VERSION" --body "This pull request updates the \"Tested up to\" version in specified files (${FILENAMES}) to match the current WordPress version $CURRENT_WP_VERSION." --base "$BASE_BRANCH"
112142
}
113143

114144
main

0 commit comments

Comments
 (0)