Skip to content

Commit

Permalink
Merge pull request jamulussoftware#2547 from hoffie/autobuild/shellch…
Browse files Browse the repository at this point in the history
…eck-clean

Scripts: Apply shellcheck suggestions
  • Loading branch information
hoffie authored Apr 5, 2022
2 parents e452695 + 06bffcc commit 06cd9a8
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 71 deletions.
2 changes: 1 addition & 1 deletion linux/deploy_deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export DEBFULLNAME=GitHubActions [email protected]
echo -n generating changelog
rm -f debian/changelog
dch --create --package jamulus --empty --newversion "${VERSION}" ''
perl .github/actions_scripts/getChangelog.pl ChangeLog "${VERSION}" --line-per-entry | while read entry
perl .github/actions_scripts/getChangelog.pl ChangeLog "${VERSION}" --line-per-entry | while read -r entry
do
echo -n .
dch "$entry"
Expand Down
82 changes: 46 additions & 36 deletions mac/deploy_mac.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
#!/bin/bash
set -e
set -eu

root_path="$(pwd)"
root_path=$(pwd)
project_path="${root_path}/Jamulus.pro"
resources_path="${root_path}/src/res"
build_path="${root_path}/build"
deploy_path="${root_path}/deploy"
cert_name=""


while getopts 'hs:' flag; do
case "${flag}" in
s)
cert_name=$OPTARG
if [[ -z "$cert_name" ]]; then
echo "Please add the name of the certificate to use: -s \"<name>\""
fi
# shift 2
;;
h)
echo "Usage: -s <cert name> for signing mac build"
exit 0
;;
*)
exit 1
;;

s)
cert_name=$OPTARG
if [[ -z "$cert_name" ]]; then
echo "Please add the name of the certificate to use: -s \"<name>\""
fi
;;
h)
echo "Usage: -s <cert name> for signing mac build"
exit 0
;;
*)
exit 1
;;
esac
done

Expand All @@ -41,10 +38,14 @@ cleanup()

build_app()
{
local client_or_server="${1}"

# Build Jamulus
qmake "${project_path}" -o "${build_path}/Makefile" "CONFIG+=release" ${@:2}
local target_name=$(sed -nE 's/^QMAKE_TARGET *= *(.*)$/\1/p' "${build_path}/Makefile")
local job_count="$(sysctl -n hw.ncpu)"
qmake "${project_path}" -o "${build_path}/Makefile" "CONFIG+=release" "${@:2}"
local target_name
target_name=$(sed -nE 's/^QMAKE_TARGET *= *(.*)$/\1/p' "${build_path}/Makefile")
local job_count
job_count=$(sysctl -n hw.ncpu)

make -f "${build_path}/Makefile" -C "${build_path}" -j "${job_count}"

Expand All @@ -60,35 +61,47 @@ build_app()
make -f "${build_path}/Makefile" -C "${build_path}" distclean

# Return app name for installer image
eval "$1=${target_name}"
case "${client_or_server}" in
client_app)
CLIENT_TARGET_NAME="${target_name}"
;;
server_app)
SERVER_TARGET_NAME="${target_name}"
;;
*)
echo "build_app: invalid parameter '${client_or_server}'"
exit 1
esac
}


build_installer_image()
{
local client_target_name="${1}"
local server_target_name="${2}"

# Install create-dmg via brew. brew needs to be installed first.
# Download and later install. This is done to make caching possible
brew_install_pinned "create-dmg" "1.0.9"

# Get Jamulus version
local app_version="$(sed -nE 's/^VERSION *= *(.*)$/\1/p' "${project_path}")"
local app_version
app_version=$(sed -nE 's/^VERSION *= *(.*)$/\1/p' "${project_path}")

# Build installer image

create-dmg \
--volname "${1} Installer" \
--volname "${client_target_name} Installer" \
--background "${resources_path}/installerbackground.png" \
--window-pos 200 400 \
--window-size 900 320 \
--app-drop-link 820 210 \
--text-size 12 \
--icon-size 72 \
--icon "${1}.app" 630 210 \
--icon "${2}.app" 530 210 \
--icon "${client_target_name}.app" 630 210 \
--icon "${server_target_name}.app" 530 210 \
--eula "${root_path}/COPYING" \
"${deploy_path}/$1-${app_version}-installer-mac.dmg" \
"${deploy_path}/${client_target_name}-${app_version}-installer-mac.dmg" \
"${deploy_path}/"

}

brew_install_pinned() {
Expand All @@ -114,16 +127,13 @@ brew_install_pinned() {
popd
}


# Check that we are running from the correct location
if [ ! -f "${project_path}" ];
then
echo Please run this script from the Qt project directory where $(basename "${project_path}") is located.
echo Usage: mac/$(basename "${0}")
if [[ ! -f "${project_path}" ]]; then
echo "Please run this script from the Qt project directory where $(basename "${project_path}") is located."
echo "Usage: mac/$(basename "${0}")"
exit 1
fi


# Cleanup previous deployments
cleanup

Expand All @@ -132,4 +142,4 @@ build_app client_app
build_app server_app "CONFIG+=server_bundle"

# Create versioned installer image
build_installer_image "${client_app}" "${server_app}"
build_installer_image "${CLIENT_TARGET_NAME}" "${SERVER_TARGET_NAME}"
67 changes: 44 additions & 23 deletions tools/changelog-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ declare -A LANGS=(
)

find_or_add_missing_entries() {
local changelog=$(sed -rne '/^###.*'"${target_release//./\.}"'\b/,/^### '"${prev_release//./\.}"'\b/p' ChangeLog)
local changelog_begin_position=$(grep -nP '^### .*\d+\.\d+\.\d+\b' ChangeLog | head -n1 | cut -d: -f1)
local changelog
changelog=$(sed -rne '/^###.*'"${target_release//./\.}"'\b/,/^### '"${prev_release//./\.}"'\b/p' ChangeLog)
local changelog_begin_position
changelog_begin_position=$(grep -nP '^### .*\d+\.\d+\.\d+\b' ChangeLog | head -n1 | cut -d: -f1)

echo "Checking if all merged Github PRs since ${prev_release} are included for ${target_release}..."
for id in $(gh pr list --limit "${PR_LIST_LIMIT}" --search 'milestone:"Release '"${target_release}"'"' --state merged | awk '{print $1}'); do
Expand All @@ -57,17 +59,22 @@ find_or_add_missing_entries() {
}

group_entries() {
local changelog_begin_position=$(grep -nP '^### .*\d+\.\d+\.\d+\b' ChangeLog | head -n1 | cut -d: -f1)
local changelog_prev_release_position=$(grep -nP '^### .*\d+\.\d+\.\d+\b' ChangeLog | head -n2 | tail -n1 | cut -d: -f1)
local changelog_begin_position
changelog_begin_position=$(grep -nP '^### .*\d+\.\d+\.\d+\b' ChangeLog | head -n1 | cut -d: -f1)
local changelog_prev_release_position
changelog_prev_release_position=$(grep -nP '^### .*\d+\.\d+\.\d+\b' ChangeLog | head -n2 | tail -n1 | cut -d: -f1)

# Save everything before the actual release changelog content:
local changelog_header=$(head -n "${changelog_begin_position}" ChangeLog)
local changelog_header
changelog_header=$(head -n "${changelog_begin_position}" ChangeLog)

# Save everything after the actual release changelog content:
local changelog_prev_releases=$(tail -n "+${changelog_prev_release_position}" ChangeLog)
local changelog_prev_releases
changelog_prev_releases=$(tail -n "+${changelog_prev_release_position}" ChangeLog)

# Save the current release's changelog content:
local changelog=$(sed -rne '/^###.*'"${target_release//./\.}"'\b/,/^### '"${prev_release//./\.}"'\b/p' ChangeLog | tail -n +2 | head -n -1)
local changelog
changelog=$(sed -rne '/^###.*'"${target_release//./\.}"'\b/,/^### '"${prev_release//./\.}"'\b/p' ChangeLog | tail -n +2 | head -n -1)

# Remove trailing whitespace on all lines of the current changelog:
changelog=$(sed -re 's/\s+$//' <<<"$changelog")
Expand Down Expand Up @@ -100,7 +107,7 @@ group_entries() {
local index=0
for category in "${category_order[@]}"; do
changelog=$(sed -re 's/^(- '"${category}"')/'"${index}"' \1/' <<<"${changelog}")
index=$(($index+1))
index=$((index+1))
done

# Reduce blocks ("entries") to a single line by replacing \n with \v.
Expand Down Expand Up @@ -131,15 +138,21 @@ check_or_add_pr() {
# (\> ensures that we only match full, standalone IDs)
return
fi
local json=$(gh pr view "${id/#/}" --json title,author,state)
local state=$(jq -r .state <<<"${json}")
local title=$(jq -r .title <<<"${json}" | sanitize_title)
local author=$(jq -r .author.login <<<"${json}")
local json
json=$(gh pr view "${id/#/}" --json title,author,state)
local state
state=$(jq -r .state <<<"${json}")
local title
title=$(jq -r .title <<<"${json}" | sanitize_title)
local author
author=$(jq -r .author.login <<<"${json}")
if [[ "${state}" != "MERGED" ]]; then
echo "-> Ignoring PR #${id} as state ${state} != MERGED"
return
fi
local title_suggestion_in_pr=$(gh pr view "$id" --json body,comments,reviews --jq '(.body), (.comments[] .body), (.reviews[] .body)' | grep -oP '\bCHANGELOG:\s*\K([^\\]{5,})' | tail -n1 | sanitize_title)
local title_suggestion_in_pr
title_suggestion_in_pr=$(gh pr view "$id" --json body,comments,reviews --jq '(.body), (.comments[] .body), (.reviews[] .body)' |
grep -oP '\bCHANGELOG:\s*\K([^\\]{5,})' | tail -n1 | sanitize_title)
if [[ "${title_suggestion_in_pr}" ]]; then
title="${title_suggestion_in_pr}"
if [[ "${title_suggestion_in_pr}" == "SKIP" ]]; then
Expand All @@ -153,7 +166,8 @@ check_or_add_pr() {
fi
echo ", adding new entry"
local new_entry=""
local lang=$(grep -oP 'Updated? \K(\S+)(?= app translations? for )' <<<"$title" || true)
local lang
lang=$(grep -oP 'Updated? \K(\S+)(?= app translations? for )' <<<"$title" || true)
if [[ "${lang}" ]]; then
# Note: This creates a top-level entry for each language.
# group-entries can merge those to a single one.
Expand All @@ -165,26 +179,33 @@ check_or_add_pr() {
echo "- ${title} (#${id})."
echo " (contributed by @${author})"
)
local changelog_before=$(head -n "${changelog_begin_position}" ChangeLog)
local changelog_after=$(tail -n "+$((${changelog_begin_position}+1))" ChangeLog)
local changelog_before
changelog_before=$(head -n "${changelog_begin_position}" ChangeLog)
local changelog_after
changelog_after=$(tail -n "+$((changelog_begin_position+1))" ChangeLog)
(echo "$changelog_before"; echo; echo "$new_entry"; echo "$changelog_after") > ChangeLog
}

add_translation_pr() {
local lang="${1}"
local author="${2}"
local id="${3}"
local changelog_begin_position=$(grep -nP '^### .*\d+\.\d+\.\d+\b' ChangeLog | head -n1 | cut -d: -f1)
local changelog_prev_release_position=$(grep -nP '^### .*\d+\.\d+\.\d+\b' ChangeLog | head -n2 | tail -n1 | cut -d: -f1)
local changelog_begin_position
changelog_begin_position=$(grep -nP '^### .*\d+\.\d+\.\d+\b' ChangeLog | head -n1 | cut -d: -f1)
local changelog_prev_release_position
changelog_prev_release_position=$(grep -nP '^### .*\d+\.\d+\.\d+\b' ChangeLog | head -n2 | tail -n1 | cut -d: -f1)

# Save everything before the actual release changelog content:
local changelog_header=$(head -n "${changelog_begin_position}" ChangeLog)
local changelog_header
changelog_header=$(head -n "${changelog_begin_position}" ChangeLog)

# Save everything after the actual release changelog content:
local changelog_prev_releases=$(tail -n "+${changelog_prev_release_position}" ChangeLog)
local changelog_prev_releases
changelog_prev_releases=$(tail -n "+${changelog_prev_release_position}" ChangeLog)

# Save the current release's changelog content:
local changelog=$(sed -rne '/^###.*'"${target_release//./\.}"'\b/,/^### '"${prev_release//./\.}"'\b/p' ChangeLog | tail -n +2 | head -n -1)
local changelog
changelog=$(sed -rne '/^###.*'"${target_release//./\.}"'\b/,/^### '"${prev_release//./\.}"'\b/p' ChangeLog | tail -n +2 | head -n -1)
local changelog_orig="${changelog}"

# Is there an existing entry for this language already?
Expand Down Expand Up @@ -227,12 +248,12 @@ add_translation_pr() {
changelog_after_translations="${changelog_after_translations}${line}"$'\n'
fi
done <<< "${changelog}"
changelog="$(
changelog=$(
# echo -n strips whitespace. we need that here.
echo -n "${changelog_before_translations}"
echo -n "$(grep -vP '^$' <<< "${changelog_translations}" | sort)"
echo -n "${changelog_after_translations}"
)"
)
fi
fi
# Rebuild the changelog and write back to file:
Expand Down
14 changes: 9 additions & 5 deletions tools/check-wininstaller-translations.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ BASE_LANG=en
INSTALLERLNG=installerlng.nsi
BASE_LANGSTRINGS=$(grep LangString "${BASE_DIR}/${BASE_LANG}.nsi" | cut -d' ' -f2)
EXIT=0
LANGUAGE_FILES="$(ls -1 src/res/translation/wininstaller/{??.nsi,??_??.nsi} | grep -vF "${BASE_LANG}.nsi")"
for LANGUAGE_FILE in ${LANGUAGE_FILES}; do
for LANGUAGE_FILE in src/res/translation/wininstaller/{??.nsi,??_??.nsi}; do
if [[ ${LANGUAGE_FILE} =~ /${BASE_LANG}.nsi$ ]]; then
continue
fi
echo
echo "* ${LANGUAGE_FILE}"
echo -n " - Checking language file is included in ${INSTALLERLNG}... "
if grep -q '^!include "\${ROOT_PATH}\\'$(sed -re 's|/|\\\\|g' <<<"${LANGUAGE_FILE}")'"' "${BASE_DIR}/${INSTALLERLNG}"; then
# shellcheck disable=SC2016 # shellcheck is confused here as NSI files use variables which look like shell variables
# shellcheck disable=SC1003 # shellcheck misinterprets the verbatim backslash as an attempt to escape the single quote. it's not.
if grep -q '^!include "\${ROOT_PATH}\\'"$(sed -re 's|/|\\\\|g' <<<"${LANGUAGE_FILE}")"'"' "${BASE_DIR}/${INSTALLERLNG}"; then
echo "ok"
else
echo "ERROR"
Expand All @@ -35,7 +39,7 @@ for LANGUAGE_FILE in ${LANGUAGE_FILES}; do
fi

echo -n " - Checking for wrong macros... "
LANG_MACROS="$(grep -oP '\$\{LANG_[^}]+\}' "${LANGUAGE_FILE}")"
LANG_MACROS=$(grep -oP '\$\{LANG_[^}]+\}' "${LANGUAGE_FILE}")
if grep ENGLISH <<<"$LANG_MACROS"; then
echo "ERROR, found LANG_ENGLISH"
EXIT=1
Expand All @@ -52,7 +56,7 @@ for LANGUAGE_FILE in ${LANGUAGE_FILES}; do
fi

echo -n " - Checking if LANG_ macro is in ${INSTALLERLNG}..."
LANG_NAME="$(sort -u <<<"${LANG_MACROS}" | sed -rne 's/\$\{LANG_(.*)\}/\1/p')"
LANG_NAME=$(sort -u <<<"${LANG_MACROS}" | sed -rne 's/\$\{LANG_(.*)\}/\1/p')
if grep -qi '^!insertmacro MUI_LANGUAGE "'"${LANG_NAME}"'"' "$BASE_DIR/${INSTALLERLNG}"; then
echo "ok"
else
Expand Down
13 changes: 9 additions & 4 deletions tools/create-translation-issues.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ declare -A TRANSLATORS_BY_LANG=(
[web_pt]="Snayler,melcon,ewarning"
)

# shellcheck disable=SC2016 # shellcheck can't know that this will be used with envsubst, so verbatim variables are correct here.
BODY_TEMPLATE_APP='Hi ${SPLIT_TRANSLATORS},
We are getting ready for the ${RELEASE} release. No further changes to translatable strings are currently planned for this release.
Expand All @@ -89,6 +90,7 @@ Further documentation can be found in [TRANSLATING.md](https://github.com/jamulu
Thanks for contributing to Jamulus!'


# shellcheck disable=SC2016 # shellcheck can't know that this will be used with envsubst, so verbatim variables are correct here.
BODY_TEMPLATE_WEB='Hi ${SPLIT_TRANSLATORS},
We are getting ready for the ${RELEASE} release and have created the [${TRANSLATE_BRANCH}](https://github.com/jamulussoftware/jamuluswebsite/tree/${TRANSLATE_BRANCH}) branch ([full diff](https://github.com/jamulussoftware/jamuluswebsite/compare/release..${TRANSLATE_BRANCH})).
Expand Down Expand Up @@ -149,7 +151,7 @@ get_languages() {
echo "Error: Please ensure that you are at the root of a jamuluswebsite checkout" >/dev/stderr
exit 1
fi
for LANG in $(cd _translator-files/po/ && ls -d *); do
for LANG in $(cd _translator-files/po/ && ls -d -- *); do
[[ -d _translator-files/po/$LANG ]] || continue
[[ $LANG == en ]] && continue # does not have to be translated
echo "$LANG"
Expand Down Expand Up @@ -184,7 +186,8 @@ create_translation_issue_for_lang() {
multiple_translators_text=""
[[ $translators == *,* ]] && multiple_translators_text=$'\n\n''This Issue is assigned to multiple people. Please coordinate who will translate what part.'
[[ $TYPE == app ]] && body_template="$BODY_TEMPLATE_APP" || body_template="$BODY_TEMPLATE_WEB"
local body=$(
local body
body=$(
# Note: Those line continuation backslashes are required for variables
# to be passed through:
DEADLINE="$DEADLINE" \
Expand All @@ -199,7 +202,8 @@ create_translation_issue_for_lang() {
)

# Check for an existing issue
local existing_issue=$(gh issue list --milestone "$MILESTONE" --state all --search "$title" --json number --jq '.[0].number' || true)
local existing_issue
existing_issue=$(gh issue list --milestone "$MILESTONE" --state all --search "$title" --json number --jq '.[0].number' || true)

# If there's no existing issue, create one
if [[ -z $existing_issue ]]; then
Expand All @@ -214,7 +218,8 @@ create_translation_issue_for_lang() {
# update the issue if the bodies differ.
# This is used on initial creation to fill in the issue number and it
# can be used to update the body text afterwards.
local online_body=$(gh issue view "$existing_issue" --json body --jq .body)
local online_body
online_body=$(gh issue view "$existing_issue" --json body --jq .body)
body=${body//<Insert this issue\'s number here>/${existing_issue}}
if [[ "$online_body" != "$body" ]]; then
echo "Updating Issue to translate $lang for $RELEASE"
Expand Down
Loading

0 comments on commit 06cd9a8

Please sign in to comment.