Skip to content

Commit

Permalink
fix simple analytics injection script (#1501)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
liamaharon authored Sep 12, 2023
1 parent c879d1d commit 77c867b
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitlab/pipeline/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"' _ {}
Expand Down

0 comments on commit 77c867b

Please sign in to comment.