-PACKAGESIZE=$(echo "$(du -ms ${PACKAGETMPDIR} | cut -f1) * 1.1" | bc)
-hdiutil create -srcfolder ${PACKAGETMPDIR} -format UDBZ -size ${PACKAGESIZE}M -volname "Quassel ${BUILDTYPE} - ${QUASSEL_VERSION}" "${WORKINGDIR}${QUASSEL_DMG}" >/dev/null
+
+echo "Creating macOS disk image with hdiutil: 'Quassel ${BUILDTYPE} - ${QUASSEL_VERSION}'"
+
+# hdiutil seems to have a bit of a reputation for failing to create disk images
+# for various reasons.
+#
+# If you've come here to see why on earth your macOS build is failing despite
+# making changes entirely unrelated to macOS, you have my sympathy.
+#
+# There are two main approaches:
+#
+# 1. Let hdiutil calculate a size automatically
+#
+# 2. Separately calculate the size with a margin of error, then specify this
+# to hdiutil during disk image creation.
+#
+# Both seem to have caused issues, but in recent tests, option #1 seemed more
+# reliable.
+#
+# Option 1:
+
+hdiutil create -srcfolder ${PACKAGETMPDIR} -format UDBZ -volname "Quassel ${BUILDTYPE} - ${QUASSEL_VERSION}" "${WORKINGDIR}${QUASSEL_DMG}" >/dev/null
+
+# If hdiutil changes over time and fails often, you can try the other option.
+#
+# Option 2:
+#
+#PACKAGESIZE_MARGIN="1.1"
+#PACKAGESIZE=$(echo "$(du -ms ${PACKAGETMPDIR} | cut -f1) * $PACKAGESIZE_MARGIN" | bc)
+#echo "PACKAGESIZE: $PACKAGESIZE MB"
+#hdiutil create -srcfolder ${PACKAGETMPDIR} -format UDBZ -size ${PACKAGESIZE}M -volname "Quassel ${BUILDTYPE} - ${QUASSEL_VERSION}" "${WORKINGDIR}${QUASSEL_DMG}" >/dev/null
+
+
+# Regardless of choice, clean up the packaging temporary directory