Skip to content

Commit

Permalink
Announce script cleanup (pinterest#1732)
Browse files Browse the repository at this point in the history
- Deleted updates to ktlint.github.io since it now redirects to pinterest.github.io/ktlint
- Made the script more robust
  • Loading branch information
shashachu committed Dec 15, 2022
1 parent d3c890c commit 20d9a88
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions .announce
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/bin/bash -e

# settings.servers.github.privateKey
if [ "$GITHUB_TOKEN" == "" ]; then exit 1; fi

# project.version
if [ "$VERSION" == "" ]; then exit 1; fi

Expand All @@ -23,8 +20,14 @@ echo "Announcing $PREVIOUS_VERSION -> $VERSION"
COMMIT_MESSAGE="Updated refs to latest ($VERSION) release"

if [ "$(git status --porcelain=v1 docs/install/cli.md docs/install/integrations.md)" != "" ]; then
echo "To proceed, cli.md and integrations.md must not contain uncommitted changes"
exit 1
echo "ERROR: To proceed, cli.md and integrations.md must not contain uncommitted changes"
# ask for user confirmation
if [[ "$AUTOACCEPT" = false ]]; then
read -p "revert changes? (y/n)? " -n 1 -r; echo; if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1; else git checkout docs/install/cli.md docs/install/integrations.md; fi
else
echo "Reverting changes to cli.md and integrations.md"
git checkout docs/install/cli.md docs/install/integrations.md
fi
fi

escape_for_sed() { echo $1 | sed -e 's/[]\/$*.^|[]/\\&/g'; }
Expand All @@ -42,22 +45,18 @@ fi

BRANCH="$VERSION-update-refs"

if [ "$(git show-ref refs/heads/$BRANCH)" != "" ]; then
echo "ERROR: Branch $BRANCH already exists."
if [[ "$AUTOACCEPT" = false ]]; then
read -p "Delete local branch? (y/n)? " -n 1 -r; echo; if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1; else git branch -D $BRANCH; fi
else
echo "Deleting local branch $BRANCH"
git branch -D $BRANCH
fi
fi

# Make a separate branch because master branch is protected
git checkout --track origin/master -b $BRANCH && git commit -m "$COMMIT_MESSAGE" docs/install/cli.md docs/install/integrations.md && git push origin $BRANCH

open "https://github.com/pinterest/ktlint/compare/$BRANCH?expand=1"

# update ktlint.github.io

CHECKOUT_DIR=$(mktemp -d /tmp/ktlint.github.io.XXXXXX)
git clone https://${GITHUB_TOKEN}@github.com/ktlint/ktlint.github.io.git $CHECKOUT_DIR

sed -i "" "s/$(escape_for_sed $PREVIOUS_VERSION)/$(escape_for_sed $VERSION)/g" $CHECKOUT_DIR/index.html
(cd $CHECKOUT_DIR && git --no-pager diff index.html)

# ask for user confirmation
if [[ "$AUTOACCEPT" = false ]]; then
read -p "commit & push (y/n)? " -n 1 -r; echo; if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1; fi
fi

(cd $CHECKOUT_DIR && git commit -m "$COMMIT_MESSAGE" index.html && git push origin master)

0 comments on commit 20d9a88

Please sign in to comment.