Skip to content

Commit

Permalink
Merge pull request #39 from pantheon-systems/release-0.2.0
Browse files Browse the repository at this point in the history
Release 0.2.0
  • Loading branch information
pwtyler authored Dec 19, 2023
2 parents b4c0ed4 + ed0d733 commit fe34f7c
Show file tree
Hide file tree
Showing 8 changed files with 315 additions and 209 deletions.
92 changes: 59 additions & 33 deletions .bin/prepare-dev.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#!/bin/bash
set -eou pipefail
set -x
IFS=$'\n\t'

if [[ "${DRY_RUN:-}" == 1 ]]; then
echo "Dry Run. Will not Push."
fi

# shellcheck disable=SC2155
readonly SELF_DIRNAME="$(dirname -- "$0")"
readonly BASE_DIR="${SELF_DIRNAME}/.."
Expand Down Expand Up @@ -29,42 +34,46 @@ process_file(){
return
fi
echo "Checking file '${file}'..."
if [[ "$file" = "$BASE_DIR/package-lock.json" ]];then
# skip package-lock and let `npm i` do it when package.json is processed.
echo "skipping sed of package lock"
if [[ "$file" == "$BASE_DIR/package-lock.json" ]];then
echo "package and package-lock will be handled later."
return
fi
if [[ "$file" == "$BASE_DIR/composer.json" || "$file" == "$BASE_DIR/composer-lock.json" ]];then
echo "skip composer."
return
fi

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"
}

shopt -s nocasematch # make the "if readme" case insensitive
local file_name=${file#"$BASE_DIR/"}
if [[ "$file_name" == "readme.txt" || "$file_name" == "readme.md" ]]; then
echo "adding new heading"
if [[ "$file_name" == "readme.txt" ]]; 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'
fi
shopt -u nocasematch
awk -v heading="$new_heading" "$awk_with_target" "$file" > tmp.md
mv tmp.md "$file"
git add "$file"
return
git_config(){
git config user.email "${GIT_USER}"
git config user.name "${GIT_NAME}"
}

update_readme(){
FILE_PATH="$1:-"
if [[ -z "${FILE_PATH}" ]]; then
echo "missing file path"
return 1
fi

echo "search-and-replace with sed"
# Use `sed` to perform the search and replace operation in each file
sed -i.tmp -e "s/${CANONICAL_VERSION}/${NEW_DEV_VERSION}/g" "$file" && rm "$file.tmp"
if [[ "$file" == "$BASE_DIR/package.json" ]];then
# TODO: This seems unsafe as we might update dependencies as well.
# Is it safe to just sed package-lock instead? That also seems wrong.
echo "running 'npm i --package-lock-only' to update package-lock.json"
npm i --package-lock-only
git add "$BASE_DIR/package-lock.json"
local EXTENSION=${file#"$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'
fi
awk -v heading="$new_heading" "$awk_with_target" "$FILE_PATH" > tmp.md
mv tmp.md "$file"

git add "$file"
}
Expand All @@ -74,9 +83,11 @@ main() {
CANONICAL_VERSION="$(grep 'Stable tag:' < "${CANONICAL_FILE}" | awk '{print $3}')"

# fetch all tags and history:
git fetch --tags --unshallow --prune
if ! git rev-parse --is-shallow-repository > /dev/null; then
git fetch --tags --unshallow --prune
fi

if [ "$(git rev-parse --abbrev-ref HEAD)" != "main" ]; then
if ! git show-ref --quiet refs/heads/main && [[ "$(git rev-parse --abbrev-ref HEAD)" != "main" ]]; then
git branch --track main origin/main
fi

Expand All @@ -94,11 +105,26 @@ main() {
for file in "$BASE_DIR"/*; do
process_file "$file"
done
# Who am I?
git config user.email "${GIT_USER}"
git config user.name "${GIT_NAME}"

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}
fi
done
shopt -u nocasematch

git commit -m "Prepare ${NEW_DEV_VERSION}"

if [[ -f "$BASE_DIR/package.json" ]]; then
npm version "${NEW_DEV_VERSION}" --no-git-tag-version
fi

if [[ "${DRY_RUN:-}" == 1 ]]; then
return
fi
git push origin "${DEVELOP_BRANCH}"
}

Expand Down
6 changes: 5 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ Tags: comments, spam
Requires at least: 4.5
Tested up to: 6.2.1
Requires PHP: 5.6
Stable tag: 0.1.3
Stable tag: 0.2.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

See the robots hard at work.

## Changelog

### 0.2.0 (19 December 2023)
* Set Counter to 4 [[37](https://github.com/pantheon-systems/plugin-pipeline-example/pull/37)]
* Add another counter [[37](https://github.com/pantheon-systems/plugin-pipeline-example/pull/37)]

### 0.1.3 (19 December 2023)
* Set Counter to 3 [[37](https://github.com/pantheon-systems/plugin-pipeline-example/pull/37)]

Expand Down
Loading

0 comments on commit fe34f7c

Please sign in to comment.