From e91a288ade061012776512ae54290f36283f8b3a Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 26 Nov 2024 09:07:23 -0700 Subject: [PATCH 1/8] 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 --- bin/validate-plugin-version.sh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/bin/validate-plugin-version.sh b/bin/validate-plugin-version.sh index b4ae0d9..fd37b47 100644 --- a/bin/validate-plugin-version.sh +++ b/bin/validate-plugin-version.sh @@ -3,6 +3,16 @@ set -euo pipefail IFS=$'\n\t' main() { + # Determine the default branch + DEFAULT_BRANCH=$(git remote show origin | grep 'HEAD branch' | cut -d' ' -f5) + echo "Default branch is $DEFAULT_BRANCH" + + # Check out the specified branch if $BRANCH is set + if [[ -n "${BRANCH:-}" ]]; then + echo "Checking out branch $BRANCH" + git checkout "$BRANCH" + fi + # If $PLUGIN_PATH is defined, echo it. if [[ -n "${PLUGIN_PATH:-}" ]]; then PLUGIN_PATH=${WORKFLOW_PATH}/${PLUGIN_PATH} @@ -108,7 +118,11 @@ main() { git commit -m "Update Tested Up To version to $CURRENT_WP_VERSION" git push origin "$BRANCH_NAME" - 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" + # Determine the base branch for the PR + BASE_BRANCH="${BRANCH:-$DEFAULT_BRANCH}" + + echo "Creating a pull request with base branch $BASE_BRANCH." + 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" } main \ No newline at end of file From a17e3ae1646ebb4a71c71c7af4b93607b6918029 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 26 Nov 2024 09:14:32 -0700 Subject: [PATCH 2/8] debug the passed branch --- .github/workflows/test.yml | 5 +++++ bin/validate-plugin-version.sh | 11 ++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2016be2..375945c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,6 +5,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Print current branch + run: | + echo "Current branch: $(git rev-parse --abbrev-ref HEAD)" - name: Validate Plugin Version uses: ./ with: diff --git a/bin/validate-plugin-version.sh b/bin/validate-plugin-version.sh index fd37b47..61d9c25 100644 --- a/bin/validate-plugin-version.sh +++ b/bin/validate-plugin-version.sh @@ -7,15 +7,20 @@ main() { DEFAULT_BRANCH=$(git remote show origin | grep 'HEAD branch' | cut -d' ' -f5) echo "Default branch is $DEFAULT_BRANCH" - # Check out the specified branch if $BRANCH is set - if [[ -n "${BRANCH:-}" ]]; then + # Check out the specified branch if $BRANCH is set and not already on it + if [[ -n "${BRANCH:-}" && "$(git rev-parse --abbrev-ref HEAD)" != "$BRANCH" ]]; then + echo "Checking if branch $BRANCH exists." + if ! git show-ref --verify --quiet "refs/heads/$BRANCH"; then + echo "Error: Branch '$BRANCH' does not exist." + exit 1 + fi echo "Checking out branch $BRANCH" git checkout "$BRANCH" fi # If $PLUGIN_PATH is defined, echo it. if [[ -n "${PLUGIN_PATH:-}" ]]; then - PLUGIN_PATH=${WORKFLOW_PATH}/${PLUGIN_PATH} + PLUGIN_PATH=${WORKFLOW_PATH}/${PLUGIN_PATH} echo "Plugin path: $PLUGIN_PATH" else local PLUGIN_PATH From 7bb3f22bbffec5d768dc52d9d2f6b73881fec10a Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 26 Nov 2024 09:17:12 -0700 Subject: [PATCH 3/8] more debugging --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 375945c..be164bf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,6 +10,8 @@ jobs: - name: Print current branch run: | echo "Current branch: $(git rev-parse --abbrev-ref HEAD)" + echo "All branches:" + git branch -a - name: Validate Plugin Version uses: ./ with: From 6ca5dd72f1777a9a73dc817693dc0f9a564183f4 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 26 Nov 2024 09:19:28 -0700 Subject: [PATCH 4/8] use the remote default branch if it doesn't exist locally --- bin/validate-plugin-version.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bin/validate-plugin-version.sh b/bin/validate-plugin-version.sh index 61d9c25..07fee05 100644 --- a/bin/validate-plugin-version.sh +++ b/bin/validate-plugin-version.sh @@ -11,11 +11,17 @@ main() { if [[ -n "${BRANCH:-}" && "$(git rev-parse --abbrev-ref HEAD)" != "$BRANCH" ]]; then echo "Checking if branch $BRANCH exists." if ! git show-ref --verify --quiet "refs/heads/$BRANCH"; then - echo "Error: Branch '$BRANCH' does not exist." - exit 1 + if git show-ref --verify --quiet "refs/remotes/origin/$BRANCH"; then + echo "Branch '$BRANCH' exists on remote. Checking out from remote." + git checkout -b "$BRANCH" "origin/$BRANCH" + else + echo "Error: Branch '$BRANCH' does not exist." + exit 1 + fi + else + echo "Checking out branch $BRANCH" + git checkout "$BRANCH" fi - echo "Checking out branch $BRANCH" - git checkout "$BRANCH" fi # If $PLUGIN_PATH is defined, echo it. From e71bbcf6aba5c26f4064713d5d25051aee9ccf39 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 26 Nov 2024 09:34:30 -0700 Subject: [PATCH 5/8] output the contents of the changed files if we're dry-running this way we can see what's being changed --- bin/validate-plugin-version.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/validate-plugin-version.sh b/bin/validate-plugin-version.sh index 07fee05..513aa91 100644 --- a/bin/validate-plugin-version.sh +++ b/bin/validate-plugin-version.sh @@ -110,6 +110,10 @@ main() { full_path="${PLUGIN_PATH}/${trimmed_filename}" if [[ -f "$full_path" ]]; then git add "$full_path" + # If we're dry-running, output the contents of the changed files. + if [[ "${DRY_RUN}" == "true" ]]; then + cat "$full_path" + fi fi done From f5b80b7c186dd75d9005525bd7dabb2829d253e2 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 26 Nov 2024 09:35:02 -0700 Subject: [PATCH 6/8] remove debugging from the test workflow --- .github/workflows/test.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index be164bf..1dd72f7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,11 +7,6 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Print current branch - run: | - echo "Current branch: $(git rev-parse --abbrev-ref HEAD)" - echo "All branches:" - git branch -a - name: Validate Plugin Version uses: ./ with: From d9f703c729ccbb7c030270adf4230324220db52b Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 26 Nov 2024 09:36:36 -0700 Subject: [PATCH 7/8] add newline --- bin/validate-plugin-version.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/validate-plugin-version.sh b/bin/validate-plugin-version.sh index 513aa91..3dea76c 100644 --- a/bin/validate-plugin-version.sh +++ b/bin/validate-plugin-version.sh @@ -113,6 +113,7 @@ main() { # If we're dry-running, output the contents of the changed files. if [[ "${DRY_RUN}" == "true" ]]; then cat "$full_path" + echo -e "\n" fi fi done From 73e8036e45dde9f3de2662ff6a01eccf01d9d7f6 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 26 Nov 2024 09:37:26 -0700 Subject: [PATCH 8/8] move the newline before the cat formats nicer --- bin/validate-plugin-version.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/validate-plugin-version.sh b/bin/validate-plugin-version.sh index 3dea76c..5b75434 100644 --- a/bin/validate-plugin-version.sh +++ b/bin/validate-plugin-version.sh @@ -112,8 +112,8 @@ main() { git add "$full_path" # If we're dry-running, output the contents of the changed files. if [[ "${DRY_RUN}" == "true" ]]; then - cat "$full_path" echo -e "\n" + cat "$full_path" fi fi done