From f643cfff4f43a3cc81873fb14c7932a9b2486293 Mon Sep 17 00:00:00 2001 From: Nemi Shah Date: Thu, 2 Jun 2022 15:25:56 +0530 Subject: [PATCH] Add dev tag and release tag scripts --- .npmignore | 5 +- addDevTag | 103 +++++++++++++++++++++++++++++++++ addReleaseTag | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 259 insertions(+), 2 deletions(-) create mode 100755 addDevTag create mode 100755 addReleaseTag diff --git a/.npmignore b/.npmignore index 02cb7cd6..d25da771 100644 --- a/.npmignore +++ b/.npmignore @@ -13,10 +13,11 @@ lib/tslint.json addDevTag addReleaseTag frontendDriverInterfaceSupported.json +webJsInterfaceSupported.json .github/ .gitattributes examples/ .prettierignore docs/ -init.sh -tslint-rules/ \ No newline at end of file +tslint-rules/ +.babelrc \ No newline at end of file diff --git a/addDevTag b/addDevTag new file mode 100755 index 00000000..49f2f2d9 --- /dev/null +++ b/addDevTag @@ -0,0 +1,103 @@ +# check if we need to merge master into this branch------------ +if [[ $(git log origin/master ^HEAD) ]]; then + echo "You need to merge master into this branch. Exiting" + exit 1 +fi + +# get version------------ +version=`cat package.json | grep -e '"version":'` + +while IFS='"' read -ra ADDR; do + counter=0 + for i in "${ADDR[@]}"; do + if [ $counter == 3 ] + then + version=$i + fi + counter=$(($counter+1)) + done +done <<< "$version" + +versionLock=`head -n 3 package-lock.json | grep -e '"version":'` + +while IFS='"' read -ra ADDR; do + counter=0 + for i in "${ADDR[@]}"; do + if [ $counter == 3 ] + then + versionLock=$i + fi + counter=$(($counter+1)) + done +done <<< "$versionLock" + +# check if package and package-lock versions are similar.----------- +if ! [[ $version == $versionLock ]] +then + RED='\033[0;31m' + NC='\033[0m' # No Color + printf "${RED}Difference between package-lock and package version. Please run npm install. Stopping process${NC}\n" + exit 1 +fi + +# get current branch name +branch_name="$(git symbolic-ref HEAD 2>/dev/null)" || +branch_name="(unnamed branch)" # detached HEAD +branch_name=${branch_name##refs/heads/} + +# check if branch is correct based on the version----------- +if ! [[ $version == $branch_name* ]] +then + RED='\033[0;31m' + NC='\033[0m' # No Color + printf "${RED}Adding tag to wrong branch. Stopping process${NC}\n" + exit 1 +fi + +#Sync tags with remote +git fetch --prune --prune-tags + +# GET Current Commit Hash ------- +if [ $# -eq 0 ] +then + commit_hash=`git log --pretty=format:'%H' -n 1` +else + commit_hash=$1 +fi + +# check if current commit already has a tag or not------------ +if [[ `git tag -l --points-at $commit_hash` == "" ]] +then + continue=1 +else + RED='\033[0;31m' + NC='\033[0m' + printf "${RED}This commit already has a tag. Please remove that and re-run this script${NC}\n" + echo "git tag --delete " + echo "git push --delete origin " + exit 1 +fi + +# check if release version of this tag exists------------ + +if git rev-parse v$version >/dev/null 2>&1 +then + RED='\033[0;31m' + NC='\033[0m' + printf "${RED}The released version of this tag already exists${NC}\n" + exit 1 +fi + +# add an empty commit if the user has not given a commit hash so that we are sure it's built------------ +if [ $# -eq 0 ] +then + npm run build-pretty + npm run build-docs + git add --all + git commit --allow-empty -m"adding dev-v$version tag to this commit to ensure building" + git push + commit_hash=`git log --pretty=format:'%H' -n 1` +fi + +git tag dev-v$version $commit_hash +git push --tags \ No newline at end of file diff --git a/addReleaseTag b/addReleaseTag new file mode 100755 index 00000000..3c503778 --- /dev/null +++ b/addReleaseTag @@ -0,0 +1,153 @@ +#!/bin/bash +# Expects a releasePassword file to be ./ + +# get version------------ +version=`cat package.json | grep -e '"version":'` +while IFS='"' read -ra ADDR; do + counter=0 + for i in "${ADDR[@]}"; do + if [ $counter == 3 ] + then + version=$i + fi + counter=$(($counter+1)) + done +done <<< "$version" + +branch_name="$(git symbolic-ref HEAD 2>/dev/null)" || +branch_name="(unnamed branch)" # detached HEAD + +branch_name=${branch_name##refs/heads/} + +git fetch --prune --prune-tags + +password=`cat ./apiPassword` + + +# we get from the server is the tests have passed or not. +testPassedJson=`curl -s -X GET \ +"https://api.supertokens.io/0/frontend?password=$password&version=$version&name=web-js" \ +-H 'api-version: 0'` + + +if [[ `echo $testPassedJson | jq .testPassed` == "null" ]] +then + testPassed="false" +else + testPassed=`echo $testPassedJson | jq .testPassed` +fi + +if [[ $testPassed != "true" ]] +then + RED='\033[0;31m' + NC='\033[0m' # No Color + printf "${RED}All tests have not passed. So stopping process.${NC}\n" + exit 1 +fi + +# check that current commit has a dev tag and that it is the correct version +# get current commit hash------------ +if [ $# -eq 0 ] +then + commit_hash=`git log --pretty=format:'%H' -n 1` +else + commit_hash=$1 +fi + + +# check if current commit already has a tag or not------------ +currTag=`git tag -l --points-at $commit_hash` + +expectedCurrTag=dev-v$version + +if [[ $currTag == $expectedCurrTag ]] +then + continue=1 +else + RED='\033[0;31m' + NC='\033[0m' + printf "${RED}This commit does not have the right tag for the version you want to release.${NC}\n" + exit 1 +fi + +releasePassword=`cat ./releasePassword` + +# now we call the patch API to make it release mode +responseStatus=`curl -s -o /dev/null -w "%{http_code}" -X PATCH \ + https://api.supertokens.io/0/frontend \ + -H 'Content-Type: application/json' \ + -H 'api-version: 0' \ + -d "{ + \"password\": \"$releasePassword\", + \"name\":\"web-js\", + \"version\":\"$version\", + \"release\": true + }"` + +if [ $responseStatus -ne "200" ] +then + RED='\033[0;31m' + NC='\033[0m' + printf "${RED}patch api failed. Please try again.${NC}\n" + exit 1 +fi + +git tag --delete $currTag +git push --delete origin $currTag + +git tag v$version +git push --tags + + +response=`curl -s -X GET \ +"https://api.supertokens.io/0/frontend/latest/check?password=$password&version=$version&name=web-js" \ +-H 'api-version: 0'` +response=`echo $response | jq .isLatest` + + +if [[ $response == "null" ]] +then + RED='\033[0;31m' + NC='\033[0m' + printf "${RED}error while determining if we should push to master or not. Please do so manually if needed:${NC}\n" + if [[ $branch_name == "(unnamed branch)" ]] + then + echo "git checkout -b forrelease" + echo "git merge master" + echo "git checkout master" + echo "git merge forrelease" + echo "git push" + echo "git checkout forrelease" + exit 1 + else + echo "git merge master" + echo "git checkout master" + echo "git merge $branch_name" + echo "git push" + echo "git checkout $branch_name" + exit 1 + fi + +fi + +if [[ $response == "true" ]] +then + echo "pushing to master..." + if [[ $branch_name == "(unnamed branch)" ]] + then + git checkout -b forrelease + git merge master + git checkout master + git merge forrelease + git push + git checkout forrelease + echo "Done! Please delete this branch" + else + git merge master + git checkout master + git merge $branch_name + git push + git checkout $branch_name + echo "Done!" + fi +fi \ No newline at end of file