Add CI workflow to compute diff between files dist files #1
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: Dist Files Size Diff | ||
| on: | ||
| pull_request: | ||
| paths: | ||
| - 'src/*/**' | ||
| - '!src/*/doc/**' | ||
| - '.github/**' | ||
| jobs: | ||
| dist-files-size-diff: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: marocchino/sticky-pull-request-comment@v2 | ||
| with: | ||
| message: | | ||
| ⏳ The dist files size difference is being calculated... | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '22' | ||
| - name: Install tools | ||
| run: | | ||
| git config --global user.email "" | ||
| git config --global user.name "github-action[bot]" | ||
| cd .github/dist-files-size-diff | ||
| npm install | ||
| - run: corepack enable | ||
| - name: Get yarn cache directory path | ||
| id: yarn-cache-dir-path | ||
| run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT | ||
| - uses: actions/cache@v4 | ||
| id: yarn-cache | ||
| with: | ||
| path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | ||
| key: ${{ runner.os }}-yarn-${{ hashFiles('**/package.json') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-yarn- | ||
| - name: Install dependencies and build files (from pull request) | ||
| run: | | ||
| yarn --immutable && yarn build | ||
| - name: Check if dist files are built | ||
| id: changes | ||
| run: echo "STATUS=$(git status --porcelain)" >> $GITHUB_OUTPUT | ||
| - name: Changes were found | ||
| if: steps.changes.outputs.STATUS != '' | ||
| uses: marocchino/sticky-pull-request-comment@v2 | ||
| with: | ||
| message: | | ||
| ⚠️ The dist files size cannot be calculated because we found that dist files are not up-to-date. | ||
| Please make sure to build the dist files (with `yarn build`) before creating a pull request. | ||
| - name: Stop the workflow | ||
| if: steps.changes.outputs.STATUS != '' | ||
| run: exit 1 | ||
| - name: Get dist files size (from pull request) | ||
| id: pr-dist-size | ||
| run: | | ||
| set -e | ||
| find src -mindepth 2 -path '*/assets/dist/*' \( -name "*.js" -o -name "*.css" \) -not \( -path '*/tests/*' -o -path '*/public/*' \) | sort | while read -r file; do | ||
| echo "{\"$file\": {\"size\": $(wc -c < "$file"), \"size_gz\": $(gzip -c "$file" | wc -c), \"size_brotli\": $(brotli -c "$file" | wc -c)}}" | ||
| done | jq -s 'add' -c | ||
| - name: Install dependencies and build files (from reference branch) | ||
| id: base-dist-size | ||
| run: | | ||
| git fetch origin ${{ github.base_ref }}:${{ github.base_ref }} | ||
| git checkout ${{ github.base_ref }} | ||
| yarn --immutable && yarn build | ||
| - name: Get dist files size (from base branch) | ||
| id: base-dist-size | ||
|
Check failure on line 82 in .github/workflows/dist-files-size-diff.yaml
|
||
| run: | | ||
| set -e | ||
| find src -mindepth 2 -path '*/assets/dist/*' \( -name "*.js" -o -name "*.css" \) -not \( -path '*/tests/*' -o -path '*/public/*' \) | sort | while read -r file; do | ||
| echo "{\"$file\": {\"size\": $(wc -c < "$file"), \"size_gz\": $(gzip -c "$file" | wc -c), \"size_brotli\": $(brotli -c "$file" | wc -c)}}" | ||
| done | jq -s 'add' -c | ||
| - name: Generate the diff | ||
| id: diff | ||
| uses: actions/github-script@v7 | ||
| env: | ||
| PR_DIST_SIZE: ${{ steps.pr-dist-size.outputs.result }} | ||
| BASE_DIST_SIZE: ${{ steps.base-dist-size.outputs.result }} | ||
| with: | ||
| script: | | ||
| console.log(process.env.PR_DIST_SIZE); | ||
| console.log(process.env.BASE_DIST_SIZE); | ||
| - name: Comment on the pull request (if any failure) | ||
| if: ${{ failure() }} | ||
| uses: marocchino/sticky-pull-request-comment@v2 | ||
| with: | ||
| message: | | ||
| ❌ The dist files size difference could not be calculated. Please check the logs for more details. | ||
| - name: Comment on the pull request (if success) | ||
| if: ${{ always() && steps.diff.conclusion == 'success' }} | ||
| uses: marocchino/sticky-pull-request-comment@v2 | ||
| with: | ||
| message: | | ||
| ``` | ||
| ${{ steps.diff.outputs.result }} | ||
| ``` | ||