Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CMSP-501] WIP prepare dev script #19

Merged
merged 7 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions .bin/prepare-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/bin/bash
set -eou pipefail
IFS=$'\n\t'

# shellcheck disable=SC2155
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"
readonly GIT_USER="[email protected]"
readonly GIT_NAME="Pantheon Automation"

readonly RELEASE_BRANCH="release"
readonly DEVELOP_BRANCH="alt-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
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"
return
fi

(
shopt -s nocasematch # make the "if readme" case insensitive
if [[ "${file}" == "$BASE_DIR/readme.txt" ]]; then
echo "adding new heading"
new_heading="### ${NEW_DEV_VERSION}"
awk -v heading="$new_heading" '/## Changelog/ { print; print ""; print heading; print ""; next } 1' "$file" > tmp.md
mv tmp.md "$file"
git add "$file"
return
elif [[ "${file}" == "$BASE_DIR/readme.md" ]]; then
echo "adding new heading"
new_heading="= ${NEW_DEV_VERSION} ="
awk -v heading="$new_heading" '/== Changelog ==/ { print; print ""; print heading; print ""; next } 1' "$file" > tmp.md
mv tmp.md "$file"
git add "$file"
return
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"
fi

git add "$file"
}

main() {
local CANONICAL_VERSION
CANONICAL_VERSION="$(grep 'Stable tag:' < "${CANONICAL_FILE}" | awk '{print $3}')"

git checkout "${RELEASE_BRANCH}"
git pull origin "${RELEASE_BRANCH}"
git checkout "${DEVELOP_BRANCH}"
git pull origin "${DEVELOP_BRANCH}"
git rebase "${RELEASE_BRANCH}"

local NEW_DEV_VERSION
NEW_DEV_VERSION=$(new_dev_version_from_current "$CANONICAL_VERSION")

echo "Updating ${CANONICAL_VERSION} to ${NEW_DEV_VERSION}"
# Iterate through each file in the top-level directory
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 commit -m "Prepare ${NEW_DEV_VERSION}"
git push origin "${DEVELOP_BRANCH}"
}

main "$@"
4 changes: 2 additions & 2 deletions .bin/release-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ main() {
fi
done
# Who am I?
git config --global user.email "[email protected]"
git config --global user.name "Pantheon Automation"
git config user.email "[email protected]"
git config user.name "Pantheon Automation"

RELEASE_MESSAGE="Release ${NEW_VERSION}"
git commit -m "${RELEASE_MESSAGE}"
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/build-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ jobs:
git commit -m "Release $VERSION"
git tag "$VERSION"
git push --tags
prepare-dev:
name: Prepare next dev release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Update Development Branch
run: bash ./bin/prepare-dev.sh
2 changes: 2 additions & 0 deletions .github/workflows/on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
DB_HOST: localhost
steps:
- uses: actions/checkout@v3
- name: Run shell linter
run: make lint-shell
- name: Install NPM & Composer dependencies
run: |
composer install
Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


lint-shell:
shellcheck .bin/prepare-dev.sh .bin/release-pr.sh
lint: lint-shell
composer lint

test:
composer test
1 change: 1 addition & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the robots hard at work.
## Changelog

### 0.1.1-dev
* Set Counter to 0 [19](https://github.com/pantheon-systems/plugin-pipeline-example/pull/19)

### 0.1.0 (6 June 2023)
* Initial Release [[1](https://github.com/pantheon-systems/plugin-pipeline-example/pull/1)]
1 change: 0 additions & 1 deletion rossums-universal-robots.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* @package Rossums_Universal_Robots
*/

// Your code starts here.
/**
* Returns an int. It's a feature.
*
Expand Down
Loading