Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Announce script cleanup #1732

Merged
merged 1 commit into from
Dec 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)