@@ -253,15 +253,43 @@ runs:
253253 cd /opencb/
254254
255255 # Remove ASCII coloring from the indexed logs
256- cat build-logs.txt | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2};?)?)?[mGK]//g" > build-logs-uncolored.txt
256+ mv build-logs.txt build-logs-redacted.txt
257+
258+ # Not required in the CI but usefull for local tests
259+ sed_inplace () {
260+ local expr="$1"
261+ local file="$2"
262+ if sed --version >/dev/null 2>&1; then
263+ sed -r -i "$expr" "$file"
264+ else
265+ sed -E -i '' "$expr" "$file"
266+ fi
267+ }
268+
269+ sed_inplace "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2};?)?)?[mGK]//g" build-logs-redacted.txt
270+
271+ # Replace secrets before indexing logs
272+ redact_one () {
273+ local secret="$1"
274+ if [[ -n "$secret" ]]; then
275+ local escaped
276+ escaped="$(printf '%s' "$secret" | sed -e 's/[\/&\\]/\\&/g' -e 's/[].[^$*+?{}()|]/\\&/g')"
277+ sed_inplace "s/${escaped}/REDACTED/g" build-logs-redacted.txt
278+ fi
279+ }
280+
281+ redact_one "${{ inputs.elastic-password }}"
282+ redact_one "${{ inputs.github-key }}"
283+ redact_one "${{ inputs.container-registry-token }}"
284+ redact_one "${{ inputs.akka-repository-token }}"
257285
258286 /opencb/project-builder/feed-elastic.sh \
259287 'https://scala3.westeurope.cloudapp.azure.com/data' \
260288 "${{ inputs.project-name }}" \
261289 "$(cat build-status.txt)" \
262290 "$(date --iso-8601=seconds)" \
263291 build-summary.txt \
264- build-logs-uncolored .txt \
292+ build-logs-redacted .txt \
265293 "$(config .version)" \
266294 "${{ inputs.scala-version }}" \
267295 "${{ inputs.custom-build-id != '' && inputs.custom-build-id || github.run_id }}" \
0 commit comments