From e76494f7a3f9b945ae6082bf4ea033b7b375d2c9 Mon Sep 17 00:00:00 2001 From: Pantheon Automation Date: Wed, 20 Dec 2023 01:27:16 +0000 Subject: [PATCH 1/4] Prepare 0.2.2-dev --- README.MD | 4 ++-- readme.txt | 7 +++++-- rossums-universal-robots.php | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.MD b/README.MD index a409251..34125cc 100644 --- a/README.MD +++ b/README.MD @@ -5,7 +5,7 @@ Tags: comments, spam Requires at least: 4.5 Tested up to: 6.2.1 Requires PHP: 5.6 -Stable tag: 0.2.1 +Stable tag: 0.2.2-dev License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -13,7 +13,7 @@ See the robots hard at work. ## Changelog -### 0.2.1 (20 December 2023) +### 0.2.2-dev (20 December 2023) * Set Counter to 5 [[#](https://github.com/pantheon-systems/plugin-pipeline-example/pull/#)] ### 0.2.0 (19 December 2023) diff --git a/readme.txt b/readme.txt index 84654b6..76337be 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Tags: comments, spam Requires at least: 4.5 Tested up to: 6.2.1 Requires PHP: 5.6 -Stable tag: 0.2.1 +Stable tag: 0.2.2-dev License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -68,7 +68,10 @@ directory take precedence. For example, `/assets/screenshot-1.png` would win ove == Changelog == -= 0.2.1 (20 December 2023) = += 0.2.2-dev = + + += 0.2.2-dev (20 December 2023) = * Set Counter to 5 [[#](https://github.com/pantheon-systems/plugin-pipeline-example/pull/#)] = 0.2.0 (19 December 2023) = diff --git a/rossums-universal-robots.php b/rossums-universal-robots.php index b95430f..c63de25 100644 --- a/rossums-universal-robots.php +++ b/rossums-universal-robots.php @@ -7,7 +7,7 @@ * Author URI: pantheon.io * Text Domain: rossums-universal-robots * Domain Path: /languages - * Version: 0.2.1 + * Version: 0.2.2-dev * * @package Rossums_Universal_Robots */ From 9b83a06b005e0653806eeee2ee7bbafade84e715 Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Wed, 20 Dec 2023 09:53:29 -0800 Subject: [PATCH 2/4] Fix readmes --- README.MD | 4 +++- readme.txt | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.MD b/README.MD index 34125cc..ad31814 100644 --- a/README.MD +++ b/README.MD @@ -13,7 +13,9 @@ See the robots hard at work. ## Changelog -### 0.2.2-dev (20 December 2023) +### 0.2.2-dev + +### 0.2.1 (20 December 2023) * Set Counter to 5 [[#](https://github.com/pantheon-systems/plugin-pipeline-example/pull/#)] ### 0.2.0 (19 December 2023) diff --git a/readme.txt b/readme.txt index 76337be..fee6f18 100644 --- a/readme.txt +++ b/readme.txt @@ -70,8 +70,7 @@ directory take precedence. For example, `/assets/screenshot-1.png` would win ove = 0.2.2-dev = - -= 0.2.2-dev (20 December 2023) = += 0.2.1 (20 December 2023) = * Set Counter to 5 [[#](https://github.com/pantheon-systems/plugin-pipeline-example/pull/#)] = 0.2.0 (19 December 2023) = From 586960f89ed8921c5914ced287e5c567a96dee5e Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Wed, 20 Dec 2023 10:55:35 -0800 Subject: [PATCH 3/4] prepare dev refactor maybe I can unit test this if things keep breaking (#44) --- .bin/prepare-dev.sh | 95 ++++++++++++++---------------------- .bin/src/functions.sh | 68 ++++++++++++++++++++++++++ Makefile | 2 +- README.MD | 1 + readme.txt | 1 + rossums-universal-robots.php | 2 +- 6 files changed, 109 insertions(+), 60 deletions(-) create mode 100644 .bin/src/functions.sh diff --git a/.bin/prepare-dev.sh b/.bin/prepare-dev.sh index 2e45d24..b00ec37 100644 --- a/.bin/prepare-dev.sh +++ b/.bin/prepare-dev.sh @@ -12,86 +12,63 @@ readonly SELF_DIRNAME="$(dirname -- "$0")" readonly BASE_DIR="${SELF_DIRNAME}/.." # TODO: Parameterize or make case-insensitive when this is an action -readonly CANONICAL_FILE="README.MD" +# shellcheck disable=SC2034 readonly GIT_USER="bot@getpantheon.com" +# shellcheck disable=SC2034 readonly GIT_NAME="Pantheon Automation" +# shellcheck disable=SC1091 +source "${SELF_DIRNAME}/src/functions.sh" + readonly RELEASE_BRANCH="release" readonly DEVELOP_BRANCH="main" -new_dev_version_from_current(){ - local CURRENT_VERSION="$1" - IFS='.' read -ra parts <<< "$CURRENT_VERSION" - patch="${parts[2]}" - patch=$((patch + 1)) - INCREMENTED="${parts[0]}.${parts[1]}.${patch}-dev" - echo "$INCREMENTED" -} - process_file(){ - local file="$1" - if [ ! -f "$file" ]; then + local FILE="${1:-}" + local OLD_VERSION="${2:-}" + local NEW_VERSION="${3:-}" + if [[ -z "${FILE}" ]] || [[ ! -f "$FILE" ]]; then + echo_info "No File '${FILE}'" return fi - echo "Checking file '${file}'..." - if [[ "$file" == "$BASE_DIR/package-lock.json" || "$file" == "$BASE_DIR/package.json" ]];then - echo "package and package-lock will be handled later." + echo "Checking file '${FILE}'..." + if [[ "$FILE" == "$BASE_DIR/package-lock.json" || "$FILE" == "$BASE_DIR/package.json" ]];then + echo_info "package and package-lock will be handled later." return fi - if [[ "$file" == "$BASE_DIR/composer.json" || "$file" == "$BASE_DIR/composer.lock" ]];then - echo "skip composer." + if [[ "$FILE" == "$BASE_DIR/composer.json" || "$FILE" == "$BASE_DIR/composer.lock" ]];then + echo_info "skip composer." return fi shopt -s nocasematch # make the "if readme" case insensitive for readme_extension in "txt" "md"; do if [[ "$file" == "${BASE_DIR}/readme.${readme_extension}" ]]; then - echo "skip readmes" + echo_info "skipping readme" continue fi done shopt -u nocasematch echo "search-and-replace with sed" - sed -i.tmp -e '/^\s*\* @since/!s/'"${CANONICAL_VERSION}"'/'"${NEW_DEV_VERSION}"'/g' "$file" && rm "$file.tmp" - - git add "$file" -} + sed -i.tmp -e '/^\s*\* @since/!s/'"${OLD_VERSION}"'/'"${NEW_VERSION}"'/g' "$FILE" && rm "$FILE.tmp" -git_config(){ - git config user.email "${GIT_USER}" - git config user.name "${GIT_NAME}" + git add "$FILE" } -update_readme(){ - FILE_PATH="${1:-}" - if [[ -z "${FILE_PATH}" ]]; then - echo "missing file path" - return 1 +main() { + local README_MD="${1:-}" + if [[ -z "$README_MD" ]]; then + README_MD=README.MD fi - local EXTENSION=${FILE_PATH#"$BASE_DIR/readme."} - - echo "adding new heading to readme.${EXTENSION}" - - if [[ "$EXTENSION" == "md" ]]; then # there's gotta be a better way but whatever - local new_heading="### ${NEW_DEV_VERSION}" - local awk_with_target='/## Changelog/ { print; print ""; print heading; print ""; next } 1' - else - local new_heading="= ${NEW_DEV_VERSION} =" - local awk_with_target='/== Changelog ==/ { print; print ""; print heading; print ""; next } 1' + local README_TXT="${2:-}" + if [[ -z "$README_TXT" ]]; then + README_TXT=readme.txt fi - awk -v heading="$new_heading" "$awk_with_target" "$FILE_PATH" > tmp.md - mv tmp.md "$FILE_PATH" - - sed -i.tmp -e "s/Tested up to: ${CANONICAL_VERSION}/Tested up to: ${NEW_DEV_VERSION}/g" "$FILE_PATH" && rm "$FILE_PATH.tmp" - git add "$FILE_PATH" -} - -main() { - local CANONICAL_VERSION - CANONICAL_VERSION="$(grep 'Stable tag:' < "${CANONICAL_FILE}" | awk '{print $3}')" + local CURRENT_VERSION + CURRENT_VERSION="$(grep 'Stable tag:' < "${README_MD}" | awk '{print $3}')" # fetch all tags and history: git fetch --tags --unshallow --prune @@ -104,23 +81,25 @@ main() { git rebase "${RELEASE_BRANCH}" local NEW_DEV_VERSION - NEW_DEV_VERSION=$(new_dev_version_from_current "$CANONICAL_VERSION") + NEW_DEV_VERSION=$(new_dev_version_from_current "$CURRENT_VERSION") - echo "Updating ${CANONICAL_VERSION} to ${NEW_DEV_VERSION}" + echo "Updating ${CURRENT_VERSION} to ${NEW_DEV_VERSION}" # Iterate through each file in the top-level directory for file in "$BASE_DIR"/*; do - process_file "$file" + if [[ "$file" == "$README_MD" || "$file" == "$README_TXT" ]]; then + echo_info "Don't process readme [${file}]." + continue + fi + process_file "$file" "${CURRENT_VERSION}" "${NEW_DEV_VERSION}" done git_config - shopt -s nocasematch # make the "if readme" case insensitive - for readme_extension in "txt" "md"; do - if [[ -f "${BASE_DIR}/readme.${readme_extension}" ]]; then - update_readme readme.${readme_extension} + for readme in "$README_MD" "$README_TXT"; do + if [[ -f "${BASE_DIR}/${readme}" ]]; then + update_readme "${BASE_DIR}/${readme}" "${CURRENT_VERSION}" "${NEW_DEV_VERSION}" fi done - shopt -u nocasematch git commit -m "Prepare ${NEW_DEV_VERSION}" diff --git a/.bin/src/functions.sh b/.bin/src/functions.sh new file mode 100644 index 0000000..e3d4d26 --- /dev/null +++ b/.bin/src/functions.sh @@ -0,0 +1,68 @@ +#!/bin/bash +# no flags here, always source this file + + +## +# Expected Global Variables: +# - BASE_DIR +## +# echo to stderr with info tag +echo_info(){ + echo "[Info] $*" >&2 +} + +# echo to stderr with info tag +echo_error(){ + echo "[Error] $*" >&2 +} + +new_dev_version_from_current(){ + local CURRENT_VERSION="${1:-}" + if [[ -z "$CURRENT_VERSION" ]]; then + echo_error "No version passed to new_dev_version_from_current()" + return 1 + fi + + IFS='.' read -ra parts <<< "$CURRENT_VERSION" + local patch="${parts[2]}" + patch=$((patch + 1)) + local INCREMENTED="${parts[0]}.${parts[1]}.${patch}-dev" + echo "$INCREMENTED" +} + +git_config(){ + git config user.email "${GIT_USER}" + git config user.name "${GIT_NAME}" +} + +update_readme(){ + local FILE_PATH="${1:-}" + local OLD_VERSION="${2:-}" + local NEW_VERSION="${3:-}" + if [[ -z "${FILE_PATH}" || -z "${OLD_VERSION}" || -z "${NEW_VERSION}" ]]; then + echo_error "usage: update_readme FILE_PATH OLD_VERSION NEW_VERSION" + return 1 + fi + + local EXTENSION=${FILE_PATH#"$BASE_DIR/readme."} + + echo_info "adding new heading to readme.${EXTENSION}" + shopt -s nocasematch # make the "if" case insensitive + if [[ "$EXTENSION" == "md" ]]; then # there's gotta be a better way but whatever + echo_info "markdown search-replace" + local new_heading="### ${NEW_VERSION}" + local awk_with_target='/## Changelog/ { print; print ""; print heading; print ""; next } 1' + else + echo_info "wp.org txt search-replace" + local new_heading="= ${NEW_VERSION} =" + local awk_with_target='/== Changelog ==/ { print; print ""; print heading; print ""; next } 1' + fi + shopt -u nocasematch + + awk -v heading="$new_heading" "$awk_with_target" "$FILE_PATH" > tmp.md + mv tmp.md "$FILE_PATH" + + sed -i.tmp -e "s/Tested up to: ${OLD_VERSION}/Tested up to: ${NEW_VERSION}/g" "$FILE_PATH" && rm "$FILE_PATH.tmp" + + git add "$FILE_PATH" +} \ No newline at end of file diff --git a/Makefile b/Makefile index bf4d810..48e616f 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ lint-shell: - shellcheck .bin/prepare-dev.sh .bin/release-pr.sh + shellcheck .bin/prepare-dev.sh .bin/release-pr.sh .bin/src/* lint: lint-shell composer lint diff --git a/README.MD b/README.MD index ad31814..b1a3421 100644 --- a/README.MD +++ b/README.MD @@ -14,6 +14,7 @@ See the robots hard at work. ## Changelog ### 0.2.2-dev +* Set Second Counter to 1 [[44](https://github.com/pantheon-systems/plugin-pipeline-example/pull/44)] ### 0.2.1 (20 December 2023) * Set Counter to 5 [[#](https://github.com/pantheon-systems/plugin-pipeline-example/pull/#)] diff --git a/readme.txt b/readme.txt index fee6f18..9cf6044 100644 --- a/readme.txt +++ b/readme.txt @@ -69,6 +69,7 @@ directory take precedence. For example, `/assets/screenshot-1.png` would win ove == Changelog == = 0.2.2-dev = +* Set Second Counter to 1 [[44](https://github.com/pantheon-systems/plugin-pipeline-example/pull/44)] = 0.2.1 (20 December 2023) = * Set Counter to 5 [[#](https://github.com/pantheon-systems/plugin-pipeline-example/pull/#)] diff --git a/rossums-universal-robots.php b/rossums-universal-robots.php index c63de25..1c95509 100644 --- a/rossums-universal-robots.php +++ b/rossums-universal-robots.php @@ -29,5 +29,5 @@ function rur_counter() { * @since 0.2.0 */ function rur_another_counter() { - return 0; + return 1; } From cea23c3d97609a6ac0181cb670180b276a810472 Mon Sep 17 00:00:00 2001 From: Pantheon Automation Date: Wed, 20 Dec 2023 18:55:47 +0000 Subject: [PATCH 4/4] Release 0.2.2 --- README.MD | 4 ++-- readme.txt | 4 ++-- rossums-universal-robots.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.MD b/README.MD index b1a3421..b1a40ab 100644 --- a/README.MD +++ b/README.MD @@ -5,7 +5,7 @@ Tags: comments, spam Requires at least: 4.5 Tested up to: 6.2.1 Requires PHP: 5.6 -Stable tag: 0.2.2-dev +Stable tag: 0.2.2 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -13,7 +13,7 @@ See the robots hard at work. ## Changelog -### 0.2.2-dev +### 0.2.2 (20 December 2023) * Set Second Counter to 1 [[44](https://github.com/pantheon-systems/plugin-pipeline-example/pull/44)] ### 0.2.1 (20 December 2023) diff --git a/readme.txt b/readme.txt index 9cf6044..682e081 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Tags: comments, spam Requires at least: 4.5 Tested up to: 6.2.1 Requires PHP: 5.6 -Stable tag: 0.2.2-dev +Stable tag: 0.2.2 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -68,7 +68,7 @@ directory take precedence. For example, `/assets/screenshot-1.png` would win ove == Changelog == -= 0.2.2-dev = += 0.2.2 (20 December 2023) = * Set Second Counter to 1 [[44](https://github.com/pantheon-systems/plugin-pipeline-example/pull/44)] = 0.2.1 (20 December 2023) = diff --git a/rossums-universal-robots.php b/rossums-universal-robots.php index 1c95509..fbf3df4 100644 --- a/rossums-universal-robots.php +++ b/rossums-universal-robots.php @@ -7,7 +7,7 @@ * Author URI: pantheon.io * Text Domain: rossums-universal-robots * Domain Path: /languages - * Version: 0.2.2-dev + * Version: 0.2.2 * * @package Rossums_Universal_Robots */