basant307/AI_Governance_Project
048
1#!/bin/bash2 3# Make script exit on first failure4set -e5 6# Check if VERSION variable is set7if [ -z "$VERSION" ]; then8 echo "VERSION variable is not set."9 exit 110else11 echo "VERSION is set to: $VERSION"12fi13 14# Check if NEXT_VERSION variable is set15if [ -z "$NEXT_VERSION" ]; then16 echo "NEXT_VERSION variable is not set."17 exit 118else19 echo "NEXT_VERSION is set to: $NEXT_VERSION"20fi21 22# Check if NEXT_BACK_PORT_VERSION variable is set23if [ -z "$NEXT_BACK_PORT_VERSION" ]; then24 echo "NEXT_BACK_PORT_VERSION variable is not set."25 exit 126else27 echo "NEXT_BACK_PORT_VERSION is set to: $NEXT_BACK_PORT_VERSION"28fi29 30# See current branch31echo "Current Branch: $(git branch --show-current)"32 33# See head of current branch34echo "Current Head: "35git log -n 136 37# See current origin38echo "See remotes: "39git remote -v40 41# Set git configs42git config --global user.name "${GITHUB_ACTOR}"43git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"44 45# Create and push the new backport branch46git checkout master47git checkout -b "$NEXT_BACK_PORT_VERSION"48git push origin "$NEXT_BACK_PORT_VERSION"49 50# Step 2: Make sure local unstable is up-to-date51git checkout unstable52git pull53 54# Check if current Git branch is named "unstable"55current_branch=$(git symbolic-ref --short HEAD 2>/dev/null)56 57if [ "$current_branch" = "unstable" ]; then58 echo "Current Git branch is unstable."59else60 echo "Current Git branch is not unstable."61 exit 262fi63 64echo "Updating documentation"65jq --arg ver "$VERSION" '.versions += [$ver]' ./documentation/versions.json > /tmp/temp.json66mv /tmp/temp.json ./documentation/versions.json67 68git add .69git commit -m "Documentation $VERSION: Append $VERSION to versions.json"70echo "Documentation committed"71 72# Step 3: Create a merge commit and push it73git merge -s ours master -m "Merge master to unstable"74echo "Master merged to unstable"75git push origin unstable76echo "Unstable pushed to remote"77 78# Step 4: Fast-forward master to the merge commit79git checkout master80git merge unstable81echo "Unstable merged in master"82 83git push84echo "Master pushed to remote"85 86# Update package.json87jq --arg ver "$VERSION" '.version = $ver' package.json > /tmp/temp.json88mv /tmp/temp.json package.json89 90# Update package-lock.json91jq --arg ver "$VERSION" '.version = $ver' package-lock.json > /tmp/temp.json92mv /tmp/temp.json package-lock.json93 94# Check if version is updated in package.json95version_check_package=$(jq -r '.version' package.json)96if [ "$version_check_package" != "$VERSION" ]; then97 echo "Failed to update version in package.json"98 exit 399else100 echo "Version updated in package.json"101fi102 103# Check if version is updated in package-lock.json104version_check_package_lock=$(jq -r '.version' package-lock.json)105if [ "$version_check_package_lock" != "$VERSION" ]; then106 echo "Failed to update version in package-lock.json"107 exit 4108else109 echo "Version updated in package-lock.json"110fi111 112# Commit and push the updated version files113git add package.json package-lock.json114git commit -m "Update version to $VERSION"115git push116 117# Update new version in unstable118git checkout unstable119 120# Update package.json121jq --arg ver "$NEXT_VERSION" '.version = $ver' package.json > /tmp/temp.json122mv /tmp/temp.json package.json123 124# Update package-lock.json125jq --arg ver "$NEXT_VERSION" '.version = $ver' package-lock.json > /tmp/temp.json126mv /tmp/temp.json package-lock.json127 128# Check if version is updated in package.json for unstable129version_check_package_unstable=$(jq -r '.version' package.json)130if [ "$version_check_package_unstable" != "$NEXT_VERSION" ]; then131 echo "Failed to update version in package.json for unstable"132 exit 3133else134 echo "Version updated in package.json for unstable"135fi136 137# Check if version is updated in package-lock.json for unstable138version_check_package_lock_unstable=$(jq -r '.version' package-lock.json)139if [ "$version_check_package_lock_unstable" != "$NEXT_VERSION" ]; then140 echo "Failed to update version in package-lock.json for unstable"141 exit 4142else143 echo "Version updated in package-lock.json for unstable"144fi145 146# Commit and push the updated version files147git add package.json package-lock.json148git commit -m "Update version to $NEXT_VERSION"149git push150 151git checkout master