Adding pr comment bot that alerts if the size has increased. (#17976)
* Adding pr comment bot that alerts if the size has increased. * Fixing indentation * Fixing size check logic * Fixing comment api use * Adding right permissions * Fixing comment * Fixing body includes * Fixing stuff * Fixing perm key * fixing output * Adding issue * Adding more permissions * Adding token * Adding result to a markdown file * Fixing summary * Changing threashold to 5% * Fixing pr vsix file path * Adding back comment bot * Fixing find comment step * Fixing markdown step * Adding job level permissions * adding permissions to write PR comments * Switching to markdown path * Replace comment
This commit is contained in:
Родитель
91d475f75a
Коммит
16d4d9c477
|
@ -0,0 +1,146 @@
|
|||
name: File Size Check
|
||||
# Trigger the workflow on PRs to the main branch. It builds the extension in prod mode and checks the size of the
|
||||
# vsix file and webview bundle file and compares it with the main branch. It fails if the size has increased by more than 10%.
|
||||
# For vsix, we also check if the size is greater than 25MB.
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
size-check:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
checks: write
|
||||
actions: read
|
||||
issues: write
|
||||
pull-requests: write
|
||||
|
||||
steps:
|
||||
- name: Checkout main branch
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: main
|
||||
path: './main'
|
||||
|
||||
- name: Checkout PR branch
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
path: './pr'
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '18'
|
||||
|
||||
- name: Install tools
|
||||
run: |
|
||||
echo "Installing Yarn"
|
||||
npm install --global yarn@1.22.19
|
||||
echo "Installing Gulp CLI"
|
||||
npm install --global gulp-cli@2.3.0
|
||||
echo "Installing VSCE"
|
||||
npm install --global vsce@2.9.2
|
||||
echo "Installing gulp"
|
||||
npm install --global gulp@4.0.2
|
||||
|
||||
- name: Build main branch
|
||||
run: |
|
||||
cd main
|
||||
yarn --frozen-lockfile
|
||||
yarn build --prod
|
||||
yarn gulp package:online
|
||||
|
||||
- name: Build PR branch
|
||||
run: |
|
||||
cd pr
|
||||
yarn --frozen-lockfile
|
||||
yarn build --prod
|
||||
yarn gulp package:online
|
||||
|
||||
- name: Calculate webview bundle sizes
|
||||
run: |
|
||||
main_file=$(du -sk ./main/out/src/reactviews/assets | cut -f1)
|
||||
pr_file=$(du -sk ./pr/out/src/reactviews/assets | cut -f1)
|
||||
echo "Main branch bundle size: $main_file KB"
|
||||
echo "PR branch bundle size: $pr_file KB"
|
||||
size_diff=$((pr_file - main_file))
|
||||
percentage_change=$((100 * size_diff / main_file))
|
||||
echo "Size difference: $size_diff KB"
|
||||
echo "Percentage change: $percentage_change%"
|
||||
echo "main_webview_bundle_size=$main_file" >> $GITHUB_ENV
|
||||
echo "pr_webview_bundle_size=$pr_file" >> $GITHUB_ENV
|
||||
echo "webview_size_diff=$size_diff" >> $GITHUB_ENV
|
||||
echo "webview_bundle_percentage_change=$percentage_change" >> $GITHUB_ENV
|
||||
|
||||
- name: Calculate vsix file sizes
|
||||
run: |
|
||||
main_vsix=$(find ./main -name "*.vsix")
|
||||
pr_vsix=$(find ./pr -name "*.vsix")
|
||||
main_size=$(stat -c%s "$main_vsix")
|
||||
pr_size=$(stat -c%s "$pr_vsix")
|
||||
main_size=$((main_size / 1024))
|
||||
pr_size=$((pr_size / 1024))
|
||||
size_diff=$((pr_size - main_size))
|
||||
percentage_change=$((100 * size_diff / main_size))
|
||||
echo "Main branch VSIX size: $main_size KB"
|
||||
echo "PR branch VSIX size: $pr_size KB"
|
||||
echo "Size difference: $size_diff bytes"
|
||||
echo "Percentage change: $percentage_change%"
|
||||
echo "main_vsix_size=$main_size" >> $GITHUB_ENV
|
||||
echo "pr_vsix_size=$pr_size" >> $GITHUB_ENV
|
||||
echo "vsix_size_diff=$size_diff" >> $GITHUB_ENV
|
||||
echo "vsix_percentage_change=$percentage_change" >> $GITHUB_ENV
|
||||
|
||||
- name: Write results as Markdown file
|
||||
run: |
|
||||
echo "### VSIX Size Comparison" > results.md
|
||||
echo "- **Main branch VSIX size**: ${{ env.main_vsix_size }} KB" >> results.md
|
||||
echo "- **PR branch VSIX size**: ${{ env.pr_vsix_size }} KB" >> results.md
|
||||
echo "- **Size difference**: ${{ env.vsix_size_diff }} KB (${{ env.vsix_percentage_change }}%)" >> results.md
|
||||
echo "### React Webview Bundle Size Comparison" >> results.md
|
||||
echo "- **Main branch bundle size**: ${{ env.main_webview_bundle_size }} KB" >> results.md
|
||||
echo "- **PR branch bundle size**: ${{ env.pr_webview_bundle_size }} KB" >> results.md
|
||||
echo "- **Size difference**: ${{ env.webview_size_diff }} KB (${{ env.webview_bundle_percentage_change }}%)" >> results.md
|
||||
|
||||
- name: Find comment
|
||||
uses: peter-evans/find-comment@v3
|
||||
id: fc
|
||||
with:
|
||||
issue-number: ${{ github.event.pull_request.number }}
|
||||
comment-author: 'github-actions[bot]'
|
||||
body-includes: |
|
||||
### VSIX Size Comparison
|
||||
|
||||
- name: Create comment
|
||||
if: steps.fc.outputs.comment-id == ''
|
||||
uses: peter-evans/create-or-update-comment@v4
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
issue-number: ${{ github.event.pull_request.number }}
|
||||
body-path: ./results.md
|
||||
|
||||
- name: Update comment
|
||||
if: steps.fc.outputs.comment-id != ''
|
||||
uses: peter-evans/create-or-update-comment@v4
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
comment-id: ${{ steps.fc.outputs.comment-id }}
|
||||
body-path: ./results.md
|
||||
edit-mode: replace
|
||||
|
||||
- name: Fail if vsix size is increased by 5% or size is above 25mb
|
||||
if: ${{ env.vsix_percentage_change > 5 || env.pr_vsix_size > 25000000 }}
|
||||
run: exit 1
|
||||
|
||||
- name: Fail if bundle size is increased by 5%
|
||||
if: ${{ env.webview_bundle_percentage_change > 5 }}
|
||||
run: exit 1
|
||||
|
||||
|
||||
|
||||
|
||||
|
Загрузка…
Ссылка в новой задаче