Skip to content

Commit 26f62e4

Browse files
authored
[minor] Preserve whitespace and add branch as an input (#9)
* preserve whitespace this is important for md files where whitespaces represent line breaks * add branch as an input * move branch down to when we create the new one it might not be the right thing... * use github ref for dry run * roll back changes and just make the pr work from the passed base branch * lint
1 parent 84ae0da commit 26f62e4

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ inputs:
2121
description: The filenames to check for the tested up to version. Default is 'readme.txt,README.md'.
2222
required: false
2323
default: 'readme.txt,README.md'
24+
branch:
25+
description: The branch to use as the base for PRs and commit the changes back to.
26+
required: false
27+
default: 'main'
2428
runs:
2529
using: composite
2630
steps:
@@ -40,5 +44,6 @@ runs:
4044
WORKFLOW_PATH: ${{ github.workspace }}
4145
GH_TOKEN: ${{ inputs.gh-token }}
4246
FILENAMES: ${{ inputs.filenames }}
47+
BRANCH: ${{ inputs.branch }}
4348
run: bash ${{ github.action_path }}/bin/validate-plugin-version.sh
4449

bin/validate-plugin-version.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ main() {
4747

4848
# Compare versions using PHP
4949
if php -r "exit(version_compare('$TESTED_UP_TO', '$CURRENT_WP_VERSION', '>=') ? 0 : 1);"; then
50-
echo "Tested up to version matches or is greater than the current WordPress version. Nothing to do here."
50+
echo "Tested up to version matches or is greater than the current WordPress version. Check passed."
5151
exit
5252
fi
5353
echo "Tested up to version ($TESTED_UP_TO) is less than current WordPress version ($CURRENT_WP_VERSION)."
@@ -61,9 +61,9 @@ main() {
6161
if [[ -f "$full_path" ]]; then
6262
echo "Updating 'Tested up to' version in $full_path"
6363
if [[ "$OSTYPE" == "darwin"* ]]; then
64-
sed -i '' -E "s/(Tested up to: ).*/\1$CURRENT_WP_VERSION/" "$full_path"
64+
sed -i '' -E "s/(Tested up to: )([0-9.]+)([[:space:]]*)/\1$CURRENT_WP_VERSION\3/" "$full_path"
6565
else
66-
sed -i -E "s/(Tested up to: ).*/\1$CURRENT_WP_VERSION/" "$full_path"
66+
sed -i -E "s/(Tested up to: )([0-9.]+)([[:space:]]*)/\1$CURRENT_WP_VERSION\3/" "$full_path"
6767
fi
6868
fi
6969
done
@@ -108,7 +108,7 @@ main() {
108108
git commit -m "Update Tested Up To version to $CURRENT_WP_VERSION"
109109
git push origin "$BRANCH_NAME"
110110

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."
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"
112112
}
113113

114114
main

0 commit comments

Comments
 (0)