Skip to content

Post Comment to PR #505

Post Comment to PR

Post Comment to PR #505

name: Post Comment to PR
on:
workflow_run:
workflows: ["On PR action"]
types:
- completed
jobs:
compare_configuration:
uses: ./.github/workflows/compare_config.yml
with:
current_run_id: ${{github.event.workflow_run.id}}
base_commit_sha: ${{github.event.workflow_run.event.pull_request.base.sha}}
create_PR_comment:
needs: [compare_configuration]
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
contents: read
checks: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get artifacts from PR
uses: dawidd6/action-download-artifact@v3
with:
run_id: ${{github.event.workflow_run.id}}
path: current
- name: Get artifacts from PR base
uses: dawidd6/action-download-artifact@v3
with:
commit: ${{github.event.workflow_run.event.pull_request.base.sha}}
workflow: on-commit.yml
path: old
- name: Unpack PR number
id: get-pr-number
run: |
pr_number="$(cat current/PR_number/PR_number)"
echo "pr_number=$pr_number" >> $GITHUB_OUTPUT
- name: Generage memory diff
run: |
shopt -s extglob
pr_reports=$(ls current/sample-artifacts-meta/subsets/*/twister.json)
python3 scripts/ci/combine_twister_reports.py $pr_reports new.json
cat new.json
base_reports=$(ls old/sample-artifacts-meta/subsets/*/twister.json)
python3 scripts/ci/combine_twister_reports.py $base_reports old.json
cat old.json
python3 scripts/ci/compare_size_reports.py -o old.json -n new.json --md_output --show_only_diff > memory_usage.md
cat memory_usage.md >> $GITHUB_STEP_SUMMARY
- uses: actions/download-artifact@v4
if: ${{ fromJson(needs.compare_configuration.outputs.diff_detected)}}
with:
name: configuration_diff
- name: Post diff to summary
if: ${{ fromJson(needs.compare_configuration.outputs.diff_detected)}}
run: |
echo "<details>" >> memory_usage.md
echo "<summary>.config diff</summary>" >> memory_usage.md
echo "" >> memory_usage.md
lines=$(cat config_diff.md | wc -l)
if [ $lines -ge 200 ]; then
echo ".config change: ${{needs.compare_configuration.outputs.artifact_url}}" >> memory_usage.md;
head -n 200 config_diff.md >> memory_usage.md;
echo "\`\`\`" >> memory_usage.md;
echo "Configuration diff too long to fit. Check file in artifacts." >> memory_usage.md;
else
cat config_diff.md >> memory_usage.md;
fi
echo "</details>" >> memory_usage.md
- name: Find Comment
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ steps.get-pr-number.outputs.pr_number }}
comment-author: 'github-actions[bot]'
body-includes: "| Sample | | diff | used | total |"
- name: Create or update comment
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ steps.get-pr-number.outputs.pr_number }}
body-path: memory_usage.md
edit-mode: replace