output-watcher.yml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. name: Compare JS output
  2. on:
  3. pull_request:
  4. # We want all branches so we configure types to be the GH default again
  5. types: [opened, synchronize, reopened]
  6. paths:
  7. - '.github/workflows/output-watcher.yml'
  8. - 'bin/build-lib.js'
  9. pull_request_target:
  10. # We want all branches so we configure types to be the GH default again
  11. types: [opened, synchronize, reopened]
  12. paths:
  13. - 'packages/@uppy/*/src/**/*'
  14. permissions:
  15. pull-requests: write
  16. env:
  17. YARN_ENABLE_GLOBAL_CACHE: false
  18. DIFF_BUILDER: true
  19. jobs:
  20. compare_diff:
  21. runs-on: ubuntu-latest
  22. steps:
  23. - name: Checkout sources
  24. uses: actions/checkout@v3
  25. with:
  26. fetch-depth: 2
  27. ref: refs/pull/${{ github.event.pull_request.number }}/merge
  28. - run: git reset HEAD^ --hard
  29. - name: Get yarn cache directory path
  30. id: yarn-cache-dir-path
  31. run:
  32. echo "dir=$(corepack yarn config get cacheFolder)" >> $GITHUB_OUTPUT
  33. - uses: actions/cache@v3
  34. id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
  35. with:
  36. path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
  37. key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
  38. restore-keys: |
  39. ${{ runner.os }}-yarn-
  40. - name: Install Node.js
  41. uses: actions/setup-node@v3
  42. with:
  43. node-version: lts/*
  44. - name: Install dependencies
  45. run:
  46. corepack yarn workspaces focus $(corepack yarn workspaces list --json
  47. | jq -r .name | awk '/^@uppy-example/{ next } { if ($0!="uppy.io")
  48. print $0 }')
  49. env:
  50. # https://docs.cypress.io/guides/references/advanced-installation#Skipping-installation
  51. CYPRESS_INSTALL_BINARY: 0
  52. - run: corepack yarn build:lib
  53. - name: Store output file
  54. run: tar cf /tmp/previousVersion.tar packages/@uppy/*/lib
  55. - name: Fetch source from the PR
  56. run: git checkout FETCH_HEAD -- packages
  57. - run: corepack yarn build:lib
  58. - name: Store output file
  59. run: tar cf /tmp/newVersion.tar packages/@uppy/*/lib
  60. - name: Setup git
  61. run: |
  62. git config --global user.email "actions@github.com"
  63. git config --global user.name "GitHub Actions"
  64. git init /tmp/uppy
  65. echo '*.map' > /tmp/uppy/.gitignore
  66. - name: Install dformat
  67. run: |
  68. curl -fsSL https://dprint.dev/install.sh | sh
  69. cd /tmp/uppy && echo '{"plugins":[]}' > dprint.json && "$HOME/.dprint/bin/dprint" config add typescript
  70. - name: Extract previous version
  71. run: cd /tmp/uppy && tar xf /tmp/previousVersion.tar
  72. - name: Format previous output code
  73. run: cd /tmp/uppy && "$HOME/.dprint/bin/dprint" fmt **/*.js
  74. - name: Commit previous version
  75. run: cd /tmp/uppy && git add -A . && git commit -m 'previous version'
  76. - name: Extract new version
  77. run: cd /tmp/uppy && tar xf /tmp/newVersion.tar
  78. - name: Format new output code
  79. run: cd /tmp/uppy && "$HOME/.dprint/bin/dprint" fmt **/*.js
  80. - name: Build diff
  81. id: diff
  82. run: |
  83. EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
  84. echo "OUTPUT_DIFF<<$EOF" >> "$GITHUB_OUTPUT"
  85. cd /tmp/uppy && git --no-pager diff >> "$GITHUB_OUTPUT"
  86. echo "$EOF" >> "$GITHUB_OUTPUT"
  87. - name: Add/update comment
  88. uses: marocchino/sticky-pull-request-comment@v2
  89. with:
  90. message: |
  91. <details><summary>Diff output files</summary>
  92. ```diff
  93. ${{ steps.diff.outputs.OUTPUT_DIFF || 'No diff' }}
  94. ```
  95. </details>