diff --git a/pre-commit_semantic-release.sh b/pre-commit_semantic-release.sh index 9d34d74c..ba805352 100755 --- a/pre-commit_semantic-release.sh +++ b/pre-commit_semantic-release.sh @@ -14,9 +14,9 @@ sed -i -e "s_^\(version:\).*_\1 ${1}_" FORMULA sudo -H pip install m2r # Copy and then convert the `.md` docs -cp *.md docs/ -cd docs/ -m2r --overwrite *.md +cp ./*.md docs/ +cd docs/ || exit +m2r --overwrite ./*.md # Change excess `H1` headings to `H2` in converted `CHANGELOG.rst` sed -i -e '/^=.*$/s/=/-/g' CHANGELOG.rst diff --git a/ssf/files/default/git/git_10_prepare.sh b/ssf/files/default/git/git_10_prepare.sh index 032d5378..52b1794d 100755 --- a/ssf/files/default/git/git_10_prepare.sh +++ b/ssf/files/default/git/git_10_prepare.sh @@ -14,23 +14,23 @@ COMMENT='Command `'${STATE}'` run' # Check if PR branch already exists BRANCH=$(git branch -l "${BRANCH_PR}") COMMIT= -if [ ! -z "${BRANCH}" ]; then - git checkout ${BRANCH_PR} +if [ -n "${BRANCH}" ]; then + git checkout "${BRANCH_PR}" # This may end up as blank as well, so that's why a separate `if` is required below COMMIT=$(git log -n1 | grep "${COMMIT_GREP}") fi # Perform actions depending on if a commit was found or not -if [ ! -z "${COMMIT}" ]; then +if [ -n "${COMMIT}" ]; then CHANGED='False' else - git checkout ${BRANCH_UPSTREAM} + git checkout "${BRANCH_UPSTREAM}" git pull git status # If the branch existed but not the commit, assume the branch is stale (i.e. previous PR merged) # Remove it, ready to be recreated at the latest upstream commit - if [ ! -z "${BRANCH}" ]; then - git branch -d ${BRANCH_PR} + if [ -n "${BRANCH}" ]; then + git branch -d "${BRANCH_PR}" fi # TODO: Improve this part, should be able to remove with the duplication with the right solution # Don't want to resort to using `git branch -D` above, since that could be premature in certain situations @@ -40,8 +40,10 @@ else if [ -z "${BRANCH}" ]; then NEW_BRANCH='-b' fi - git checkout ${NEW_BRANCH} ${BRANCH_PR} - git merge ${BRANCH_UPSTREAM} + # Disabling `SC2086` where double-quoting an empty variable introduces an error + # shellcheck disable=SC2086 + git checkout ${NEW_BRANCH} "${BRANCH_PR}" + git merge "${BRANCH_UPSTREAM}" fi # Write the state line diff --git a/ssf/files/default/git/git_20_commit_push.sh b/ssf/files/default/git/git_20_commit_push.sh index ec1f4aaa..5f6fa3d2 100755 --- a/ssf/files/default/git/git_20_commit_push.sh +++ b/ssf/files/default/git/git_20_commit_push.sh @@ -10,10 +10,11 @@ COMMIT_GREP=${4} COMMIT_TITLE=${5} COMMIT_BODY=${6} COMMIT_OPTIONS=${7} -PUSH_ACTIVE=$(echo ${8} | tr "[:upper:]" "[:lower:]") -PUSH_VIA_PR=$(echo ${9} | tr "[:upper:]" "[:lower:]") +PUSH_ACTIVE=$(echo "${8}" | tr "[:upper:]" "[:lower:]") +PUSH_VIA_PR=$(echo "${9}" | tr "[:upper:]" "[:lower:]") REMOTE_FORK_NAME=${10} -REMOTE_FORK_BRANCH=${11} +# Currently unused but leaving here as a placeholder +# REMOTE_FORK_BRANCH=${11} REMOTE_UPSTREAM_NAME=${12} REMOTE_UPSTREAM_BRANCH=${13} # Prepare initial state line variables @@ -22,7 +23,7 @@ COMMENT='Command `'${STATE}'` run' # Prepare git options depending on if a commit was found or not COMMIT=$(git log -n1 | grep "${COMMIT_GREP}") -if [ ! -z "${COMMIT}" ]; then +if [ -n "${COMMIT}" ]; then AMEND='--amend' FORCE='-f' else @@ -31,15 +32,18 @@ else fi # Perform actions +# Disabling `SC2086` where double-quoting an empty variable introduces errors +# shellcheck disable=SC2086 git commit ${AMEND} "${COMMIT_OPTIONS}" -m "${COMMIT_TITLE}" -m "${COMMIT_BODY}" if ${PUSH_ACTIVE}; then if ${PUSH_VIA_PR}; then - git push ${FORCE} -u ${REMOTE_FORK_NAME} ${BRANCH_PR} + # shellcheck disable=SC2086 + git push ${FORCE} -u "${REMOTE_FORK_NAME}" "${BRANCH_PR}" else - git checkout ${BRANCH_UPSTREAM} - git merge ${BRANCH_PR} - git push ${REMOTE_UPSTREAM_NAME} HEAD:${REMOTE_UPSTREAM_BRANCH} - git branch -d ${BRANCH_PR} + git checkout "${BRANCH_UPSTREAM}" + git merge "${BRANCH_PR}" + git push "${REMOTE_UPSTREAM_NAME}" "HEAD:${REMOTE_UPSTREAM_BRANCH}" + git branch -d "${BRANCH_PR}" fi fi diff --git a/ssf/files/default/git/git_30_create_PR.sh b/ssf/files/default/git/git_30_create_PR.sh index e0c63e60..8e255ef3 100755 --- a/ssf/files/default/git/git_30_create_PR.sh +++ b/ssf/files/default/git/git_30_create_PR.sh @@ -22,18 +22,18 @@ COMMENT='Command `'${STATE}'` run' # Only create the PR if it doesn't already exist # If it already exists, the `git push` done earlier will have updated the PR already -PR_EXISTS=$(curl -i https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/pulls | grep "${GH_USER}:${BRANCH_PR}") -if [ ! -z "${PR_EXISTS}" ]; then +PR_EXISTS=$(curl -i "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/pulls" | grep "${GH_USER}:${BRANCH_PR}") +if [ -n "${PR_EXISTS}" ]; then CHANGED='False' else curl -H "Authorization: bearer ${GH_TOKEN}" -d ' { "title": "'"${COMMIT_TITLE}"'", "body": "'"${COMMIT_BODY}"'", - "head": "'${GH_USER}':'${BRANCH_PR}'", - "base": "'${REPO_BRANCH}'" + "head": "'"${GH_USER}"':'"${BRANCH_PR}"'", + "base": "'"${REPO_BRANCH}"'" } - ' https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/pulls >> ${FILE_API_RESPONSE} + ' "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/pulls" >> "${FILE_API_RESPONSE}" fi # Write the state line diff --git a/ssf/files/default/pre-commit_semantic-release.sh b/ssf/files/default/pre-commit_semantic-release.sh index 9d34d74c..ba805352 100755 --- a/ssf/files/default/pre-commit_semantic-release.sh +++ b/ssf/files/default/pre-commit_semantic-release.sh @@ -14,9 +14,9 @@ sed -i -e "s_^\(version:\).*_\1 ${1}_" FORMULA sudo -H pip install m2r # Copy and then convert the `.md` docs -cp *.md docs/ -cd docs/ -m2r --overwrite *.md +cp ./*.md docs/ +cd docs/ || exit +m2r --overwrite ./*.md # Change excess `H1` headings to `H2` in converted `CHANGELOG.rst` sed -i -e '/^=.*$/s/=/-/g' CHANGELOG.rst