Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine all workflow metrics into single summary #666

Closed
wants to merge 16 commits into from
74 changes: 40 additions & 34 deletions .github/workflows/_finalize.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,46 +129,52 @@ jobs:
- name: Download artifacts
uses: actions/download-artifact@v4

- name: Write output to step summary
- name: Concatenate all json data
shell: bash -x -e {0}
run: |
find -name "sitrep.json" | while read -s f; do
cat "$f" | jq -r '.summary' | tee -a $GITHUB_STEP_SUMMARY
done
# Combine all json files into a final summary json
output="combined.json"
combinedJson="{}"

# Loop over subdirectories in the current directory
while IFS= read -r dir; do
echo $dir
dirName=$(basename $dir) && [ -d "$dir" ] || continue
CliveUnger marked this conversation as resolved.
Show resolved Hide resolved

# Initialize default empty JSON objects
sitrep="{}"
metricSummary="{}"
status="{}"

# Check if the sitrep.json file exists and read it, else use default
if [ -f "$dir/sitrep.json" ]; then
sitrep=$(<"$dir/sitrep.json")
fi

- name: Concatenate all sitreps
shell: bash -x -e {0}
run: |
# combine all sitreps files into a single file, where each sitrep json sits
# in a field named by the folder that contained it
echo "[" >> fsitrep.json
sitrep_files=($(find . -name "sitrep.json"))
total_files=${#sitrep_files[@]}

# parse all the sitrep files and consolidate them into one
for ((i=0; i<total_files; i++)); do
FILE=${sitrep_files[$i]}
# Extract directory name
key=$(dirname "$FILE")
# Extract the summary field from the JSON files and append the content to the output JSON file.
if [[ "$key" == "./artifact-t5x-mgmn-test" || "$key" == "./artifact-pax-mgmn-test" ]]; then
val_tmp=$(cat "$FILE" | jq -r '.summary' )
# For t5x/pax mgmn test extract the test summary of tests and ignore extended metric info in the summary.
delimiter="|"
IFS=$delimiter read -ra parts <<< "$val_tmp"
value="${parts[0]}passed"
else
value=$(cat "$FILE" | jq -r '.summary' )
# Check if the metric_summary.json file exists and read it, else use default
if [ -f "$dir/metric_summary.json" ]; then
metricSummary=$(<"$dir/metric_summary.json")
fi

jq -n --arg key "$key" --arg value "$value" '{ ($key): $value }' >> fsitrep.json
if [ $i != $((total_files-1)) ]; then
echo -n "," >> fsitrep.json
# Use Bash globbing to find the *-status.json file and read it, else use default
statusFiles=("$dir"/*-status.json)
statusFile=${statusFiles[0]}
if [ -f $statusFile ]; then
status=$(<"${statusFile}")
fi
done
echo "]" >> fsitrep.json
mv fsitrep.json sitrep.json


# Use jq to merge the JSON data
combinedJson=$(jq --arg dirName "$dirName" \
--argjson sitrep "$sitrep" \
--argjson status "$status" \
--argjson metricSummary "$metricSummary" \
'.[$dirName] = {"sitrep": $sitrep, "status": $status, "metric_summary": $metricSummary}' <<<"$combinedJson")
done < <(find . -maxdepth 1 -type d)

# Output the combined JSON to the file, nicely formatted
echo "$combinedJson" | jq '.' > "$output"
mv combined.json sitrep.json

- name: Upload training logs as artifacts
uses: actions/upload-artifact@v4
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/_sandbox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
a smooth integration process once the changes are ready to be merged.

Usage:

1. In your development branch, modify the sandbox.yml workflow file
to include the new actions you want to test. Make sure to commit
the changes to the development branch.
Expand All @@ -38,4 +38,4 @@ jobs:
merge the development branch into the main branch. Remember to
revert the changes to the sandbox.yml file in the main branch to
keep it empty for future testing.
EOF
EOF
1 change: 1 addition & 0 deletions .github/workflows/_sitrep_mgmn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,4 @@ jobs:
path: |
sitrep.json
${{ inputs.BADGE_FILENAME }}
metrics_summary.json
Loading