fix: Pipe scripts to shellcheck via stdin to avoid Docker-in-Docker mount issues
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 31s
Build-Test-Publish / build (linux/arm64) (push) Successful in 1m14s

This commit is contained in:
j
2026-03-07 23:53:34 +13:00
parent 178f8fa179
commit 52f7ab187f

View File

@@ -86,12 +86,13 @@ int run_shellcheck(const std::filesystem::path& template_path, std::vector<std::
// Get relative path from template_path // Get relative path from template_path
std::string rel_path = std::filesystem::relative(script, template_path).string(); std::string rel_path = std::filesystem::relative(script, template_path).string();
// Run shellcheck in container // Run shellcheck in container, piping script via stdin to avoid
// volume mount issues in Docker-in-Docker CI environments
// -f gcc gives us parseable output: file:line:col: severity: message // -f gcc gives us parseable output: file:line:col: severity: message
// -s bash specifies bash dialect // -s bash specifies bash dialect
// -e SC1091 excludes "not following sourced file" warnings (common.sh is external) // -e SC1091 excludes "not following sourced file" warnings (common.sh is external)
std::string command = "docker run --rm -v " + template_path.string() + ":/mnt:ro koalaman/shellcheck:stable " std::string command = "cat " + script.string() + " | docker run --rm -i koalaman/shellcheck:stable "
"-f gcc -s bash -e SC1091 /mnt/" + rel_path + " 2>&1"; "-f gcc -s bash -e SC1091 - 2>&1";
FILE* pipe = popen(command.c_str(), "r"); FILE* pipe = popen(command.c_str(), "r");
if (!pipe) { if (!pipe) {
@@ -118,10 +119,14 @@ int run_shellcheck(const std::filesystem::path& template_path, std::vector<std::
while (std::getline(iss, line)) { while (std::getline(iss, line)) {
if (line.empty()) continue; if (line.empty()) continue;
// Replace /mnt/ with actual filename for clarity // Replace stdin placeholder or /mnt/ path with actual filename
size_t mnt_pos = line.find("/mnt/"); if (line.substr(0, 2) == "-:") {
if (mnt_pos != std::string::npos) { line = rel_path + ":" + line.substr(2);
line = line.substr(mnt_pos + 5); // Skip "/mnt/" } else {
size_t mnt_pos = line.find("/mnt/");
if (mnt_pos != std::string::npos) {
line = line.substr(mnt_pos + 5); // Skip "/mnt/"
}
} }
// Color based on severity // Color based on severity