Skip to content

Commit

Permalink
Merge pull request #43 from pantheon-systems/release-0.2.2
Browse files Browse the repository at this point in the history
Release 0.2.2
  • Loading branch information
pwtyler authored Dec 20, 2023
2 parents b2d5a76 + cea23c3 commit 0d84082
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 63 deletions.
95 changes: 37 additions & 58 deletions .bin/prepare-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]"
# 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
Expand All @@ -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}"

Expand Down
68 changes: 68 additions & 0 deletions .bin/src/functions.sh
Original file line number Diff line number Diff line change
@@ -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"
}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
5 changes: 4 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ 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
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

See the robots hard at work.

## Changelog

### 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)
* Set Counter to 5 [[#](https://github.com/pantheon-systems/plugin-pipeline-example/pull/#)]

Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -68,6 +68,9 @@ directory take precedence. For example, `/assets/screenshot-1.png` would win ove

== Changelog ==

= 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) =
* Set Counter to 5 [[#](https://github.com/pantheon-systems/plugin-pipeline-example/pull/#)]

Expand Down
4 changes: 2 additions & 2 deletions rossums-universal-robots.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Author URI: pantheon.io
* Text Domain: rossums-universal-robots
* Domain Path: /languages
* Version: 0.2.1
* Version: 0.2.2
*
* @package Rossums_Universal_Robots
*/
Expand All @@ -29,5 +29,5 @@ function rur_counter() {
* @since 0.2.0
*/
function rur_another_counter() {
return 0;
return 1;
}

0 comments on commit 0d84082

Please sign in to comment.