read-size.yml 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
  21. - name: Install Node
  22. uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5
  23. with:
  24. node-version: 22
  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. WEBGPU_NODES_FILESIZE=$(stat --format=%s build/three.webgpu.nodes.min.js)
  48. gzip -k build/three.webgpu.nodes.min.js
  49. WEBGPU_NODES_FILESIZE_GZIP=$(stat --format=%s build/three.webgpu.nodes.min.js.gz)
  50. WEBGPU_NODES_TREESHAKEN=$(stat --format=%s test/treeshake/index.webgpu.nodes.bundle.min.js)
  51. gzip -k test/treeshake/index.webgpu.nodes.bundle.min.js
  52. WEBGPU_NODES_TREESHAKEN_GZIP=$(stat --format=%s test/treeshake/index.webgpu.nodes.bundle.min.js.gz)
  53. PR=${{ github.event.pull_request.number }}
  54. # write the output in a json file to upload it as artifact
  55. 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, filesize3: $WEBGPU_NODES_FILESIZE, gzip3: $WEBGPU_NODES_FILESIZE_GZIP, treeshaken3: $WEBGPU_NODES_TREESHAKEN, treeshakenGzip3: $WEBGPU_NODES_TREESHAKEN_GZIP, pr: $PR })" > sizes.json
  56. - name: Upload artifact
  57. uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
  58. with:
  59. name: sizes
  60. path: sizes.json
粤ICP备19079148号