Skip to content

Commit

Permalink
Add release-PR creation scripts
Browse files Browse the repository at this point in the history
For minor and patch releases. Pull Request is created on the version
branch.
  • Loading branch information
pallavisontakke authored Nov 11, 2024
1 parent e5e9496 commit b1aa565
Show file tree
Hide file tree
Showing 4 changed files with 372 additions and 0 deletions.
144 changes: 144 additions & 0 deletions scripts/release/create_minor_release_PR_commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#!/bin/bash
set -eu

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

GH_USERNAME=$(gh auth status | grep 'Logged in to' |cut -d ' ' -f 9)

FORK_DIR="$GH_USERNAME-timescaledb"

echo "---- Deriving the release related versions from main ----"

cd ~/"$SOURCES_DIR"/"$FORK_DIR"
git fetch --all

NEW_PATCH_VERSION="0"
NEW_VERSION=$(head -1 version.config | cut -d ' ' -f 3 | cut -d '-' -f 1)
RELEASE_BRANCH="${NEW_VERSION/%.$NEW_PATCH_VERSION/.x}"
CURRENT_VERSION=$(tail -1 version.config | cut -d ' ' -f 3)
cd sql/updates

for f in ./*
do
case $f in
*$CURRENT_VERSION.sql) LAST_UPDATE_FILE=$f;;
*) true;;
esac
done
LAST_VERSION=$(echo "$LAST_UPDATE_FILE" |cut -d '-' -f 1 |cut -d '/' -f 2)

echo "CURRENT_VERSION is $CURRENT_VERSION"
#echo "LAST_UPDATE_FILE is $LAST_UPDATE_FILE"
echo "LAST_VERSION is $LAST_VERSION"
echo "RELEASE_BRANCH is $RELEASE_BRANCH"
echo "NEW_VERSION is $NEW_VERSION"
cd ~/"$SOURCES_DIR"/"$FORK_DIR"


# Derived Variables
#RELEASE_PR_BRANCH="release-$NEW_VERSION-$RELEASE_BRANCH"
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"


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

git checkout -b "$RELEASE_PR_BRANCH" upstream/"$RELEASE_BRANCH"
#git checkout -b "$RELEASE_PR_BRANCH" upstream/main
git branch
git pull && git diff HEAD


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

sed -i.bak "s/-dev//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 reverse-dev.sql)/FILE ${DOWNGRADE_FILE})/g" CMakeLists.txt
rm CMakeLists.txt.bak


echo "---- Creating CHANGELOG_$NEW_VERSION.md file ----"

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

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

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

cd ~/"$SOURCES_DIR"/"$FORK_DIR"
RELEASE_NOTE_START=$(grep -n $CURRENT_VERSION CHANGELOG.md | cut -d ':' -f 1 | head -1)
CHANGELOG_HEADER_LINES=$((RELEASE_NOTE_START - 1))

mv CHANGELOG.md CHANGELOG.md.tmp
head -n $CHANGELOG_HEADER_LINES 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 all unreleased pr_* , fix_* , ... style files, except template ones ----"

cd .unreleased

for f in ./*
do
case $f in
*template.*) true;;
*RELEASE_NOTES*) true;;
*) git rm "$f";;
esac
done

cd ..

git diff HEAD --name-only


echo "---- Committing 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 --no-verify -a -F ~/CHANGELOG_"$NEW_VERSION".md

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

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

GH_USERNAME=$(gh auth status | grep 'Logged in to' |cut -d ' ' -f 9)

FORK_DIR="$GH_USERNAME-timescaledb"

echo "---- Deriving the release related versions from main ----"

cd ~/"$SOURCES_DIR"/"$FORK_DIR"
git fetch --all

NEW_PATCH_VERSION="0"

NEW_VERSION=$(head -1 version.config | cut -d ' ' -f 3 | cut -d '-' -f 1)

RELEASE_BRANCH="${NEW_VERSION/%.$NEW_PATCH_VERSION/.x}"

echo "RELEASE_BRANCH is $RELEASE_BRANCH"
echo "NEW_VERSION is $NEW_VERSION"

echo "---- Creating the version branch from main ----"

git fetch --all
git checkout -b "$RELEASE_BRANCH" upstream/main
git push upstream "$RELEASE_BRANCH":"$RELEASE_BRANCH"

145 changes: 145 additions & 0 deletions scripts/release/create_release_PR_commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#!/bin/bash
set -eu

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

GH_USERNAME=$(gh auth status | grep 'Logged in to' |cut -d ' ' -f 9)

FORK_DIR="$GH_USERNAME-timescaledb"

echo "---- Deriving the release related versions from main ----"

cd ~/"$SOURCES_DIR"/"$FORK_DIR"
git fetch --all

CURRENT_VERSION=$(tail -1 version.config | cut -d ' ' -f 3)
cd sql/updates
CURRENT_PATCH_VERSION=$(echo $CURRENT_VERSION | cut -d '.' -f 3)
NEW_PATCH_VERSION=$((CURRENT_PATCH_VERSION + 1))
RELEASE_BRANCH="${CURRENT_VERSION/%.$CURRENT_PATCH_VERSION/.x}"
NEW_VERSION="${CURRENT_VERSION/%.$CURRENT_PATCH_VERSION/.$NEW_PATCH_VERSION}"

for f in ./*
do
case $f in
*$CURRENT_VERSION.sql) LAST_UPDATE_FILE=$f;;
*) true;;
esac
done
LAST_VERSION=$(echo "$LAST_UPDATE_FILE" |cut -d '-' -f 1 |cut -d '/' -f 2)

echo "CURRENT_VERSION is $CURRENT_VERSION"
#echo "LAST_UPDATE_FILE is $LAST_UPDATE_FILE"
echo "LAST_VERSION is $LAST_VERSION"
echo "RELEASE_BRANCH is $RELEASE_BRANCH"
echo "NEW_VERSION is $NEW_VERSION"
cd ~/"$SOURCES_DIR"/"$FORK_DIR"


# Derived Variables
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"


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

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 ----"

touch reverse-dev.sql
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


echo "---- Creating CHANGELOG_$NEW_VERSION.md file ----"

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

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

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

cd ~/"$SOURCES_DIR"/"$FORK_DIR"
RELEASE_NOTE_START=$(grep -n $CURRENT_VERSION CHANGELOG.md | cut -d ':' -f 1 | head -1)
CHANGELOG_HEADER_LINES=$((RELEASE_NOTE_START - 1))

mv CHANGELOG.md CHANGELOG.md.tmp
head -n $CHANGELOG_HEADER_LINES 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 all unreleased pr_* , fix_* , ... style files, except template ones ----"

cd .unreleased

for f in ./*
do
case $f in
*template.*) true;;
*RELEASE_NOTES*) true;;
*) git rm "$f";;
esac
done

cd ..

git diff HEAD --name-only


echo "---- Committing 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 --no-verify -a -F ~/CHANGELOG_"$NEW_VERSION".md

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


echo "---- Setting git user parameters as per current global git configuration ----"

# GITHUB_USERNAMES
GH_EMAIL=$(git config user.email)
GH_FULL_USERNAME=$(git config user.name)
GH_USERNAME=$(gh auth status | grep 'Logged in to' |cut -d ' ' -f 9)

echo "GH_EMAIL is $GH_EMAIL"
echo "GH_FULL_USERNAME is $GH_FULL_USERNAME"
echo "GH_USERNAME is $GH_USERNAME"

# 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 b1aa565

Please sign in to comment.