Last active
May 5, 2016 07:46
-
-
Save dmonllao/6b9720690d1b23fb5081 to your computer and use it in GitHub Desktop.
rebase_security.sh automatically resolving conflicts
This file contains hidden or 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
| #!/bin/bash | |
| ## | |
| # This file exposes the behaviour of the conflicts resolution function. | |
| # * You need to clone https://github.com/dmonllao/moodle-local_ci somewhere and checkout 'autoresolver' branch | |
| # and ln -s /LOCAL_CI/PATH/resolve_rebase_conflicts_test.sh /MOODLECLONE/PATH/ | |
| # * Comment out $gitcmd clean -dfx from rebase_security/rebase_security.sh | |
| # * I'm using a couple of repos in [email protected]:davidm to test this resetting HEAD to a hardcoded | |
| # old weekly commits after each execution, something like this below: | |
| # | |
| # For master (grunt): | |
| # | |
| # git checkout master && git reset --hard fed66ad9e2efd3a88a42298a5d6bf71dada3ffd7 && git push integrationtest master -f && \ | |
| # git checkout security-master && git reset --hard fed66ad9e2efd3a88a42298a5d6bf71dada3ffd7 && git push securitytest security-master -f && \ | |
| # ./resolve_rebase_conflicts_test.sh | |
| # | |
| # For MOODLE_28_STABLE (no grunt - remember to set gitbranch to MOODLE_28_STABLE): | |
| # | |
| # git checkout MOODLE_28_STABLE && git reset --hard 2e8e92b0f1a21a77aadcb320d358273855193cd0 && git push integrationtest MOODLE_28_STABLE -f && \ | |
| # git checkout security-MOODLE_28_STABLE && git reset --hard 2e8e92b0f1a21a77aadcb320d358273855193cd0 && git push securitytest security-MOODLE_28_STABLE -f && \ | |
| # ./resolve_rebase_conflicts_test.sh | |
| ## | |
| set -e | |
| # Required vars as will be required by the jenkins job. | |
| gitcmd="git" | |
| gitdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
| gitbranch="master" | |
| npmcmd="/usr/local/bin/npm" | |
| npmbase="/opt/npmbase" | |
| integrationremote="[email protected]:davidm/integration-test.git" | |
| securityremote="[email protected]:davidm/security-test.git" | |
| # Set this as well. | |
| localcipath='/var/www/local_ci' | |
| # Test data. | |
| moodlecssfile="theme/bootstrapbase/style/moodle.css" | |
| editorcssfile="theme/bootstrapbase/style/editor.css" | |
| jsbuild="/yui/build/" | |
| function test_grunt_available() { | |
| if [ -f "Gruntfile.js" ]; then | |
| return 0 | |
| fi | |
| return 1 | |
| } | |
| function test_compile_less() { | |
| # Grunt is available since Moodle 2.9, fallback to recess. | |
| if test_grunt_available; then | |
| $gruntcmd "css" | |
| else | |
| $recesscmd --compile --compress theme/bootstrapbase/less/moodle.less > "$moodlecssfile" && | |
| $recesscmd --compile --compress theme/bootstrapbase/less/editor.less > "$editorcssfile" | |
| fi | |
| $gitcmd add "$moodlecssfile" | |
| $gitcmd add "$editorcssfile" | |
| } | |
| function test_compile_js() { | |
| # Grunt is available since Moodle 2.9, fallback to shifter (only YUI modules before). | |
| if test_grunt_available; then | |
| $gruntcmd "js" | |
| else | |
| $shiftercmd --walk --recursive | |
| fi | |
| $gitcmd add "*$jsbuild*" | |
| } | |
| # Test vars. | |
| okfile="README.txt" | |
| randomlessfile="theme/bootstrapbase/less/bootstrap/buttons.less" | |
| anotherrandomlessfile="theme/bootstrapbase/less/moodle/core.less" | |
| randomjsfile="lib/editor/atto/yui/src/editor/js/editor.js" | |
| anotherrandomjsfile="lib/editor/atto/yui/src/editor/js/editor-plugin.js" | |
| # We need gruntcmd, recesscmd and/or shiftercmd depending on $gitbranch. | |
| . $localcipath'/prepare_npm_stuff/prepare_npm_stuff.sh' | |
| # Setup | |
| $gitcmd remote add integrationtest $integrationremote || | |
| $gitcmd remote add securitytest $securityremote || | |
| $gitcmd fetch integrationtest | |
| $gitcmd fetch securitytest | |
| # Cleanup. | |
| $gitcmd rebase --abort 2> /dev/null || | |
| # Use the specified branch and clean the remote. | |
| $gitcmd checkout -B $gitbranch 'integrationtest/'$gitbranch | |
| $gitcmd reset --hard 'integrationtest/'$gitbranch | |
| $gitcmd push integrationtest $gitbranch -f | |
| # To push to security repo with test data. | |
| $gitcmd checkout -B security-tmp | |
| # A no-conflict security issue. | |
| echo "ok security fix" >> "$okfile" | |
| $gitcmd commit "$okfile" -m "MS-1" | |
| # CSS change that will conflict in future. | |
| echo ".csschange{display: none;}" >> "$randomlessfile" | |
| test_compile_less | |
| $gitcmd commit "$randomlessfile" "$editorcssfile" -m "MS-2" | |
| # Another CSS change that will conflict in future. | |
| echo ".anothercsschange{display: none;}" >> "$anotherrandomlessfile" | |
| test_compile_less | |
| $gitcmd commit "$anotherrandomlessfile" "$moodlecssfile" -m "MS-3" | |
| # JS change that will conflict in future. | |
| echo "console.log('conflict');" >> "$randomjsfile" | |
| test_compile_js | |
| $gitcmd commit "$randomjsfile" "*$jsbuild*" -m "MS-4" | |
| # Another JS change that will conflict in future. | |
| echo "console.log('another conflict');" >> "$anotherrandomjsfile" | |
| test_compile_js | |
| $gitcmd commit "$anotherrandomjsfile" "*$jsbuild*" -m "MS-5" | |
| $gitcmd push securitytest security-tmp:'security-'$gitbranch -f | |
| # Now push to integration and see if resolve conflicts script does its job. | |
| $gitcmd checkout $gitbranch | |
| # No conflict change in integration. | |
| echo "0" | cat - $okfile > temp && mv temp $okfile | |
| $gitcmd commit $okfile -m "MDL-1" | |
| $gitcmd push integrationtest $gitbranch | |
| . /var/www/local_ci/rebase_security/rebase_security.sh | |
| $gitcmd checkout $gitbranch | |
| echo "" | |
| echo "" | |
| echo "console.log('integration change on top of the file');" | cat - $randomjsfile > temp && mv temp $randomjsfile | |
| echo "console.log('another integration change on top of the file');" | cat - $anotherrandomjsfile > temp && mv temp $anotherrandomjsfile | |
| test_compile_js | |
| $gitcmd commit $randomjsfile $anotherrandomjsfile "*$jsbuild*" -m "MDL-2" | |
| echo ".integrationcsschange{display:none;}" | cat - $randomlessfile > temp && mv temp $randomlessfile | |
| echo ".anotherintegrationcsschange{display:none;}" | cat - $anotherrandomlessfile > temp && mv temp $anotherrandomlessfile | |
| test_compile_less | |
| $gitcmd commit $moodlecssfile $editorcssfile $randomlessfile $anotherrandomlessfile -m "MDL-3 Multiple commits with conflicts" | |
| echo "this does not conflict, just checking --continue" | cat - $okfile > temp && mv temp $okfile | |
| $gitcmd commit $okfile -m "MDL-4 And an extra one :)" | |
| $gitcmd push integrationtest $gitbranch | |
| . /var/www/local_ci/rebase_security/rebase_security.sh | |
| $gitcmd checkout $gitbranch | |
| echo "" | |
| echo "" | |
| echo "No conflict resolution with no new conflicts as security-branch is on top of lastbased-branch." | cat - $okfile > temp && mv temp $okfile | |
| $gitcmd commit $okfile -m "MDL-5" | |
| $gitcmd push integrationtest $gitbranch | |
| . /var/www/local_ci/rebase_security/rebase_security.sh | |
| $gitcmd checkout $gitbranch | |
| echo "" | |
| echo "HEY! IT IS EXPECTED TO EXIT 1 WITH THE LAST TEST AS THE CONFLICT CAN NOT BE MANAGED AUTOMATICALLY." | |
| echo "" | |
| echo "This will exit 1 as this conflict can not be managed automatically." >> $okfile | |
| $gitcmd commit $okfile -m "MDL-6" | |
| $gitcmd push integrationtest $gitbranch | |
| . /var/www/local_ci/rebase_security/rebase_security.sh | |
| $gitcmd checkout $gitbranch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment