-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from pantheon-systems/release-0.2.2
Release 0.2.2
- Loading branch information
Showing
6 changed files
with
116 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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}" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters