Skip to content

Run ShellCheck automatically and various small fixes to `mft_renderfarm.sh`

Christian Aribaud requested to merge cicd_shellcheck into main

Run ShellCheck on mft_renderfarm.sh whenever there is a PR or a commit on the main branch that modifies it.

Automatic ShellCheck run

Adds .gitlab-ci.yml to define the automatic task. If you want to move the file elsewhere @Deevad, it's possible but the repo configuration must be changed accordingly.

If shellcheck finds warnings, Gitlab will display a (!) label. You then have to go and see the logs. Here is an example of what it looks like.

Output is colored for easier readability.

If some warning become troublesome they can be ignored via a comment in mft_renderfarm.sh or globaly as an argument of the shellcheck call.

Various mft_renderfarm.sh fixes

Fix ShellCheck last warnings

None of the warnings where actual problems, but it is best practice to fix them.

Separating export of version from it's assignment to avoid potential troubles per https://www.shellcheck.net/wiki/SC2155.

Simplifying string substitution per https://www.shellcheck.net/wiki/SC2001.

Here, it's rather safe to use the native bash substitution function. Double-quotes are necessary to avoid trouble because of the ${VAR_NAME//SEARCH/REPLACE} syntax.

We want to remove (using ${VAR_NAME//STRING_TO_DELETE/}) but we have a slashes in the pattern ${dirPath}/${langDir}/ that would break the syntax (we'd have ${inPath//${dirPath}/${langDir}//}, which means replace ${dirPath} with "{langDir}//). Hence ${inPath//"${dirPath}/${langDir}/"/}, which means replace ${dirPath}/${langDir}/ with nothing.

Adding -r to read call per https://www.shellcheck.net/wiki/SC2162.

Not using -r can lead to this:

$ read -p "File?: " ANSWER
File?: a_dir\new_file.txt
$ echo "$ANSWER"
a_dirnew_file.txt

While using -r preserves the backslashs:

$ read -r -p "File?: " ANSWER
File?: a_dir\new_file.txt
$ echo "$ANSWER"
a_dir\new_file.txt
Edited by Christian Aribaud

Merge request reports