Run shellcheck on build_linux.sh and add it to workflows (#10317)

* Shellcheck on build_linux.sh and tiny refactor

`shellcheck -e SC1090 build_linux.sh` and fixed the issues.

Also fixed the usage command to return an error, simplify directory
creation to use `mkdir -p`, and made printing of the cmake commands
consistent instead of having three different ways of doing it.

* Reorder functions in more pleasing way

* Add shellcheck to workflows

This is the beginning of adding some safety nets for making
changes. Currently it just runs shellcheck against `build_linux.sh`.

You can see it working at
https://github.com/coryrc/OrcaSlicer/actions/workflows/shellcheck.yml
I forked and tested it running in PRs and against pushes to HEAD.

* Rerun shellcheck

Missed quotes on the merge
This commit is contained in:
coryrc
2025-08-24 07:26:14 -04:00
committed by GitHub
parent 7dfce56fbb
commit 09034d87b7
2 changed files with 85 additions and 45 deletions

38
.github/workflows/shellcheck.yml vendored Normal file
View File

@@ -0,0 +1,38 @@
on:
push:
paths:
- build_linux.sh
pull_request:
paths:
- build_linux.sh
workflow_dispatch: # allows for manual dispatch
name: "Shellcheck"
permissions: {}
jobs:
shellcheck:
name: Shellcheck
runs-on: ubuntu-latest
steps:
- name: Cache shellcheck download
id: cache-shellcheck-v0_11
uses: actions/cache@v4
with:
path: ~/shellcheck
key: ${{ runner.os }}-shellcheck-v0_11
- name: Download shellcheck
if: steps.cache-shellcheck-v0_11.outputs.cache-hit != 'true'
shell: bash
env:
INPUT_VERSION: "v0.11.0"
run: |
curl -L#o ~/sc.tar.xz "https://github.com/koalaman/shellcheck/releases/download/${INPUT_VERSION}/shellcheck-${INPUT_VERSION}.linux.x86_64.tar.xz"
tar -xvf ~/sc.tar.xz -C ~
mv ~/shellcheck-"${INPUT_VERSION}"/shellcheck ~/shellcheck
- uses: actions/checkout@v4
- name: Shellcheck build_linux.sh
run: ~/shellcheck -e SC1090 build_linux.sh

View File

@@ -1,33 +1,10 @@
#!/usr/bin/env bash #!/usr/bin/env bash
SCRIPT_NAME=$(basename "$0")
SCRIPT_PATH=$(dirname $(readlink -f ${0}))
pushd ${SCRIPT_PATH} > /dev/null
set -e # Exit immediately if a command exits with a non-zero status. set -e # Exit immediately if a command exits with a non-zero status.
function check_available_memory_and_disk() { SCRIPT_NAME=$(basename "$0")
FREE_MEM_GB=$(free --gibi --total | grep 'Mem' | rev | cut --delimiter=" " --fields=1 | rev) SCRIPT_PATH=$(dirname "$(readlink -f "${0}")")
MIN_MEM_GB=10
FREE_DISK_KB=$(df --block-size=1K . | tail -1 | awk '{print $4}') pushd "${SCRIPT_PATH}" > /dev/null
MIN_DISK_KB=$((10 * 1024 * 1024))
if [[ ${FREE_MEM_GB} -le ${MIN_MEM_GB} ]] ; then
echo -e "\nERROR: Orca Slicer Builder requires at least ${MIN_MEM_GB}G of 'available' mem (system has only ${FREE_MEM_GB}G available)"
echo && free --human && echo
echo "Invoke with -r to skip RAM and disk checks."
exit 2
fi
if [[ ${FREE_DISK_KB} -le ${MIN_DISK_KB} ]] ; then
echo -e "\nERROR: Orca Slicer Builder requires at least $(echo ${MIN_DISK_KB} |awk '{ printf "%.1fG\n", $1/1024/1024; }') (system has only $(echo ${FREE_DISK_KB} | awk '{ printf "%.1fG\n", $1/1024/1024; }') disk free)"
echo && df --human-readable . && echo
echo "Invoke with -r to skip ram and disk checks."
exit 1
fi
}
function usage() { function usage() {
echo "Usage: ./${SCRIPT_NAME} [-1][-b][-c][-d][-h][-i][-j N][-p][-r][-s][-u][-l]" echo "Usage: ./${SCRIPT_NAME} [-1][-b][-c][-d][-h][-i][-j N][-p][-r][-s][-u][-l]"
@@ -72,7 +49,7 @@ while getopts ":1j:bcCdhiprsul" opt ; do
BUILD_DEPS="1" BUILD_DEPS="1"
;; ;;
h ) usage h ) usage
exit 0 exit 1
;; ;;
i ) i )
BUILD_IMAGE="1" BUILD_IMAGE="1"
@@ -87,19 +64,45 @@ while getopts ":1j:bcCdhiprsul" opt ; do
BUILD_ORCA="1" BUILD_ORCA="1"
;; ;;
u ) u )
UPDATE_LIB="1" export UPDATE_LIB="1"
;; ;;
l ) l )
USE_CLANG="1" USE_CLANG="1"
;; ;;
* )
echo "Unknown argument '${opt}', aborting."
exit 1
;;
esac esac
done done
if [ ${OPTIND} -eq 1 ] ; then if [ ${OPTIND} -eq 1 ] ; then
usage usage
exit 0 exit 1
fi fi
function check_available_memory_and_disk() {
FREE_MEM_GB=$(free --gibi --total | grep 'Mem' | rev | cut --delimiter=" " --fields=1 | rev)
MIN_MEM_GB=10
FREE_DISK_KB=$(df --block-size=1K . | tail -1 | awk '{print $4}')
MIN_DISK_KB=$((10 * 1024 * 1024))
if [[ ${FREE_MEM_GB} -le ${MIN_MEM_GB} ]] ; then
echo -e "\nERROR: Orca Slicer Builder requires at least ${MIN_MEM_GB}G of 'available' mem (system has only ${FREE_MEM_GB}G available)"
echo && free --human && echo
echo "Invoke with -r to skip RAM and disk checks."
exit 2
fi
if [[ ${FREE_DISK_KB} -le ${MIN_DISK_KB} ]] ; then
echo -e "\nERROR: Orca Slicer Builder requires at least $(echo "${MIN_DISK_KB}" |awk '{ printf "%.1fG\n", $1/1024/1024; }') (system has only $(echo "${FREE_DISK_KB}" | awk '{ printf "%.1fG\n", $1/1024/1024; }') disk free)"
echo && df --human-readable . && echo
echo "Invoke with -r to skip ram and disk checks."
exit 1
fi
}
# cmake 4.x compatibility workaround # cmake 4.x compatibility workaround
export CMAKE_POLICY_VERSION_MINIMUM=3.5 export CMAKE_POLICY_VERSION_MINIMUM=3.5
@@ -115,13 +118,13 @@ elif [[ "${DISTRIBUTION_LIKE}" == *"arch"* ]] ; then
DISTRIBUTION="arch" DISTRIBUTION="arch"
fi fi
if [ ! -f ./scripts/linux.d/${DISTRIBUTION} ] ; then if [ ! -f "./scripts/linux.d/${DISTRIBUTION}" ] ; then
echo "Your distribution \"${DISTRIBUTION}\" is not supported by system-dependency scripts in ./scripts/linux.d/" echo "Your distribution \"${DISTRIBUTION}\" is not supported by system-dependency scripts in ./scripts/linux.d/"
echo "Please resolve dependencies manually and contribute a script for your distribution to upstream." echo "Please resolve dependencies manually and contribute a script for your distribution to upstream."
exit 1 exit 1
else else
echo "resolving system dependencies for distribution \"${DISTRIBUTION}\" ..." echo "resolving system dependencies for distribution \"${DISTRIBUTION}\" ..."
source ./scripts/linux.d/${DISTRIBUTION} source "./scripts/linux.d/${DISTRIBUTION}"
fi fi
echo "FOUND_GTK3=${FOUND_GTK3}" echo "FOUND_GTK3=${FOUND_GTK3}"
@@ -139,7 +142,7 @@ echo "Changing date in version..."
echo "done" echo "done"
if ! [[ -n "${SKIP_RAM_CHECK}" ]] ; then if [[ -z "${SKIP_RAM_CHECK}" ]] ; then
check_available_memory_and_disk check_available_memory_and_disk
fi fi
@@ -155,29 +158,28 @@ if [[ -n "${BUILD_DEPS}" ]] ; then
then then
rm -fr deps/build rm -fr deps/build
fi fi
if [ ! -d "deps/build" ] mkdir -p deps/build
then
mkdir deps/build
fi
if [[ -n "${BUILD_DEBUG}" ]] ; then if [[ -n "${BUILD_DEBUG}" ]] ; then
# build deps with debug and release else cmake will not find required sources # build deps with debug and release else cmake will not find required sources
if [ ! -d "deps/build/release" ] ; then mkdir -p deps/build/release
mkdir deps/build/release CMAKE_CMD="cmake ${CMAKE_C_CXX_COMPILER_CLANG} -S deps -B deps/build/release -DSLIC3R_PCH=${SLIC3R_PRECOMPILED_HEADERS} -G Ninja -DDESTDIR=${SCRIPT_PATH}/deps/build/destdir -DDEP_DOWNLOAD_DIR=${SCRIPT_PATH}/deps/DL_CACHE ${COLORED_OUTPUT} ${BUILD_ARGS}"
fi echo "${CMAKE_CMD}"
cmake ${CMAKE_C_CXX_COMPILER_CLANG} -S deps -B deps/build/release -DSLIC3R_PCH=${SLIC3R_PRECOMPILED_HEADERS} -G Ninja -DDESTDIR="${SCRIPT_PATH}/deps/build/destdir" -DDEP_DOWNLOAD_DIR="${SCRIPT_PATH}/deps/DL_CACHE" ${COLORED_OUTPUT} ${BUILD_ARGS} ${CMAKE_CMD}
cmake --build deps/build/release cmake --build deps/build/release
BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug" BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
fi fi
echo "cmake -S deps -B deps/build ${CMAKE_C_CXX_COMPILER_CLANG} -G Ninja ${BUILD_ARGS}" # If this isn't in one quote, then empty variables can add two single quotes and mess up argument parsing for cmake.
cmake -S deps -B deps/build ${CMAKE_C_CXX_COMPILER_CLANG} -G Ninja ${COLORED_OUTPUT} ${BUILD_ARGS} CMAKE_CMD="cmake -S deps -B deps/build ${CMAKE_C_CXX_COMPILER_CLANG} -G Ninja ${COLORED_OUTPUT} ${BUILD_ARGS}"
echo "${CMAKE_CMD}"
${CMAKE_CMD}
cmake --build deps/build cmake --build deps/build
fi fi
if [[ -n "${BUILD_ORCA}" ]] ; then if [[ -n "${BUILD_ORCA}" ]] ; then
echo "Configuring OrcaSlicer..." echo "Configuring OrcaSlicer..."
if [[ -n "${CLEAN_BUILD}" ]] ; then if [[ -n "${CLEAN_BUILD}" ]] ; then
rm --force --recursive build rm -fr build
fi fi
BUILD_ARGS="${ORCA_EXTRA_BUILD_ARGS}" BUILD_ARGS="${ORCA_EXTRA_BUILD_ARGS}"
if [[ -n "${FOUND_GTK3_DEV}" ]] ; then if [[ -n "${FOUND_GTK3_DEV}" ]] ; then
@@ -191,12 +193,12 @@ if [[ -n "${BUILD_ORCA}" ]] ; then
CMAKE_CMD="cmake -S . -B build ${CMAKE_C_CXX_COMPILER_CLANG} -G Ninja Multi-Config \ CMAKE_CMD="cmake -S . -B build ${CMAKE_C_CXX_COMPILER_CLANG} -G Ninja Multi-Config \
-DSLIC3R_PCH=${SLIC3R_PRECOMPILED_HEADERS} \ -DSLIC3R_PCH=${SLIC3R_PRECOMPILED_HEADERS} \
-DCMAKE_PREFIX_PATH="${SCRIPT_PATH}/deps/build/destdir/usr/local" \ -DCMAKE_PREFIX_PATH=${SCRIPT_PATH}/deps/build/destdir/usr/local \
-DSLIC3R_STATIC=1 \ -DSLIC3R_STATIC=1 \
-DORCA_TOOLS=ON \ -DORCA_TOOLS=ON \
${COLORED_OUTPUT} \ ${COLORED_OUTPUT} \
${BUILD_ARGS}" ${BUILD_ARGS}"
echo -e "${CMAKE_CMD}" echo "${CMAKE_CMD}"
${CMAKE_CMD} ${CMAKE_CMD}
echo "done" echo "done"
echo "Building OrcaSlicer ..." echo "Building OrcaSlicer ..."