Size: Comment #64
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: | |
# better `du` | |
- run: sudo snap install dust | |
- 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 for development outputs" | |
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 for development outputs" | |
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: "[Dev] 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: "[Dev] 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: "[Debug] 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 | | |
# | Dev | x1 | y1 | | |
# | Prod | x2 | y2 | | |
# | |
# NOTE: we we don't have a prod build for this library | |
# because we currently expect non-compiler usage | |
# (so consumers should have terser or similar properly configured for DCE) | |
# | |
######################### | |
- uses: mshick/add-pr-comment@v2 | |
with: | |
issue: ${{ steps.find-pr-number.outputs.prNumber }} | |
message: | | |
<details><summary>Development Assets</summary> | |
Diff | |
```diff | |
${{ steps.dev-diff.outputs.diffText }} | |
``` | |
Details | |
<table><thead><tr><th></th><th>This PR</th><th>main</th></tr></thead> | |
<tbody> | |
<tr><td>Dev</td><td> | |
``` | |
${{ steps.dev.outputs.sizes }} | |
``` | |
</td><td> | |
``` | |
${{ steps.main-dev.outputs.sizes }} | |
``` | |
</td></tr> | |
</tbody></table> | |
</details> | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |