Skip to content

ci: check node_modules/ size #3

ci: check node_modules/ size

ci: check node_modules/ size #3

name: Check Node Modules Size
on:
pull_request:
paths:
# `yarn.lock` should no longer be present, but we'll keep this here in case we add it back.
- yarn.lock
- package.json
- package-lock.json
push:
branches:
- "*"
jobs:
analyze-size:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 18
- name: Install dependencies
run: yarn install
- name: Get main branch `node_modules` size
id: main_size
run: echo "MAIN_SIZE=$(du -sh node_modules | awk '{print $1}')" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Analyze `node_modules` size
id: current_size
run: echo "CURRENT_SIZE=$(du -sh node_modules | awk '{print $1}')" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Print sizes
run: |
echo "Main branch size: $MAIN_SIZE"
echo "Current branch size: $CURRENT_SIZE"
- name: Compare sizes and send alert
if: ${{ env.CURRENT_SIZE != env.MAIN_SIZE }}
run: |
echo "Node Modules size has changed!"
echo "Main branch size: $MAIN_SIZE"
echo "Current branch size: $CURRENT_SIZE"
# Add your alerting mechanism here, such as sending a Slack notification, creating an issue, etc.
- name: Create comment with output
if: ${{ env.CURRENT_SIZE != env.MAIN_SIZE }}
uses: actions/github-script@v6
with:
script: |
const body = `\`node_modules/\` size has changed!\n
Main branch size: ${process.env.MAIN_SIZE}\n
Current branch size: ${process.env.CURRENT_SIZE}`
// https://stackoverflow.com/questions/58066966/commenting-a-pull-request-in-a-github-action/76215842#76215842
github.rest.issues.createComment({
body,
issue_number: (await github.rest.repos.listPullRequestsAssociatedWithCommit({
commit_sha: context.sha,
owner: context.repo.owner,
repo: context.repo.repo,
})).data[0].number,
owner: context.repo.owner,
repo: context.repo.repo,
});