|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +ghtoken=`cat ~/.keys/gh_access_token` |
| 4 | +repoOwnerAndName=redhat-developer/vscode-server-connector |
| 5 | +argsPassed=$# |
| 6 | +echo "args: " $argsPassed |
| 7 | +if [ "$argsPassed" -eq 1 ]; then |
| 8 | + debug=1 |
| 9 | + echo "YOU ARE IN DEBUG MODE. Changes will NOT be pushed upstream" |
| 10 | +else |
| 11 | + echo "The script is live. All changes will be pushed, deployed, etc. Live." |
| 12 | + debug=0 |
| 13 | +fi |
| 14 | +read -p "Press enter to continue" |
| 15 | + |
| 16 | + |
| 17 | +apiStatus=`git status -s | wc -l` |
| 18 | +if [ $apiStatus -ne 0 ]; then |
| 19 | + echo "This repository has changes and we won't be able to auto upversion. Please commit or stash your changes and try again" |
| 20 | + exit 1 |
| 21 | +fi |
| 22 | + |
| 23 | +echo "" |
| 24 | +echo "These are the commits for the release" |
| 25 | +commits=`git lg | grep -n -m 1 "Upversion to " |sed 's/\([0-9]*\).*/\1/' | tail -n 1` |
| 26 | +commitMsgs=`git log --color --pretty=format:'%h - %s' --abbrev-commit | head -n $commits` |
| 27 | +echo "$commitMsgs" |
| 28 | +read -p "Press enter to continue" |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +echo "Let's just run some builds and stuff" |
| 33 | +read -p "Press enter to continue" |
| 34 | + |
| 35 | +npm install |
| 36 | +npm run build |
| 37 | +echo "Did the build work? If yes, let's package it" |
| 38 | +read -p "Press enter to continue" |
| 39 | + |
| 40 | +vsce package |
| 41 | +echo "Did the package work?" |
| 42 | +read -p "Press enter to continue" |
| 43 | + |
| 44 | + |
| 45 | +echo "Old version is $oldver" |
| 46 | +echo "Let's tag the release" |
| 47 | + |
| 48 | +oldver=`cat package.json | grep "\"version\":" | cut -f 2 -d ":" | sed 's/"//g' | sed 's/,//g' | awk '{$1=$1};1'` |
| 49 | +oldVerUnderscore=`echo $oldver | sed 's/\./_/g'` |
| 50 | +vOldVerUnderscoreFinal=v$oldVerUnderscore.Final |
| 51 | +git tag v$oldVerUnderscore.Final |
| 52 | +if [ "$debug" -eq 0 ]; then |
| 53 | + git push origin $vOldVerUnderscoreFinal |
| 54 | +else |
| 55 | + echo git push origin $vOldVerUnderscoreFinal |
| 56 | +fi |
| 57 | + |
| 58 | +echo "We've tagged." |
| 59 | +echo "Now we should actually create some releases" |
| 60 | + |
| 61 | +oldVerFinal=$oldver.Final |
| 62 | +echo "Making a release on github for $oldVerFinal" |
| 63 | +commitMsgsClean=`git log --color --pretty=format:'%s' --abbrev-commit | head -n $commits | awk '{ print " * " $0;}' | awk '{printf "%s\\\\n", $0}' | sed 's/"/\\"/g'` |
| 64 | +createReleasePayload="{\"tag_name\":\"$oldVerFinal\",\"target_commitish\":\"master\",\"name\":\"$oldVerFinal\",\"body\":\"Release of $oldVerFinal:\n\n"$commitMsgsClean"\",\"draft\":false,\"prerelease\":false,\"generate_release_notes\":false}" |
| 65 | + |
| 66 | +if [ "$debug" -eq 0 ]; then |
| 67 | + curl -L \ |
| 68 | + -X POST \ |
| 69 | + -H "Accept: application/vnd.github+json" \ |
| 70 | + -H "Authorization: Bearer $ghtoken"\ |
| 71 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 72 | + https://api.github.com/repos/$repoOwnerAndName/releases \ |
| 73 | + -d "$createReleasePayload" | tee createReleaseResponse.json |
| 74 | +else |
| 75 | + echo curl -L \ |
| 76 | + -X POST \ |
| 77 | + -H "Accept: application/vnd.github+json" \ |
| 78 | + -H "Authorization: Bearer $ghtoken"\ |
| 79 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 80 | + https://api.github.com/repos/$repoOwnerAndName/releases \ |
| 81 | + -d "$createReleasePayload" |
| 82 | +fi |
| 83 | + |
| 84 | +echo "Please go verify the release looks correct. We will add the asset next" |
| 85 | +read -p "Press enter to continue" |
| 86 | + |
| 87 | +assetUrl=`cat createReleaseResponse.json | grep assets_url | cut -c 1-17 --complement | rev | cut -c3- | rev | sed 's/api.github.com/uploads.github.com/g'` |
| 88 | +rm createReleaseResponse.json |
| 89 | +zipFileName=` ls -1 -t *.vsix | head -n 1` |
| 90 | +echo "Running command to add artifact to release: " |
| 91 | + echo curl -L \ |
| 92 | + -X POST \ |
| 93 | + -H "Accept: application/vnd.github+json" \ |
| 94 | + -H "Authorization: Bearer $ghtoken"\ |
| 95 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 96 | + -H "Content-Type: application/octet-stream" \ |
| 97 | + $assetUrl?name=$zipFileName \ |
| 98 | + --data-binary "@$zipFileName" |
| 99 | +if [ "$debug" -eq 0 ]; then |
| 100 | + curl -L \ |
| 101 | + -X POST \ |
| 102 | + -H "Accept: application/vnd.github+json" \ |
| 103 | + -H "Authorization: Bearer $ghtoken"\ |
| 104 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 105 | + -H "Content-Type: application/octet-stream" \ |
| 106 | + $assetUrl?name=$zipFileName \ |
| 107 | + --data-binary "@$zipFileName" |
| 108 | +fi |
| 109 | +echo "" |
| 110 | +echo "Please go verify the release looks correct and the distribution was added correctly." |
| 111 | +read -p "Press enter to continue" |
| 112 | + |
| 113 | +echo "Now we need to upversion" |
| 114 | +newLastSegment=`echo $oldver | cut -f 3 -d "." | awk '{ print $0 + 1;}' | bc` |
| 115 | +newverPrefix=`echo $oldver | cut -f 1,2 -d "."` |
| 116 | +newver=$newverPrefix.$newLastSegment |
| 117 | +echo "New version is $newver" |
| 118 | + |
| 119 | +echo "Updating package.json with new version" |
| 120 | +cat package.json | sed "s/ \"version\": \"$oldver\",/ \"version\": \"$newver\",/g" > package2 |
| 121 | +mv package2 package.json |
| 122 | +echo "Running npm install" |
| 123 | +npm install |
| 124 | + |
| 125 | +echo "Committing and pushing to main" |
| 126 | +git commit -a -m "Upversion to $newver - Development Begins" --signoff |
| 127 | + |
| 128 | +curBranch=`git rev-parse --abbrev-ref HEAD` |
| 129 | +if [ "$debug" -eq 0 ]; then |
| 130 | + git push origin $curBranch |
| 131 | +else |
| 132 | + echo git push origin $curBranch |
| 133 | +fi |
| 134 | + |
| 135 | + |
| 136 | + |
0 commit comments