Skip to content

Instantly share code, notes, and snippets.

@sramam
Created April 25, 2020 23:52
Show Gist options
  • Save sramam/2183bfaf507b2851341df7ba9520c7a5 to your computer and use it in GitHub Desktop.
Save sramam/2183bfaf507b2851341df7ba9520c7a5 to your computer and use it in GitHub Desktop.
Automated update and publish procedure
#!/usr/bin/env sh
banner()
{
echo "+------------------------------------------+"
printf "| %-40s |\n" "`date`"
echo "| |"
printf "|`tput bold` %-40s `tput sgr0`|\n" "$@"
echo "+------------------------------------------+"
}
function macOsPrompt() {
osascript <<EOT
button returned of (display alert "Await CI build '$1'" message "$2" as critical buttons {"Waiting", "Build Failure", "Build Success"} default button "Waiting")
EOT
echo $ret
}
function waitForCIBuild() {
local gitRepo=$( basename `pwd`)
local alertTitle="${gitRepo}"
local actionsUrl="https://github.com/tufan-io/$gitRepo/actions?query=workflow%3Aaction-ci"
local alertMessage="Build status:\n$actionsUrl"
local selection="Waiting"
while [ "$selection" == "Waiting" ]
do
echo "$alertTitle: $actionsUrl"
selection=$( macOsPrompt "$alertTitle" "$alertMessage" )
done
echo "$selection"
}
function updateAndBuild() {
local dir=$1
local gitRepo=$2
local cwd=`pwd`
cd $dir
echo "\n====== <$( basename `pwd` )> ======"
echo `pwd`
local gitStatus1=$( git status -s 2>&1 )
if [ -z "$gitStatus1" ]
then
banner "Starting upgrade '$gitRepo'"
# repo is clean. We can attempt to check for and apply dependency updates
npm run sort-package-json
npm upgrade
npm run no-circular-deps
local gitStatus2=$( git status -s 2>&1 )
if [ -z "$gitStatus2" ]
then
# no modifications, we can break here to continue after else segment
break;
else
banner "build+test upgrades locally '$gitRepo'"
# we have updates and/or modifications to package.json
# first, we'll run a local build to make sure things pass.
git add .
npm run build
git commit -m "chore: updating dependencies"
git push # this will trigger a CI build, all platforms
banner "Await CI build '$gitRepo'"
const ciStatus=waitForCIBuild
# following process described here:
# https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-cli#with-npm-version
echo "ciStatus = $ciStatus"
if [ "$ciStatus" == "BuildSuccess" ]
then
banner "Publish new version '$gitRepo'"
git fetch --all --tags
npm version patch
npm publish
git push
git push origin --tags
else
echo "$ciStatus. Aborting update sequence at '${gitRepo}'"
exit -1
fi
fi
else
echo "---"
echo `pwd`
git status -s
echo "Please commit changes before proceeding"
fi
echo `pwd`
echo "\n====== </$( basename `pwd` )> ======\n"
cd $cwd
}
set -x # echo commands without expanding
cd /Users/sramam/trial/poc/meta/meta-tufan-cli/modules
updateAndBuild simple-ci simple-ci
# function noMods() {
# local output=$( git status -s 2>&1 )
# if [ -z "$output" ]
# then
# ($1)
# shift
# ($@)
# else
# echo "---"
# echo `pwd`
# git status -s
# echo "Please commit changes before proceeding"
# # previous mods exist
# break
# fi
# }
# function ifMods() {
# echo "ifMods"
# local output=$( git status -s 2>&1 )
# if [ -z "$output" ]
# then
# echo "---"
# echo `pwd`
# echo "Module is current. No updates needed"
# # output is empty - no changes were detected
# break
# else
# ($@)
# fi
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment