From 77c867bafff800488af43fa7e3602b914c062876 Mon Sep 17 00:00:00 2001
From: Liam Aharon <liam.aharon@hotmail.com>
Date: Tue, 12 Sep 2023 16:13:27 +1000
Subject: [PATCH] fix simple analytics injection script (#1501)

When `process_file` is run by `xargs`, it is executed inside a new shell
without access to variables defined outside of its scope.

This resulted in `script_content` being an empty string.

By exporting `script_content` prior to running `xargs` it is available
inside the new shells.
---
 .gitlab/pipeline/build.yml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/.gitlab/pipeline/build.yml b/.gitlab/pipeline/build.yml
index 328b37af1d4..924d648e3f9 100644
--- a/.gitlab/pipeline/build.yml
+++ b/.gitlab/pipeline/build.yml
@@ -111,6 +111,9 @@ build-rustdoc:
             sed -i "s|</head>|$script_content</head>|" "$file"
         }
         export -f process_file
+        # xargs runs process_file in seperate shells without access to outer variables.
+        # to make script_content available inside process_file, export it as an env var here.
+        export script_content
 
         # Modify .html files in parallel using xargs, otherwise it can take a long time.
         find "$path" -name '*.html' | xargs -I {} -P "$(nproc)" bash -c 'process_file "$@"' _ {}
-- 
GitLab