tests: added spread results commenter #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | ||
workflow_call: | ||
inputs: | ||
runs-on: | ||
description: 'A tag to indicate which runner to use' | ||
required: true | ||
type: string | ||
jobs: | ||
report-spread-failures: | ||
runs-on: ${{ inputs.runs-on }} | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Download spread data | ||
uses: actions/download-artifact@v4 | ||
with: | ||
pattern: spread-json-${{ github.run_id }}-${{ github.run_attempt }}-* | ||
- name: Echo collected output | ||
run: | | ||
ls -la "${{ github.workspace }}/" | ||
jq -s 'add' results*/*.json > consolidated-report.json | ||
report="$(date)\n" | ||
report+="## Failures:\n" | ||
if [[ $(jq -r '.[] | select( .info_type == "Error" ) | select( .verb == "preparing" )' consolidated-report.json) ]]; then | ||
report+="### Prepare:\n" | ||
report+=$(jq -r '.[] | select( .info_type == "Error" ) | select( .verb == "preparing" ) .task' consolidated-report.json | while read line; do echo "- $line\n"; done) | ||
fi | ||
if [[ $(jq -r '.[] | select( .info_type == "Error" ) | select( .verb == "executing" )' consolidated-report.json) ]]; then | ||
report+="### Executing:\n" | ||
report+=$(jq -r '.[] | select( .info_type == "Error" ) | select( .verb == "executing" ) .task' consolidated-report.json | while read line; do echo "- $line\n"; done) | ||
firesults-${{ github.run_id }}-${{ github.run_attempt }}- | ||
if [[ $(jq -r '.[] | select( .info_type == "Error" ) | select( .verb == "restoring" )' consolidated-report.json) ]]; then | ||
report+="### Restoring:\n" | ||
report+=$(jq -r '.[] | select( .info_type == "Error" ) | select( .verb == "restoring" ) .task' consolidated-report.json | while read line; do echo "- $line\n"; done) | ||
fi | ||
echo "report=$report" >> $GITHUB_ENV | ||
- name: Comment report to PR | ||
if: ${{ github.event.number }} | ||
run: | | ||
if ! gh pr comment "${{ github.event.number }}" --report "$(echo -e $report)" --edit-last; then | ||
gh pr comment "${{ github.event.number }}" --report "$(echo -e $report)"results-${{ github.run_id }}-${{ github.run_attempt }}- | ||
fi | ||
- name: Write report to test summary | ||
echo -e "$report" >> $GITHUB_STEP_SUMMARY | ||
- name: Delete artifacts | ||
run: | | ||
artifact_ids=$(gh api /repos/${{ github.repository }}/actions/artifacts | jq -r '.artifacts[] | select(.name|startswith("spread-json-${{ github.run_id }}-${{ github.run_attempt }}-")) | "\(.id)"') | ||
for artifact_id in $artifact_ids; do | ||
echo "planning to delete $artifact_id"; | ||
gh api -X delete /repos/${{ github.repository }}/actions/artifacts/$artifact_id | ||
done | ||