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

WIP: Patch workflow for ckeditor #17

Merged
merged 8 commits into from
May 14, 2019
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
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,42 @@ To update CKEditor in liferay-portal:
3. Re-deploy the module with `gradlew clean deploy`.

An example of this can be seen in [this](https://github.com/liferay/liferay-portal/commit/5b2ae3732d96f7f0dec6d35cb4de99f9d389c248) commit (look at the [`package.json`](https://github.com/liferay/liferay-portal/blob/5b2ae3732d96f7f0dec6d35cb4de99f9d389c248/modules/apps/frontend-editor/frontend-editor-ckeditor-web/package.json) file)

## Patching

- Make sure you're update to date with the [superproject](https://github.com/liferay/liferay-ckeditor) repository:

```sh
git pull origin master
```

- Set up everything to start working on a patch:

```sh
sh ck.sh setup
```

- Work on your changes:

`cd` into the `ckeditor-dev/` submodule and prepare your desired changes on the `liferay` branch.

This could be `cherry-pick`ing a previously created commit or manually editing a file, so this can't be automated.
julien marked this conversation as resolved.
Show resolved Hide resolved

- Create your commit, add your changes and write a good commit message.

- Navigate back to the superproject's root directory and create the patch:

```sh
cd ..
sh ck.sh patch
```

- Create a build of CKEditor containing the patches:

From the root of the superproject's directory, run

```sh
sh ck.sh build
```

- Don't forget to add the changes and commit
220 changes: 220 additions & 0 deletions ck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
#!/bin/sh

set -e

function init() {
# Make sure submodule is registered and up-to-date.
git submodule update --init

# Fetch remote changes.
cd ckeditor-dev

# Make sure our working copy is clean.
git reset --hard HEAD --quiet
git clean -fdx
}

function usage() {
echo "Usage: ck.sh COMMAND"
echo
echo " Where COMMAND is either:"
echo
echo " 🔧 setup: Setup everything to start working on a patch"
echo " 💉 patch: Generate patches "
echo " 🔥 build: Generate a patched version of CKEditor"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍕🌶🌭

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

echo
echo
}

# Check arguments
if [ $# -ne 1 ]; then
usage
exit 1
fi

COMMAND=$1

case "$COMMAND" in
build)
echo
echo "*---------------------------------------------------------*"
echo "| ⚠️ WARNING |"
echo "*---------------------------------------------------------*"
echo

echo "This will generate a patched version of CKEditor"
read -p "Are you sure you want to continue? [y/n]" yn

case $yn in
[Yy]*)
init
git checkout --detach HEAD --quiet
git branch -f liferay HEAD
git checkout liferay

echo
echo "Checking for existing patches"
echo

if ! ls ../patches/*; then
echo "There doesn't seem to be any patch"
fi

echo
echo "Applying patches from \"patches/\" directory."
echo

if ! git am ../patches/*; then
echo
echo "⚠️ There was a problem applying patches:"
echo
echo "To retry manually and fix:"
echo
echo " cd ckeditor-dev"
echo " git am --abort"
echo " git am ../patches/*"
echo
echo "Once you are happy with the result, run `sh ck.sh patch` to update the contents of \"patches/\"."
echo
exit 1
fi

if [ -n "$DEBUG" ]; then
dev/builder/build.sh --build-config ../../../build-config.js \
--leave-css-unminified --leave-js-unminified
else
dev/builder/build.sh --build-config ../../../build-config.js
fi

# Remove old build files.
rm -rf ../ckeditor/*

# Replace with new build files.
cp -r dev/builder/release/ckeditor/* ../ckeditor/

echo
echo "*---------------------------------------------------------*"
echo "| ✅ DONE |"
echo "*---------------------------------------------------------*"
echo
echo "Don't forget to commit the result!"
echo
;;
*)
echo
echo "Aborting."
echo
esac
;;
patch)
init
# Navigate back to superproject
cd ..
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be nice to make init do that on its own. It is always a bit surprising when calling a function leaves you in a different working directory.


# Save SHA1 for later
sha1=`git submodule | grep ckeditor-dev | awk '{print $1}' | sed -e s/[^0-9a-f]//`

cd ckeditor-dev

# Check for the existence of the liferay branch in the submodule
if ! git rev-parse --verify liferay &>/dev/null; then
echo
echo "*---------------------------------------------------------*"
echo "| ❌ ERROR |"
echo "*---------------------------------------------------------*"
echo
echo "It seems that there's no `liferay` branch in the `ckeditor-dev` submodule."
echo
echo "Please run `sh ck.sh setup` to set up everything correctly."
echo

exit 1
fi

git checkout liferay --quiet

# Check for existing patches
patches=$(find ../patches -name *.patch -type f)

if [[ $(echo "$patches" | wc -l) -ne 0 ]]; then
echo
echo "*---------------------------------------------------------*"
echo "| ⚠️ WARNING |"
echo "*---------------------------------------------------------*"
echo
echo
echo "This will replace any existing patches..."
echo
echo "$patches"
echo

# Prompt the user to confirm he wants to delete existing patches
read -p "Are you sure you want to continue [y/n]? " yn
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again because init is destructive, we might want to do the prompting a bit earlier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok yes seems better

case $yn in
[Yy]*)
echo
echo "Removing existing patches."
echo

mkdir -p ../patches
rm -rf ../patches/*
;;
*)
echo
echo "Aborting."
echo
exit 1
;;
esac
else
echo
echo "No patches found."
echo
fi

echo "Generating patches."
echo

git format-patch $sha1 -o ../patches

echo
echo "*---------------------------------------------------------*"
echo "| ✅ DONE |"
echo "*---------------------------------------------------------*"
echo
echo
echo "You can now build CKEditor with your patches."
echo
echo
echo "Here are the steps to follow:"
echo
echo "1. Run `sh ./ck.sh build` to generate a patched version."
echo
;;
setup)
init
git checkout --detach HEAD
git branch -f liferay HEAD
git checkout liferay

echo
echo "*---------------------------------------------------------*"
echo "| ✅ DONE |"
echo "*---------------------------------------------------------*"
echo
echo
echo "You can now start working on your patch(es)."
echo
echo
echo "Here are the steps to follow:"
echo
echo "1. Navigate to the ckeditor-dev submodule directory (`cd ckeditor-dev`)"
echo "2. Work on your changes"
echo "3. Commit your changes"
echo "4. Run `sh ck.sh patch` to generate the patches"
echo
;;
*)
usage
;;
esac