Last active
December 2, 2020 15:29
-
-
Save thomaspoignant/7d75d4cf0d71b4b3dff9bdcb2e4b4ca1 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
function open_pull_requests() { | |
if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then | |
STAGES=( dev pre pro ) | |
for STAGE in "${STAGES[@]}"; do | |
# Run CDK diff | |
cdk diff -c stage=${STAGE} | tee cdk_diff_${STAGE}.txt | |
# Prepare PR message | |
read -r -d '' MESSAGE <<-EOM | |
> :warning: **Please review this changes before merging.** | |
**This PR will apply these changes(\`cdk diff\`):** | |
\`\`\`console | |
$(cat cdk_diff_${STAGE}.txt) | |
\`\`\` | |
EOM | |
set +e | |
CMD_MESSAGE_OUTPUT=$(gh pr create --title "Update $STAGE environment." --body "$MESSAGE" --base "$STAGE" --head "$TRAVIS_BRANCH" 2>&1) | |
CMD_RES=$? | |
set -e | |
if [ $CMD_RES -ne 0 ]; then | |
if [[ "$CMD_MESSAGE_OUTPUT" == *"already exists"* ]]; then | |
echo "A PR is already opened. Skip opening a new one." | |
else | |
travis_terminate 1 | |
fi | |
fi | |
done | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment