auto-push-master.sh (2039B)
1 #!/bin/sh 2 set -e 3 set +x 4 if test "$(git config remote.origin.url)" != "https://github.com/jsmaniac/phc-thesis.git"; then 5 echo "Not on official repo, will not auto-push to master." 6 elif test "$TRAVIS_PULL_REQUEST" != "false"; then 7 echo "This is a Pull Request, will not auto-push to master." 8 elif test "$TRAVIS_BRANCH" != "dev"; then 9 echo "Not on dev branch (TRAVIS_BRANCH = $TRAVIS_BRANCH), will not auto-push to master." 10 elif test -z "${encrypted_8fdb34b09f5e_key:-}" -o -z "${encrypted_8fdb34b09f5e_iv:-}"; then 11 echo "Travis CI secure environment variables are unavailable, will not auto-push to master." 12 else 13 set -x 14 echo "Automatic push to master" 15 16 # Git configuration: 17 git config --global user.name "$(git log --format="%aN" HEAD -1) (Travis CI automatic commit)" 18 git config --global user.email "$(git log --format="%aE" HEAD -1)" 19 20 # SSH configuration 21 mkdir -p ~/.ssh 22 chmod 700 ~/.ssh 23 set +x 24 if openssl aes-256-cbc -K $encrypted_8fdb34b09f5e_key -iv $encrypted_8fdb34b09f5e_iv -in travis-deploy-key-id_rsa.enc -out travis-deploy-key-id_rsa -d >/dev/null 2>&1; then 25 echo "Decrypted key successfully." 26 else 27 echo "Error while decrypting key." 28 fi 29 mv travis-deploy-key-id_rsa ~/.ssh/travis-deploy-key-id_rsa 30 set -x 31 chmod 600 ~/.ssh/travis-deploy-key-id_rsa 32 set +x 33 eval `ssh-agent -s` 34 set -x 35 ssh-add ~/.ssh/travis-deploy-key-id_rsa 36 37 # Push to the auto-git branch, which can then auto-push to master, after this build finished 38 repo_url="$(git config remote.origin.url)" 39 ssh_repo_url="$(echo "$repo_url" | sed -e 's|^https://github.com/|git@github.com:|')" 40 commit_hash="$(git rev-parse HEAD)" 41 git log --oneline --decorate --graph -10 42 git fetch origin auto-push 43 git checkout FETCH_HEAD 44 echo "$commit_hash" > commit_hash 45 git add commit_hash 46 git commit -m "Request to auto-push $commit_hash to master" --allow-empty 47 git log --oneline --decorate --graph -10 48 git push --quiet "$ssh_repo_url" HEAD:auto-push || true # do not cause a tantrum in case of race conditions. 49 fi