From 309ea0bae9ce964a574ff8d73bb414213838b888 Mon Sep 17 00:00:00 2001 From: Aaron Holmes Date: Wed, 18 Oct 2023 14:36:26 -0700 Subject: [PATCH] Add script to build and publish packages. --- publish_all.sh | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100755 publish_all.sh diff --git a/publish_all.sh b/publish_all.sh new file mode 100755 index 00000000..097553bc --- /dev/null +++ b/publish_all.sh @@ -0,0 +1,95 @@ +#!/bin/bash +set -eEo pipefail + +spinwait_pid= +spinwait_col= +spinwait() { + IFS=';' + # inspiration https://unix.stackexchange.com/a/183121 + read -sdR -p $'\E[6n' spinwait_row spinwait_col + spinwait_row="${spinwait_row#*[}" + + s=(\| / - \\) + i=0 + while true; do + tput cup $((spinwait_row-1)) $spinwait_col 2> /dev/null + echo -en " ${s[i]}"; i=$(( (i + 1) % ${#s[@]})) + sleep 0.2 + done & + spinwait_pid=$! +} +spinwait-stop() { + optional_msg=$1 + kill $spinwait_pid 2> /dev/null + tput cup $((spinwait_row-1)) $spinwait_col 2> /dev/null + [ -n "$optional_msg" ] && echo -e " $optional_msg" || echo -e " " +} + +project_name= +get-project-name() { + # inspiration https://stackoverflow.com/a/73519411 + project_name=$(awk \ + -F' = ' \ + -v s="project" \ + -v p="name" \ + ' + # process only sections (they start with ^[ ) + /^\[/{ + gsub(/[\[\]]/, "", $1) + f = ($1 == s) + next + } + # print only the value following the ` = ` + # only for the line starting with `name = ` + NF && f && $1==p{ + gsub(/"/, "", $2) + print $2 + }' pyproject.toml) +} + +trap 'spinwait-stop' ERR +trap 'spinwait-stop; exit' SIGINT SIGTERM +build() { + dir="$1" + pushd $dir 1> /dev/null + get-project-name + echo -n Building $project_name + spinwait + python -m build 1> /dev/null + spinwait-stop done + popd 1> /dev/null +} + +publish() { + set +e + local dir="$1" + local repository + [ -n "$2" ] && repository="$2" || repository="testpypi" + pushd $dir 1> /dev/null + get-project-name + echo Publishing $project_name to $repository + python -m twine upload --repository $repository dist/* + popd 1> /dev/null +} + + +build . +build src/AWS +build src/database +build src/development +build src/platform +build src/programming +build src/testing +build src/web + +# default to testpypi +[ -n "$1" ] && repository="$1" || repository="testpypi" + +publish . $repository +publish src/AWS $repository +publish src/database $repository +publish src/development $repository +publish src/platform $repository +publish src/programming $repository +publish src/testing $repository +publish src/web $repository \ No newline at end of file