Skip to content

Commit

Permalink
Adding pr comment bot that alerts if the size has increased.
Browse files Browse the repository at this point in the history
  • Loading branch information
aasimkhan30 committed Aug 13, 2024
1 parent 91d475f commit a71b717
Showing 1 changed file with 133 additions and 0 deletions.
133 changes: 133 additions & 0 deletions .github/workflows/file-size-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
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

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 [email protected]
echo "Installing Gulp CLI"
npm install --global [email protected]
echo "Installing VSCE"
npm install --global [email protected]
echo "Installing gulp"
npm install --global [email protected]
-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 vsix file sizes
run: |
main_vsix=$(find ./main -name "*.vsix")
pr_vsix=$(find ./main -name "*.vsix")
main_size=$(stat -c%s "$main_vsix")
pr_size=$(stat -c%s "$pr_vsix")
size_diff=$((pr_size - main_size))
percentage_change=$((100 * size_diff / main_size))
echo "Main branch VSIX size: $main_size bytes"
echo "PR branch VSIX size: $pr_size bytes"
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_percentage_change=$percentage_change" >> $GITHUB_ENV
-name: Calculate webview bundle sizes
run: |
main_webview_bundle=$(du -sk ./main/out/src/reactviews/assets | cut -f1)
pr_webview_bundle=$(du -sk ./pr/out/src/reactviews/assets | cut -f1)
size_diff=$((pr_size - main_size))
percentage_change=$((100 * size_diff / main_size))
echo "Main branch bundle size: $main_size KB"
echo "PR branch bundle size: $pr_size KB"
echo "Size difference: $size_diff KB"
echo "Percentage change: $percentage_change%"
echo "main_webview_bundle_size=$main_size" >> $GITHUB_ENV
echo "pr_webview_bundle_size=$pr_size" >> $GITHUB_ENV
echo "webview_bundle_percentage_change=$percentage_change" >> $GITHUB_ENV
- name: Comment on PR with bundle size difference
uses: actions/github-script@v7
with:
script: |
const mainWebviewBundleSize = process.env.main_webview_bundle_size;
const prWebviewBundleSize = process.env.pr_webview_bundle_size;
const webviewBundlePercentageChange = process.env.webview_bundle_percentage_change;
const mainVsixSize = process.env.main_vsix_size;
const prVsixSize = process.env.pr_vsix_size;
const vsixPercentageChange = process.env.vsix_percentage_change;
const comment = `
### VSIX Size Comparison
- **Main branch VSIX size**: ${mainVsixSize} bytes
- **PR branch VSIX size**: ${prVsixSize} bytes
- **Size difference**: ${prVsixSize - mainVsixSize} bytes (${vsixPercentageChange}%)
### Bundle Size Comparison
- **Main branch bundle size**: ${mainWebviewBundleSize} KB
- **PR branch bundle size**: ${prWebviewBundleSize} KB
- **Size difference**: ${prWebviewBundleSize - mainWebviewBundleSize} KB (${percentageChange}%)
`;
console.log(comment);
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
- name: Fail if vsix size is increased by 10% or size is above 25mb
if: ${{ env.vsix_percentage_change > 10 || env.pr_vsix_size > 25000000 }}
run: exit 1

- name: Fail if bundle size is increased by 10%
if: ${{ env.webview_bundle_percentage_change > 10 }}
run: exit 1



0 comments on commit a71b717

Please sign in to comment.