Skip to content

Commit

Permalink
Add patch release PR creation scripts
Browse files Browse the repository at this point in the history
For the version branch.

Issue: timescale/eng-database#613
  • Loading branch information
pallavisontakke committed Jun 25, 2024
1 parent 2710536 commit 3b9c06b
Show file tree
Hide file tree
Showing 2 changed files with 176 additions and 0 deletions.
129 changes: 129 additions & 0 deletions scripts/release/create_release_PR_commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#!/bin/bash
set -eu

#Versions
#Expected to change more often , when we run this script.
NEW_VERSION="2.15.3"
CURRENT_VERSION="2.15.2"
LAST_VERSION="2.15.1"
RELEASE_BRANCH="2.15.x"
RELEASE_ISSUE="613"

# GITHUB_USERNAMES
GH_USERNAME="pallavisontakke"

# Folder, where we have cloned repositories' sources
SOURCES_DIR="sources"

# Derived Variables
FORK_DIR="$GH_USERNAME-timescaledb"
RELEASE_PR_BRANCH="release-$NEW_VERSION"
UPDATE_FILE="$CURRENT_VERSION--$NEW_VERSION.sql"
DOWNGRADE_FILE="$NEW_VERSION--$CURRENT_VERSION.sql"
LAST_UPDATE_FILE="$LAST_VERSION--$CURRENT_VERSION.sql"
LAST_DOWNGRADE_FILE="$CURRENT_VERSION--$LAST_VERSION.sql"
CHANGELOG_HEADER_LINES="6"


echo "---- Creating release branch $RELEASE_PR_BRANCH from $RELEASE_BRANCH, on the fork ----"

cd ~/"$SOURCES_DIR"/"$FORK_DIR"
git fetch --all
git checkout -b "$RELEASE_PR_BRANCH" upstream/"$RELEASE_BRANCH"
git branch
git pull && git diff HEAD


echo "---- Modifying version.config to the new versions ----"

sed -i.bak "s/"$CURRENT_VERSION"/"$NEW_VERSION"/g" version.config
sed -i.bak "s/"$LAST_VERSION"/"$CURRENT_VERSION"/g" version.config
rm version.config.bak


echo "---- Creating update SQL file $UPDATE_FILE ----"

cd sql/updates
cp latest-dev.sql "$UPDATE_FILE"
git add "$UPDATE_FILE"
truncate -s 0 latest-dev.sql


echo "---- Creating downgrade SQL file $DOWNGRADE_FILE ----"

cp reverse-dev.sql "$DOWNGRADE_FILE"
git add "$DOWNGRADE_FILE"
truncate -s 0 reverse-dev.sql


echo "---- Adding update sql file to CMakeLists.txt ----"

cd ..
gawk -i inplace '/'$LAST_UPDATE_FILE')/ { print; print " updates/'$UPDATE_FILE')"; next }1' CMakeLists.txt
sed -i.bak "s/"$LAST_UPDATE_FILE")/"$LAST_UPDATE_FILE"/g" CMakeLists.txt
rm CMakeLists.txt.bak


echo "---- Adding downgrade sql file to CMakeLists.txt ----"

gawk -i inplace '/ '$LAST_DOWNGRADE_FILE')/ { print; print " '$DOWNGRADE_FILE')"; next }1' CMakeLists.txt
sed -i.bak "s/ "$LAST_DOWNGRADE_FILE")/ "$LAST_DOWNGRADE_FILE"/g" CMakeLists.txt
rm CMakeLists.txt.bak

sed -i.bak "s/FILE "$LAST_DOWNGRADE_FILE")/FILE "$DOWNGRADE_FILE")/g" CMakeLists.txt
rm CMakeLists.txt.bak


#delete Features section from the templates and create this version's CHANGELOG.md
#Undo the deletion, from the template files.
echo "---- Creating CHANGELOG_"$NEW_VERSION".md file ----"

cd ~/"$SOURCES_DIR"/"$FORK_DIR"
cd .unreleased

head -n 12 RELEASE_NOTES_HEADER.md.j2 > RELEASE_NOTES_HEADER.md.j2.tmp
mv RELEASE_NOTES_HEADER.md.j2.tmp RELEASE_NOTES_HEADER.md.j2

head -n 12 template.release_notes_header.j2 > template.release_notes_header.j2.tmp
mv template.release_notes_header.j2.tmp template.release_notes_header.j2

rm -f ~/CHANGELOG_"$NEW_VERSION".md

cd ~/"$SOURCES_DIR"/"$FORK_DIR"
./scripts/merge_changelogs.sh > ~/CHANGELOG_"$NEW_VERSION".md

cd .unreleased
rm RELEASE_NOTES_HEADER.md.j2 template.release_notes_header.j2
git checkout RELEASE_NOTES_HEADER.md.j2 template.release_notes_header.j2


echo "---- Editing the CHANGELOG.md file with the contents of CHANGELOG_"$NEW_VERSION".md file. ----"

cd ~/"$SOURCES_DIR"/"$FORK_DIR"
mv CHANGELOG.md CHANGELOG.md.tmp
head -n 6 CHANGELOG.md.tmp > CHANGELOG.md
cat ~/CHANGELOG_"$NEW_VERSION".md >> CHANGELOG.md
CHANGELOG_LENGTH=$(wc -l CHANGELOG.md.tmp | cut -d ' ' -f 5)
CHANGELOG_ENTRIES=$((CHANGELOG_LENGTH-CHANGELOG_HEADER_LINES))
tail -n "$CHANGELOG_ENTRIES" CHANGELOG.md.tmp >> CHANGELOG.md
rm CHANGELOG.md.tmp


echo "---- Deleting fix_* & pr_* files ----"

rm -f .unreleased/fix_*
rm -f .unreleased/pr_*

git diff HEAD --name-only


echo "---- Commiting the Release PR to fork ----"

#Remove date from the intermediate CHANGELOG file.

cut -d '(' -f1 < ~/CHANGELOG_"$NEW_VERSION".md > ~/CHANGELOG_"$NEW_VERSION".md.tmp
mv ~/CHANGELOG_"$NEW_VERSION".md.tmp ~/CHANGELOG_"$NEW_VERSION".md

git commit -a -F ~/CHANGELOG_"$NEW_VERSION".md

git push origin $RELEASE_PR_BRANCH
47 changes: 47 additions & 0 deletions scripts/release/ready_fork_for_commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
set -eu

# GITHUB_USERNAMES
GH_USERNAME="pallavisontakke"
GH_FULL_USERNAME="Pallavi Sontakke"
GH_EMAIL="[email protected]"

# Folder, where we have cloned repositories' sources
SOURCES_DIR="sources"

# Derived Variables
FORK_DIR="$GH_USERNAME-timescaledb"


echo "---- Updating fork with upstream for user $GH_USERNAME ----"

gh repo sync "$GH_USERNAME/timescaledb" -b main


echo "---- Cloning the fork to $FORK_DIR ----"

cd
cd "$SOURCES_DIR"
rm -rf "$FORK_DIR"
git clone [email protected]:"$GH_USERNAME"/timescaledb.git "$FORK_DIR"
cd "$FORK_DIR"
git branch
git pull && git diff HEAD
git log -n 2

echo "---- Configuring the fork for commit ----"

git config user.name "$GH_FULL_USERNAME"
git config user.email "$GH_EMAIL"
git remote add upstream [email protected]:timescale/timescaledb.git
git config -l
git remote -v


echo "---- Updating tags from upstream on the fork ----"

git fetch --tags upstream
git push --tags origin main
# Check the needed branch name here - could it be 2.14.x ?
# git push -f --tags origin main

0 comments on commit 3b9c06b

Please sign in to comment.