Skip to content

Commit 3c352cf

Browse files
[CI] Redact logs stored in DB and retry indexing (#615)
* Redact secrets form logs stored in ES * Retry to publish build results in case it fails * Redact logs using scala script * Try fix heredocs * Another fix to heredocs problems, refactor to file * Fix typo in scala invocaiton
1 parent b3d915f commit 3c352cf

File tree

2 files changed

+57
-15
lines changed

2 files changed

+57
-15
lines changed

.github/actions/build-project/action.yaml

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -250,24 +250,41 @@ runs:
250250
jq -c -r "$path" $ConfigFile
251251
}
252252
253+
echo "Indexing build results..."
253254
cd /opencb/
254255
255-
# 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+
# Remove ASCII coloring and redact secrets using Scala
257+
scala-cli run /opencb/project-builder/redact-logs.scala --server=false -- \
258+
build-logs.txt \
259+
build-logs-redacted.txt \
260+
"${{ inputs.elastic-password }}" \
261+
"${{ inputs.github-key }}" \
262+
"${{ inputs.container-registry-token }}" \
263+
"${{ inputs.akka-repository-token }}"
257264
258-
/opencb/project-builder/feed-elastic.sh \
259-
'https://scala3.westeurope.cloudapp.azure.com/data' \
260-
"${{ inputs.project-name }}" \
261-
"$(cat build-status.txt)" \
262-
"$(date --iso-8601=seconds)" \
263-
build-summary.txt \
264-
build-logs-uncolored.txt \
265-
"$(config .version)" \
266-
"${{ inputs.scala-version }}" \
267-
"${{ inputs.custom-build-id != '' && inputs.custom-build-id || github.run_id }}" \
268-
"${{ steps.job-info.outputs.build-url }}" \
269-
"$(cat build-tool.txt)"
270-
if [ $? != 0 ]; then
265+
index_exit=0
266+
for attempt in 1 2 3; do
267+
/opencb/project-builder/feed-elastic.sh \
268+
'https://scala3.westeurope.cloudapp.azure.com/data' \
269+
"${{ inputs.project-name }}" \
270+
"$(cat build-status.txt)" \
271+
"$(date --iso-8601=seconds)" \
272+
build-summary.txt \
273+
build-logs-redacted.txt \
274+
"$(config .version)" \
275+
"${{ inputs.scala-version }}" \
276+
"${{ inputs.custom-build-id != '' && inputs.custom-build-id || github.run_id }}" \
277+
"${{ steps.job-info.outputs.build-url }}" \
278+
"$(cat build-tool.txt)"
279+
index_exit=$?
280+
if [ $index_exit -eq 0 ]; then
281+
break
282+
elif [ $attempt -lt 3 ]; then
283+
echo "Indexing failed, would retry"
284+
sleep $((attempt * 5))
285+
fi
286+
done
287+
if [ $index_exit != 0 ]; then
271288
echo "::warning title=Indexing failure::Indexing results of ${{ inputs.project-name }} failed"
272289
fi
273290

project-builder/redact-logs.scala

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import scala.io.Source
2+
import java.nio.file.{Files, Paths}
3+
4+
@main def redactLogs(
5+
inputFile: String,
6+
outputFile: String,
7+
secrets: String*
8+
): Unit = {
9+
// Read the log file
10+
val content = Source.fromFile(inputFile).mkString
11+
12+
// Remove ANSI color codes
13+
val contentWithoutColors = content.replaceAll("\u001B\\[[0-9;]*[mGK]", "")
14+
15+
// Redact secrets using foldLeft
16+
val redactedContent = secrets
17+
.filter(_.nonEmpty)
18+
.foldLeft(contentWithoutColors) { (acc, secret) =>
19+
acc.replace(secret, "<REDACTED>")
20+
}
21+
22+
// Write the redacted logs
23+
Files.write(Paths.get(outputFile), redactedContent.getBytes)
24+
println(s"Redacted logs written to $outputFile")
25+
}

0 commit comments

Comments
 (0)