|
| 1 | +#!/bin/bash -e |
| 2 | + |
| 3 | +if [ "$1" = "-y" ]; then |
| 4 | + AUTOACCEPT=true |
| 5 | +else |
| 6 | + AUTOACCEPT=false |
| 7 | +fi |
| 8 | + |
| 9 | +VERSION="1.7.0" |
| 10 | +PREVIOUS_VERSION="1.6.0" |
| 11 | + |
| 12 | +if [ -z "$PREVIOUS_VERSION" ]; then |
| 13 | + echo "Cannot find PREVIOUS_VERSION." |
| 14 | + exit 1 |
| 15 | +fi |
| 16 | + |
| 17 | +if [ "$VERSION" == "$PREVIOUS_VERSION" ]; then |
| 18 | + echo "VERSION $VERSION equal to PREVIOUS_VERSION $PREVIOUS_VERSION" |
| 19 | + exit 1 |
| 20 | +fi |
| 21 | + |
| 22 | +echo "Announcing $PREVIOUS_VERSION -> $VERSION" |
| 23 | + |
| 24 | +DOCUMENTATION_DIR="documentation" |
| 25 | +RELEASE_DOCS_DIR="${DOCUMENTATION_DIR}/release-latest" |
| 26 | +SNAPSHOT_DOCS_DIR="${DOCUMENTATION_DIR}/snapshot" |
| 27 | + |
| 28 | +if [ "$(git status --porcelain=v1 $DOCUMENTATION)" != "" ]; then |
| 29 | + echo "ERROR: To proceed, the current branch must not contain uncommitted changes in directory '${DOCUMENTATION_DIR}'" |
| 30 | + # ask for user confirmation |
| 31 | + if [[ "$AUTOACCEPT" = false ]]; then |
| 32 | + read -p "revert changes? (y/n)? " -n 1 -r |
| 33 | + echo |
| 34 | + if [[ $REPLY =~ ^[Yy]$ ]]; then |
| 35 | + git checkout ${DOCUMENTATION_DIR} |
| 36 | + else |
| 37 | + exit 1 |
| 38 | + fi |
| 39 | + else |
| 40 | + echo "Reverting changes in directory '${DOCUMENTATION_DIR}'" |
| 41 | + git checkout ${DOCUMENTATION_DIR} |
| 42 | + fi |
| 43 | +fi |
| 44 | + |
| 45 | +#escape_for_sed() { echo "$1" | sed -e 's/[]\/$*.^|[]/\\&/g'; } |
| 46 | + |
| 47 | +# Make a separate branch because master branch is protected |
| 48 | + |
| 49 | +BRANCH="$VERSION-update-refs" |
| 50 | +if [ "$(git show-ref refs/heads/$BRANCH)" != "" ]; then |
| 51 | + echo "ERROR: Branch $BRANCH already exists." |
| 52 | + if [[ "$AUTOACCEPT" = false ]]; then |
| 53 | + read -p "Delete local branch? (y/n)? " -n 1 -r |
| 54 | + echo |
| 55 | + if [[ ! $REPLY =~ ^[Yy]$ ]]; then |
| 56 | + exit 1 |
| 57 | + else |
| 58 | + git branch -D $BRANCH |
| 59 | + fi |
| 60 | + else |
| 61 | + echo "Deleting local branch $BRANCH" |
| 62 | + git branch -D $BRANCH |
| 63 | + fi |
| 64 | + # Checkout local master branch so that changes to this script can be tested without pushing the script to the remote branch |
| 65 | + git checkout --track master -b $BRANCH |
| 66 | +else |
| 67 | + git checkout --track origin/master -b $BRANCH |
| 68 | +fi |
| 69 | + |
| 70 | +# update version number in snapshot docs |
| 71 | + |
| 72 | +echo "Updating version numbers in (snapshot) installation documentation" |
| 73 | +# On local machine (OSX) Use "sed -i '' ..." instead of "sed -i -e ..." as the latter creates a new file. |
| 74 | +# On Github Action workflow the "sed -i -e ..." is required as otherwise it results in failure |
| 75 | +# "can't read s/0.49.0/0.49.1/g: No such file or directory" |
| 76 | +sed -i -e "s/$PREVIOUS_VERSION/$VERSION/g" ${SNAPSHOT_DOCS_DIR}/docs/install/cli.md |
| 77 | +sed -i -e "s/$PREVIOUS_VERSION/$VERSION/g" ${SNAPSHOT_DOCS_DIR}/docs/install/integrations.md |
| 78 | +git --no-pager diff ${DOCUMENTATION_DIR} |
| 79 | + |
| 80 | +# ask for user confirmation before committing |
| 81 | +if [[ "$AUTOACCEPT" = false ]]; then |
| 82 | + read -p "Accept changes (y/n)? " -n 1 -r |
| 83 | + echo |
| 84 | + if [[ ! $REPLY =~ ^[Yy]$ ]]; then |
| 85 | + exit 1 |
| 86 | + fi |
| 87 | +fi |
| 88 | + |
| 89 | +# Replace release documentation with current snapshot documentation. |
| 90 | + |
| 91 | +echo "Replace release documentation with current snapshot documentation" |
| 92 | +# Support removal of files which still exists in release docs but which are no longer present in snapshot docs |
| 93 | +rm -rf ${RELEASE_DOCS_DIR}/docs/ |
| 94 | +cp -r ${SNAPSHOT_DOCS_DIR}/docs/ ${RELEASE_DOCS_DIR}/docs/ |
| 95 | +# Note that directory "${SNAPSHOT_DOCS_DIR}/overrides/" should not replace "${RELEASE_DOCS_DIR}/overrides/" |
| 96 | +cp -r ${SNAPSHOT_DOCS_DIR}/mkdocs.yml ${RELEASE_DOCS_DIR} |
| 97 | +# Add files which previously did not yet exists in the release docs but were present in the snapshot docs |
| 98 | +git add --all |
| 99 | +# Display sorted list of files changed but do not show contents as that could be a lot |
| 100 | +git status --porcelain=v1 documentation | sort |
| 101 | + |
| 102 | +# Commit and push changes |
| 103 | +if [[ "$AUTOACCEPT" = false ]]; then |
| 104 | + read -p "Commit and push changes (y/n)? " -n 1 -r |
| 105 | + echo |
| 106 | + if [[ ! $REPLY =~ ^[Yy]$ ]]; then |
| 107 | + exit 1 |
| 108 | + fi |
| 109 | +fi |
| 110 | +git commit -m "Updated refs to latest ($VERSION) release" |
| 111 | +git push origin $BRANCH |
0 commit comments