Last active
April 11, 2021 06:41
-
-
Save edmondburnett/8c947b6f5201ab22b7ce8389c6feedef to your computer and use it in GitHub Desktop.
Auto-update internal library dependecies for microservices in a Python monorepo, w/Poetry.
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
#!/usr/bin/env bash | |
# Check for file changes in internal libraries local to a monorepo, increment | |
# the lib's minor version number, and auto-update them before running the | |
# current project/service's dev app/server. Assumes usage of poetry's | |
# pyproject.toml and a repository structure similar to that described in this | |
# Opendoor article: https://medium.com/opendoor-labs/our-python-monorepo-d34028f2b6fa | |
REPONAME=myproject | |
LIBSPATH=~/dev/$REPONAME/lib | |
# declare -a EXTENSIONS=( | |
# "*.py" | |
# "*.toml" | |
# ) | |
# Find all internal libs in pyproject.toml and append to an array. | |
# Adjust pathing for your local/internal lib directory. | |
declare -a LIBRARIES=() | |
LIBS_STRING=$(grep -F "../../lib/" pyproject.toml | sed 's/ .*//') | |
while read -r line; do | |
LIBRARIES+=("$line") | |
done <<< "$LIBS_STRING" | |
# check for any code changes in any internal libs and update them | |
for lib in "${LIBRARIES[@]}" | |
do | |
echo "Checking for changes in $lib ..." | |
LIBPATH=$LIBSPATH/$lib | |
shasum -s -q -c $LIBPATH/.checksum | |
exitcode=$? | |
if [ $exitcode -ne 0 ] || [ ! -f $LIBPATH/.checksum ]; then | |
# increment the final version number, i.e. 0.1.20 becomes 0.1.21 | |
perl -i -pe 's/\bversion = "[^"]*\K\b(\d+)(?=[^"]*")/$1+1/e' $LIBPATH/pyproject.toml | |
# TODO: search array of extensions, exclude unecessary ones | |
find $LIBPATH/ -type f \( -iname \*.py -o -iname \*.toml \) ! -path '*.venv/*' -exec shasum {} \; > $LIBPATH/.checksum | |
poetry update $lib | |
fi | |
done | |
# execute local dev app or service | |
uvicorn apiserver:app --reload |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment