Last active
November 20, 2017 14:08
-
-
Save Nirajkashyap/dc9782229cd10cb7d3b6732f928d7d7a to your computer and use it in GitHub Desktop.
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 -e | |
| : "${BRANCHES_TO_MERGE_REGEX?}" "${BRANCH_TO_MERGE_INTO?}" | |
| : "${GITHUB_SECRET_TOKEN?}" "${GITHUB_REPO?}" | |
| export GIT_COMMITTER_EMAIL='travis@travis' | |
| export GIT_COMMITTER_NAME='Travis CI' | |
| if ! grep -q "$BRANCHES_TO_MERGE_REGEX" <<< "$TRAVIS_PULL_REQUEST_BRANCH"; then | |
| printf "Current branch %s doesn't match regex %s, exiting\\n" \ | |
| "$TRAVIS_PULL_REQUEST_BRANCH" "$BRANCHES_TO_MERGE_REGEX" >&2 | |
| exit 0 | |
| fi | |
| # Since Travis does a partial checkout, we need to get the whole thing | |
| repo_temp=$(mktemp -d) | |
| git clone "https://github.com/$GITHUB_REPO" "$repo_temp" | |
| # shellcheck disable=SC2164 | |
| cd "$repo_temp" | |
| printf 'Checking out %s\n' "$BRANCH_TO_MERGE_INTO" >&2 | |
| git checkout "$BRANCH_TO_MERGE_INTO" | |
| printf 'Merging %s\n' "$TRAVIS_COMMIT" >&2 | |
| git merge --ff-only "$TRAVIS_COMMIT" | |
| printf 'Pushing to %s\n' "$GITHUB_REPO" >&2 | |
| push_uri="https://$GITHUB_SECRET_TOKEN@github.com/$GITHUB_REPO" | |
| # Redirect to /dev/null to avoid secret leakage | |
| git push "$push_uri" "$BRANCH_TO_MERGE_INTO" >/dev/null 2>&1 | |
| git push "$push_uri" :"$TRAVIS_PULL_REQUEST_BRANCH" >/dev/null 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment