From 52ff071ad371bdbda7ac8499c7037f7ecdb3aaef Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 25 Feb 2021 09:57:22 -0800 Subject: [PATCH] Update leo-publish CI --- .circleci/leo-publish.sh | 56 +++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/.circleci/leo-publish.sh b/.circleci/leo-publish.sh index 99f4b1bd61..ac0bd0246a 100755 --- a/.circleci/leo-publish.sh +++ b/.circleci/leo-publish.sh @@ -1,19 +1,51 @@ # leo login, publish and logout -$LEO new test-app && cd test-app +# Login $LEO login -u "ALEO_PM_USERNAME" -p "ALEO_PM_PASSWORD" -# sed command below takes 0.1.0 version (which is default for new programs) -# and replaces it with GITHUB_RUN_ID - a unique incremental number for each -# GH Actions run; [AUTHOR] gets replaced with $USER variable; and we're ready -# to publish package with newer version and correct author -cat Leo.toml | sed "s/0.1.0/0.1.$GITHUB_RUN_ID/g" | sed "s/\[AUTHOR\]/$USER/g" > Leo.toml +# Clone the test-app package. +$LEO clone test-app +# Fetch the current Leo package version number. +# +# 1. Print out the Leo.toml file. +# 2. Search for a line with the word "version". +# 3. Isolate that into a single line. +# 4. Split the line from the '=' sign and keep the right-hand side. +# 5. Remove the quotes around the version number. +# 6. Trim any excess whitespace. +export CURRENT=$(cat Leo.toml \ +| grep version \ +| head -1 \ +| awk -F= '{ print $2 }' \ +| sed 's/[",]//g' \ +| xargs) + +# Increment the current Leo package version number by 1. +# +# 1. Print out the Leo.toml file. +# 2. Search for a line with the word "version". +# 3. Isolate that into a single line. +# 4. Split the line from the '=' sign and keep the right-hand side. +# 5. Remove the quotes around the version number. +# 6. Trim any excess whitespace. +# 7. Increment the version number by 1 (on the semver patch). +# +# https://stackoverflow.com/questions/8653126/how-to-increment-version-number-in-a-shell-script +export UPDATED=$(cat Leo.toml \ +| grep version \ +| head -1 \ +| awk -F= '{ print $2 }' \ +| sed 's/[",]//g' \ +| xargs \ +| awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{if(length($NF+1)>length($NF))$(NF-1)++; $NF=sprintf("%0*d", length($NF), ($NF+1)%(10^length($NF))); print}') + +# Write the updated Leo package version number to the Leo.toml file. +export TOML=$(cat Leo.toml | sed "s/$CURRENT/$UPDATED/g") +echo $TOML > Leo.toml + +# Publish the package to Aleo.pm $LEO publish + +# Logout $LEO logout - -mkdir hello-world && cd hello-world || exit 1 -$LEO init -ls -la -$LEO run -