diff --git a/please b/please index e78507a..a908c40 100755 --- a/please +++ b/please @@ -12,8 +12,8 @@ set -e declare -A EVENTS -FULL=`readlink -f $0` # fullpath -PLIZ=`basename $0` # name +FULL=$(readlink -f $0) # fullpath +PLIZ=$(basename $0) # name line() { echo -e "\e[${3:-0};$2m$1\e[0m"; if [[ "$4" != "" ]]; then exit $4; fi } error() { line "$1" 31 0 $2; } @@ -26,10 +26,10 @@ qgit() { git "$@" &>> $TMP_LOG; } # github api github() { - RESP=`bash -c "curl --silent -H 'Authorization: token $GH_AUTH_TOKEN' $@"` + RESP=$(bash -c "curl --silent -H 'Authorization: token $GH_AUTH_TOKEN' $@") echo "$RESP" >> ${TMP_LOG} - ERROR=`echo $RESP | jq -r '.message?'` + ERROR=$(echo $RESP | jq -r '.message?') [[ $ERROR ]] && [[ "null" != "$ERROR" ]] && error "Github: $ERROR" 1 echo "$RESP" @@ -39,7 +39,7 @@ github() usage() { cat << USAGE -$PLIZ $(info `version`) | $(ok "(c) Jitendra Adhikari") | $PLIZ is semver release made easy. +$PLIZ $(info $(version)) | $(ok "(c) Jitendra Adhikari") | $PLIZ is semver release made easy. $(ok Usage:) $PLIZ [command|scope] [--options] @@ -104,9 +104,9 @@ organize-commits() # $1 = diff_range, $2 = commit_types_csv if [[ "$scope" != "" ]]; then scope="**${scope^}**: "; fi CHANGELOG[$type]="${CHANGELOG[$type]}- ${scope}${subject^}\n" fi - done <<< `git log $1 --no-merges --oneline --pretty="$GCFMT" --grep "\[skip" --grep "skip\]" --grep "StyleCI" --invert-grep` + done <<< $(git log $1 --no-merges --oneline --pretty="$GCFMT" --grep "\[skip" --grep "skip\]" --grep "StyleCI" --invert-grep) - ORGANIZED="" TYPES=(`echo ${2:-feat,fix,refactor,revert,perf,chore,infra,docs,build} | tr ',' '\n'`) + ORGANIZED="" TYPES=($(echo ${2:-feat,fix,refactor,revert,perf,chore,infra,docs,build} | tr ',' '\n')) for TYPE in ${TYPES[@]}; do if [[ "${CHANGELOG[$TYPE]}" != "" ]]; then ORGANIZED="$ORGANIZED### ${LABELS[$TYPE]}\n${CHANGELOG[$TYPE]}\n" @@ -118,7 +118,7 @@ organize-commits() # $1 = diff_range, $2 = commit_types_csv # update please update() { - NEWVER=`curl -sSL https://raw.githubusercontent.com/adhocore/please/master/VERSION` + NEWVER=$(curl -sSL https://raw.githubusercontent.com/adhocore/please/master/VERSION) [[ "v$NEWVER" == "$(version)" ]] && ok "Already latest version" 0 info "Updating $PLIZ ..." @@ -131,7 +131,7 @@ version() { echo v0.10.3; } # get box.phar path get-box() { - case `php -r "echo substr(phpversion(), 0, 3);"` in + case $(php -r "echo substr(phpversion(), 0, 3);") in 7.2 | 7.3 | 7.4) BOX_VER=3.8.0 ;; 7.1) BOX_VER=3.7.0 ;; 7.0 | 5.6 | 5.5 | 5.4 | 5.3) BOX_VER=2.7.5 ;; @@ -146,30 +146,30 @@ get-box() fi fi - echo `realpath ~/box.$BOX_VER.phar` + echo $(realpath ~/box.$BOX_VER.phar) } # publish phar publish-phar() { - PBIN=`cat composer.json | jq -r '.bin[0]?'` + PBIN=$(cat composer.json | jq -r '.bin[0]?') if [ "null" == "$PBIN" ]; then info "Check ${TMP_LOG} for logs" && error "Check bin value in composer.json" 1 fi trigger before-phar info "Compiling phar ..." - php `get-box` compile >> ${TMP_LOG} + php $(get-box) compile >> ${TMP_LOG} ok - PHAR_FILE=`realpath $PBIN.phar` NAME=`basename $PHAR_FILE` + PHAR_FILE=$(realpath $PBIN.phar) NAME=$(basename $PHAR_FILE) info "Publishing phar ..." - SIZE=`github \ + SIZE=$(github \ "-H 'Content-Type: application/octet-stream' \ --data-binary @$PHAR_FILE \ https://uploads.$GH_REPO/releases/$LAST_RELEASE_ID/assets?name=$NAME" \ - | jq -r '.size'` + | jq -r '.size') ok info "[OK] $NAME $SIZE bytes" } @@ -177,7 +177,7 @@ publish-phar() # publish npm publish-npm() { - PKG=`cat ./package.json` PVT=`echo $PKG | jq -r '.private?'` + PKG=$(cat ./package.json) PVT=$(echo $PKG | jq -r '.private?') echo $PKG | jq ".version = \"$NEXT_VERSION\"" > ./package.json qgit add ./package.json && GPUSH=1 @@ -207,7 +207,7 @@ trigger() # $1 = event } GCFMT="%s (%an)" # git commit log format -REPO=`git config --get remote.origin.url | sed -e 's/git@github.com://;s/https:\/\/github.com\///;s/.git//'` +REPO=$(git config --get remote.origin.url | sed -e 's/git@github.com://;s/https:\/\/github.com\///;s/.git//') # load events [[ -f ./please.json ]] && eval $(cat ./please.json | jq -r 'to_entries|map("EVENTS[\(.key)]=\"\(.value)\"")|.[]') @@ -242,7 +242,7 @@ VFILE=${VFILE:-0} # create version file CHLOG=${CHLOG:-0} # create changelog file YES=${YES:-0} # assume yes -GH_REPO="github.com/repos/$REPO" TMP_LOG=`mktemp -t PLZ.XXXXXXXXXX` +GH_REPO="github.com/repos/$REPO" TMP_LOG=$(mktemp -t PLZ.XXXXXXXXXX) ok "Repository $REPO" && info "Log file $TMP_LOG" DEPLOY_BRANCH="${DEPLOY_BRANCH:-master}" @@ -258,14 +258,14 @@ else fi info "Getting latest releases ..." -VERSION=`github "https://api.$GH_REPO/releases?per_page=1" | jq -r '.[0]?.tag_name?'` +VERSION=$(github "https://api.$GH_REPO/releases?per_page=1" | jq -r '.[0]?.tag_name?') RANGE="$VERSION..HEAD" [[ "null" == "$VERSION" ]] && { VERSION="0.0.0" RANGE=""; } ok " Done [$VERSION]" info "Collecting commits ..." -COMMITS=`organize-commits "$RANGE" "$TYPES"` +COMMITS=$(organize-commits "$RANGE" "$TYPES") ok [[ $COMMITS ]] || error "Nothing to release" 0 @@ -275,19 +275,19 @@ echo $COMMITS >> $TMP_LOG # determine next version info "Bumping version ..." if [[ "" = "$NEXT_VERSION" ]]; then - FEAT=`git log $RANGE --oneline --pretty="%s" | grep -P '^feat' || echo ""` + FEAT=$(git log $RANGE --oneline --pretty="%s" | grep -P '^feat' || echo "") if [[ $MAJOR -eq 1 ]]; then V="" if [[ $VERSION == v* ]]; then V="v" VERSION="${VERSION//v/}" fi - NEXT_VERSION=`echo $VERSION | (IFS=".$IFS"; read a b c && echo $V$((a + 1)).0.0)` + NEXT_VERSION=$(echo $VERSION | (IFS=".$IFS"; read a b c && echo $V$((a + 1)).0.0)) elif [[ $MINOR -eq 1 ]]; then - NEXT_VERSION=`echo $VERSION | (IFS=".$IFS"; read a b c && echo $a.$((b + 1)).0)` + NEXT_VERSION=$(echo $VERSION | (IFS=".$IFS"; read a b c && echo $a.$((b + 1)).0)) elif [[ "" != "$FEAT" ]]; then - NEXT_VERSION=`echo $VERSION | (IFS=".$IFS"; read a b c && echo $a.$((b + 1)).0)` + NEXT_VERSION=$(echo $VERSION | (IFS=".$IFS"; read a b c && echo $a.$((b + 1)).0)) else - NEXT_VERSION=`echo $VERSION | (IFS=".$IFS"; read a b c && echo $a.$b.$((c + 1)))` + NEXT_VERSION=$(echo $VERSION | (IFS=".$IFS"; read a b c && echo $a.$b.$((c + 1)))) fi fi ok " Done [$NEXT_VERSION]" @@ -333,12 +333,12 @@ fi # github release trigger before-vcs info "Releasing $NEXT_VERSION ..." -COMMITS=`printf %s "$COMMITS"` -LAST_RELEASE_ID=`curl --silent -H "Authorization: token $GH_AUTH_TOKEN" \ +COMMITS=$(printf %s "$COMMITS") +LAST_RELEASE_ID=$(curl --silent -H "Authorization: token $GH_AUTH_TOKEN" \ -H 'Content-Type: application/json' \ -d "{\"tag_name\":\"$NEXT_VERSION\",\"name\":\"Version $NEXT_VERSION\",\"body\":\"$COMMITS\"}" \ https://api.$GH_REPO/releases \ - | jq -r '.id?'` + | jq -r '.id?') if [ "null" == "${LAST_RELEASE_ID:-null}" ]; then error "Something went wrong" && info "Check $TMP_LOG for logs" 1