Size: Comment #204
This file contains hidden or 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: "Size: Comment" | |
# read-write repo token | |
# access to secrets | |
# | |
# https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/ | |
on: | |
workflow_dispatch: | |
inputs: | |
RUN_ID: | |
description: Which workflow run to get artifacts from | |
required: true | |
type: string | |
workflow_run: | |
workflows: ["Size: PR"] | |
types: | |
- completed | |
permissions: | |
contents: read | |
issues: write | |
pull-requests: write | |
jobs: | |
compare_sizes: | |
name: 'Compare Sizes and Comment' | |
runs-on: 'ubuntu-latest' | |
steps: | |
- uses: dawidd6/action-download-artifact@v9 | |
with: | |
run_id: ${{ inputs.RUN_ID || github.event.workflow_run.id }} | |
workflow: size-pr.yml | |
path: pr | |
if_no_artifact_found: fail | |
- uses: dawidd6/action-download-artifact@v9 | |
with: | |
name: sizes-main | |
path: main | |
workflow: size-main.yml | |
if_no_artifact_found: fail | |
- name: "[Debug] artifacts' files" | |
run: | | |
ls -la ./main | |
ls -la ./pr/** | |
- name: "[PR] Get path of size output txt file" | |
id: find-pr-txt | |
run: | | |
cd pr/ | |
filePath=$(find . -name "out.txt") | |
echo $filePath | |
echo "txtPath=pr/$filePath" >> $GITHUB_OUTPUT | |
- name: "[PR] Get PR number" | |
id: find-pr-number | |
run: | | |
cd pr/ | |
filePath=$(find . -name "NR") | |
contents=$(cat $filePath) | |
echo $filePath | |
echo $contents | |
echo "prNumber=$contents" >> $GITHUB_OUTPUT | |
- name: "[PR] Get sizes" | |
id: dev | |
run: | | |
cat ${{ steps.find-pr-txt.outputs.txtPath }} | |
echo 'sizes<<EOF' >> $GITHUB_OUTPUT | |
while IFS= read -r line; do | |
echo "$line" >> $GITHUB_OUTPUT | |
done <<< $(cat ${{ steps.find-pr-txt.outputs.txtPath }}) | |
echo 'EOF' >> $GITHUB_OUTPUT | |
- name: "[Main] Get sizes" | |
id: main-dev | |
run: | | |
cd main/ | |
cat out.txt | |
echo 'sizes<<EOF' >> $GITHUB_OUTPUT | |
while IFS= read -r line; do | |
echo "$line" >> $GITHUB_OUTPUT | |
done <<< $(cat out.txt) | |
echo 'EOF' >> $GITHUB_OUTPUT | |
- name: "calculate diff" | |
run: | | |
# diff exits with status 1 if there is a diff | |
diff -u main/out.txt ${{ steps.find-pr-txt.outputs.txtPath }} > dev-diff.txt || echo "Differences exist" | |
cat dev-diff.txt | |
- name: "store diff in GITHUB_OUTPUT" | |
id: dev-diff | |
run: | | |
echo 'diffText<<EOF' >> $GITHUB_OUTPUT | |
while IFS= read -r line; do | |
echo "$line" >> $GITHUB_OUTPUT | |
done <<< $(cat ./dev-diff.txt) | |
echo 'EOF' >> $GITHUB_OUTPUT | |
- name: "collected data from artifacts" | |
run: | | |
echo "PR number" | |
echo -e "${{ steps.find-pr-number.outputs.prNumber }}" | |
echo "Main out.txt" | |
echo -e "${{ steps.main-dev.outputs.sizes }}" | |
echo "PR out.txt" | |
echo -e "${{ steps.dev.outputs.sizes }}" | |
echo "Dev diff" | |
echo -e "${{ steps.dev-diff.outputs.diffText }}" | |
######################### | |
# Intended Layout: | |
# | |
# | This PR | Main | | |
# | x1 | y1 | | |
# | x2 | y2 | | |
# | |
######################### | |
- uses: mshick/add-pr-comment@v2 | |
with: | |
issue: ${{ steps.find-pr-number.outputs.prNumber }} | |
message: | | |
<details><summary>Estimated Asset Sizes</summary> | |
Diff | |
```diff | |
${{ steps.dev-diff.outputs.diffText }} | |
``` | |
Details | |
<table><thead><tr><th>This PR</th><th>main</th></tr></thead> | |
<tbody> | |
<tr><td> | |
``` | |
${{ steps.dev.outputs.sizes }} | |
``` | |
</td><td> | |
``` | |
${{ steps.main-dev.outputs.sizes }} | |
``` | |
</td></tr> | |
</tbody></table> | |
</details> | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |