Skip to content

Commit

Permalink
ci: improve timing report formatting in Rust workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeytimoshin committed Jan 10, 2025
1 parent c1a09cb commit 2e21e55
Showing 1 changed file with 46 additions and 47 deletions.
93 changes: 46 additions & 47 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,54 +81,51 @@ jobs:
- name: Run tests
id: test-timing
run: |
source ./scripts/devenv.sh
{
echo "Testing group: ${{ matrix.group.name }}"
echo "Packages: ${{ matrix.group.packages }}"
echo "Rust version: $(rustc --version)"
} >> "$GITHUB_STEP_SUMMARY"
# Function to format time duration
format_duration() {
local duration="$1"
local minutes=$((duration / 60))
local seconds=$((duration % 60))
echo "${minutes}m ${seconds}s"
}
# Record group start time
group_start=$(date +%s)
# Test each package and measure time
while IFS= read -r pkg; do
if [[ -n "$pkg" ]]; then # Skip empty lines
echo "::group::Testing ${pkg}"
start=$(date +%s)
cargo test -p "${pkg}" || exit 1
end=$(date +%s)
duration=$((end - start))
formatted_time=$(format_duration "$duration")
echo "Package ${pkg} completed in ${formatted_time}"
echo "::endgroup::"
fi
done <<< "${{ matrix.group.packages }}"
# Record and print group total time
group_end=$(date +%s)
group_duration=$((group_end - group_start))
formatted_group_time=$(format_duration "$group_duration")
# Create timing report
{
echo "Group ${{ matrix.group.name }} total time: ${formatted_group_time}"
jq -n \
source ./scripts/devenv.sh
{
echo "Testing group: ${{ matrix.group.name }}"
echo "Packages: ${{ matrix.group.packages }}"
echo "Rust version: $(rustc --version)"
} >> "$GITHUB_STEP_SUMMARY"
# Function to format time duration
format_duration() {
local duration="$1"
local minutes=$((duration / 60))
local seconds=$((duration % 60))
echo "${minutes}m ${seconds}s"
}
# Record group start time
group_start=$(date +%s)
# Test each package and measure time
while IFS= read -r pkg; do
if [[ -n "$pkg" ]]; then # Skip empty lines
echo "::group::Testing ${pkg}"
start=$(date +%s)
cargo test -p "${pkg}" || exit 1
end=$(date +%s)
duration=$((end - start))
formatted_time=$(format_duration "$duration")
echo "Package ${pkg} completed in ${formatted_time}"
echo "::endgroup::"
fi
done <<< "${{ matrix.group.packages }}"
# Record and print group total time
group_end=$(date +%s)
group_duration=$((group_end - group_start))
formatted_group_time=$(format_duration "$group_duration")
# Create timing report with proper output formatting
echo "timing=$(jq -n \
--arg group "${{ matrix.group.name }}" \
--arg time "${formatted_group_time}" \
'{group: $group, time: $time}' >> "$GITHUB_OUTPUT"
} >> "$GITHUB_STEP_SUMMARY"
'{group: $group, time: $time}' | base64)" >> "$GITHUB_OUTPUT"
collect-times:
needs: test
runs-on: ubuntu-latest
Expand All @@ -140,5 +137,7 @@ jobs:
echo "# Test Execution Times"
echo "| Group | Time |"
echo "|-------|------|"
echo "${{ needs.test.outputs.timing }}" | jq -r '. | "| \(.group) | \(.time) |"'
for timing in ${{ needs.test.outputs.timing }}; do
echo "$timing" | base64 -d | jq -r '. | "| \(.group) | \(.time) |"'
done
} >> "$GITHUB_STEP_SUMMARY"

0 comments on commit 2e21e55

Please sign in to comment.