read-size.yml 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. name: Read size
  2. on:
  3. pull_request:
  4. paths:
  5. - 'src/**'
  6. - 'package.json'
  7. - 'utils/build/**'
  8. # This workflow runs in a read-only environment. We can safely checkout
  9. # the PR code here.
  10. # Reference:
  11. # https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
  12. permissions:
  13. contents: read
  14. jobs:
  15. read-size:
  16. name: Tree-shaking
  17. runs-on: ubuntu-latest
  18. steps:
  19. - name: Git checkout
  20. uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
  21. - name: Install Node
  22. uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4
  23. with:
  24. node-version: 18
  25. cache: 'npm'
  26. - name: Install dependencies
  27. run: npm ci
  28. - name: Build
  29. run: npm run build
  30. - name: === Test tree-shaking ===
  31. run: npm run test-treeshake
  32. - name: Read bundle sizes
  33. id: read-size
  34. run: |
  35. WEBGL_FILESIZE=$(stat --format=%s build/three.module.min.js)
  36. gzip -k build/three.module.min.js
  37. WEBGL_FILESIZE_GZIP=$(stat --format=%s build/three.module.min.js.gz)
  38. WEBGL_TREESHAKEN=$(stat --format=%s test/treeshake/index.bundle.min.js)
  39. gzip -k test/treeshake/index.bundle.min.js
  40. WEBGL_TREESHAKEN_GZIP=$(stat --format=%s test/treeshake/index.bundle.min.js.gz)
  41. WEBGPU_FILESIZE=$(stat --format=%s build/three.webgpu.min.js)
  42. gzip -k build/three.webgpu.min.js
  43. WEBGPU_FILESIZE_GZIP=$(stat --format=%s build/three.webgpu.min.js.gz)
  44. WEBGPU_TREESHAKEN=$(stat --format=%s test/treeshake/index.webgpu.bundle.min.js)
  45. gzip -k test/treeshake/index.webgpu.bundle.min.js
  46. WEBGPU_TREESHAKEN_GZIP=$(stat --format=%s test/treeshake/index.webgpu.bundle.min.js.gz)
  47. PR=${{ github.event.pull_request.number }}
  48. # write the output in a json file to upload it as artifact
  49. node -pe "JSON.stringify({ filesize: $WEBGL_FILESIZE, gzip: $WEBGL_FILESIZE_GZIP, treeshaken: $WEBGL_TREESHAKEN, treeshakenGzip: $WEBGL_TREESHAKEN_GZIP, filesize2: $WEBGPU_FILESIZE, gzip2: $WEBGPU_FILESIZE_GZIP, treeshaken2: $WEBGPU_TREESHAKEN, treeshakenGzip2: $WEBGPU_TREESHAKEN_GZIP, pr: $PR })" > sizes.json
  50. - name: Upload artifact
  51. uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4
  52. with:
  53. name: sizes
  54. path: sizes.json
粤ICP备19079148号