Post Comment to PR #80
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
name: Post Comment to PR | |
on: | |
workflow_run: | |
workflows: ["On PR action"] | |
types: | |
- completed | |
jobs: | |
create_comment_with_memory_usage: | |
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 | |
base_reports=$(ls old/sample-artifacts-meta/subsets/*/twister.json) | |
python3 scripts/ci/combine_twister_reports.py $base_reports old.json | |
python3 scripts/ci/compare_size_reports.py -o old.json -n new.json --md_output --show_only_diff > memory_usage.md | |
- name: Generate .config diff | |
shell: bash {0} | |
run: | | |
cd current | |
configs=$(find . -name .config) | |
cd .. | |
echo "<details>" >> memory_usage.md | |
echo "<summary>.config diff</summary>" >> memory_usage.md | |
echo "" >> memory_usage.md | |
echo "\`\`\`" >> memory_usage.md | |
for cfg in ${configs} | |
do | |
echo "compare ${cfg}" | |
grep -v "CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION" old/${cfg} > tmp_old.1 | |
grep -v "#" tmp_old.1 > tmp_old.2 | |
sort tmp_old.2 > tmp_old.3 | |
tr -s '\n' < tmp_old.3 > old/${cfg} | |
grep -v "CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION" current/${cfg} > tmp_current.1 | |
grep -v "#" tmp_current.1 > tmp_current.2 | |
sort tmp_current.2 > tmp_current.3 | |
tr -s '\n' < tmp_current.3 > current/${cfg} | |
rm -rf tmp_* | |
printf "\n%s\n%-63s|%s\n" "${cfg}" "old" "new" > cfg_diff.md | |
diff --text --report-identical-files --suppress-common-lines --side-by-side --label old --label new old/${cfg} current/${cfg} >> cfg_diff.md | |
if [ $? -eq 1 ]; then cat cfg_diff.md >> memory_usage.md; fi | |
done | |
echo "\`\`\`" >> memory_usage.md | |
echo "</details>" >> memory_usage.md | |
- name: Post diff to summary | |
run: | | |
cat memory_usage.md | |
cat memory_usage.md >> $GITHUB_STEP_SUMMARY | |
- 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 |