Last active
February 19, 2024 08:23
-
-
Save dpilafian/7194d9ee6315b843f20c0b854a2ef4f8 to your computer and use it in GitHub Desktop.
Shell functions to support running project tasks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
############### | |
# Task Runner # | |
# WTFPL # | |
############### | |
# To make this file runnable: | |
# $ chmod +x *.sh.command | |
banner="Task Runner" | |
projectHome=$(cd $(dirname $0); pwd) | |
pkgInstallHome=$(dirname $(dirname $(which httpd))) | |
apacheCfg=$pkgInstallHome/etc/httpd | |
apacheLog=$pkgInstallHome/var/log/httpd/error_log | |
webDocRoot=$(grep ^DocumentRoot $apacheCfg/httpd.conf | awk -F'"' '{ print $2 }') | |
setupTools() { | |
cd $projectHome | |
echo | |
echo $banner | |
echo $(echo $banner | sed s/./=/g) | |
pwd | |
test -d .git && git restore dist/* && git pull --ff-only | |
echo | |
echo "Node.js:" | |
which node || { echo "Need to install Node.js: https://nodejs.org"; exit; } | |
node --version | |
npm install --no-fund | |
npm update | |
npm outdated | |
echo | |
} | |
releaseInstructions() { | |
cd $projectHome | |
repository=$(grep repository package.json | awk -F'"' '{print $4}' | sed s/github://) | |
package=https://raw.githubusercontent.com/$repository/main/package.json | |
version=v$(grep '"version"' package.json | awk -F'"' '{print $4}') | |
pushed=v$(curl --silent $package | grep '"version":' | awk -F'"' '{print $4}') | |
released=$(git tag | tail -1) | |
published=v$(npm view $repository version) | |
minorVersion=$(echo ${pushed:1} | awk -F"." '{ print $1 "." $2 }') | |
echo "Local changes:" | |
git status --short | |
echo | |
echo "Recent releases:" | |
git tag | tail -5 | |
echo | |
echo "Release progress:" | |
echo " $version (local) --> $pushed (pushed) --> $released (released) --> $published (published)" | |
echo | |
test "$version" ">" "$released" && mode="NOT released" || mode="RELEASED" | |
echo "Current version is: $mode" | |
echo | |
nextActionBump() { | |
echo "When ready to do the next release:" | |
echo | |
echo " === Increment version ===" | |
echo " Edit pacakge.json to bump $version to next version number" | |
echo " $projectHome/package.json" | |
} | |
nextActionCommitTagPub() { | |
echo "Verify all tests pass and then finalize the release:" | |
echo | |
echo " === Commit and push ===" | |
echo " Check in all changed files with the message:" | |
echo " Release $version" | |
echo | |
echo " === Tag and publish ===" | |
echo " cd $projectHome" | |
echo " git tag --annotate --message 'Release' $version" | |
echo " git remote --verbose" | |
echo " git push origin --tags" | |
echo " npm publish" | |
} | |
test "$version" ">" "$released" && nextActionCommitTagPub || nextActionBump | |
echo | |
} | |
buildProject() { | |
cd $projectHome | |
echo "Build and run specs:" | |
npm test | |
echo | |
} | |
setupWebServer() { | |
cd $projectHome | |
port=$(grep web-server package.json | sed 's/[^0-9]*\([0-9]*\).*/\1/') #extract port number from script | |
echo "Web Server (http-party/http-server on node):" | |
npm run web-server | |
sleep 2 #ensure pid is ready to read | |
echo "To stop web server:" | |
echo " $ lsof -P -i :$port" | |
echo " $ kill $(lsof -Pt -i :$port)" | |
echo | |
} | |
publishWebFiles() { | |
cd $projectHome | |
publishSite=$webDocRoot/centerkey.com | |
publishFolder=$webDocRoot/[TARGET-FOLDER] | |
publish() { | |
echo "Publishing:" | |
echo $publishFolder | |
cp -v [SOURCE-FILES] $publishFolder | |
echo | |
} | |
test -w $publishSite && publish | |
} | |
setupTools | |
releaseInstructions | |
setupWebServer | |
buildProject | |
publishWebFiles |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment