e2e.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. name: End-to-end tests
  2. on:
  3. push:
  4. branches: [main]
  5. paths-ignore:
  6. - '**.md'
  7. - '**.d.ts'
  8. - 'examples/**'
  9. - 'private/**'
  10. - 'website/**'
  11. - '.github/**'
  12. - '!.github/workflows/e2e.yml'
  13. pull_request_target:
  14. types: [opened, synchronize, reopened, labeled]
  15. paths-ignore:
  16. - '**.md'
  17. - '**.d.ts'
  18. - 'examples/**'
  19. - 'private/**'
  20. - 'website/**'
  21. - '.github/**'
  22. pull_request:
  23. types: [opened, synchronize, reopened]
  24. paths:
  25. - .github/workflows/e2e.yml
  26. concurrency:
  27. group: ${{ github.workflow }}--${{ github.ref }}
  28. cancel-in-progress:
  29. # For PRs coming from forks, we need the previous job to run until the end
  30. # to be sure it can remove the `safe to test` label before it affects the next run.
  31. ${{ github.event.pull_request.head.repo.full_name == github.repository }}
  32. permissions:
  33. pull-requests: write
  34. env:
  35. YARN_ENABLE_GLOBAL_CACHE: false
  36. jobs:
  37. compare_diff:
  38. runs-on: ubuntu-latest
  39. env:
  40. DIFF_BUILDER: true
  41. outputs:
  42. diff: ${{ steps.diff.outputs.OUTPUT_DIFF }}
  43. is_accurate_diff: ${{ steps.diff.outputs.IS_ACCURATE_DIFF }}
  44. steps:
  45. - name: Checkout sources
  46. uses: actions/checkout@v3
  47. with:
  48. fetch-depth: 2
  49. ref: refs/pull/${{ github.event.pull_request.number }}/merge
  50. - name: Check if there are "unsafe" changes
  51. id: build_chain_changes
  52. # If there are changes in JS script that generates the output, we cannot
  53. # test them here without human review to make sure they don't contain
  54. # someting "nasty".
  55. run: |
  56. EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
  57. echo "MIGHT_CONTAIN_OTHER_CHANGES<<$EOF" >> "$GITHUB_OUTPUT"
  58. git --no-pager diff HEAD^ --name-only bin package.json yarn.lock babel.config.js >> "$GITHUB_OUTPUT"
  59. echo "$EOF" >> "$GITHUB_OUTPUT"
  60. - run: git reset HEAD^ --hard
  61. - name: Get yarn cache directory path
  62. id: yarn-cache-dir-path
  63. run:
  64. echo "dir=$(corepack yarn config get cacheFolder)" >> $GITHUB_OUTPUT
  65. - uses: actions/cache@v3
  66. id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
  67. with:
  68. path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
  69. key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
  70. restore-keys: |
  71. ${{ runner.os }}-yarn-
  72. - name: Install Node.js
  73. uses: actions/setup-node@v3
  74. with:
  75. node-version: lts/*
  76. - name: Install dependencies
  77. run:
  78. corepack yarn workspaces focus $(corepack yarn workspaces list --json
  79. | jq -r .name | awk '/^@uppy-example/{ next } { if ($0!="uppy.io")
  80. print $0 }')
  81. env:
  82. # https://docs.cypress.io/guides/references/advanced-installation#Skipping-installation
  83. CYPRESS_INSTALL_BINARY: 0
  84. - run: corepack yarn build:lib
  85. - name: Store output file
  86. run: tar cf /tmp/previousVersion.tar packages/@uppy/*/lib
  87. - name: Fetch source from the PR
  88. if: steps.build_chain_changes.outputs.MIGHT_CONTAIN_OTHER_CHANGES == ''
  89. run: |
  90. git checkout FETCH_HEAD -- packages
  91. echo 'IS_ACCURATE_DIFF=true' >> "$GITHUB_ENV"
  92. - name: Fetch source from the PR
  93. if:
  94. steps.build_chain_changes.outputs.MIGHT_CONTAIN_OTHER_CHANGES != '' &&
  95. (!github.event.pull_request ||
  96. (contains(github.event.pull_request.labels.*.name, 'safe to test') &&
  97. github.event.pull_request.state == 'open') ||
  98. (github.event.pull_request.head.repo.full_name == github.repository &&
  99. github.event.event_name != 'labeled'))
  100. run: |
  101. git reset FETCH_HEAD --hard
  102. corepack yarn workspaces focus $(\
  103. corepack yarn workspaces list --json | \
  104. jq -r .name | \
  105. awk '/^@uppy-example/{ next } { if ($0!="uppy.io") print $0 }'\
  106. )
  107. echo 'IS_ACCURATE_DIFF=true' >> "$GITHUB_ENV"
  108. env:
  109. # https://docs.cypress.io/guides/references/advanced-installation#Skipping-installation
  110. CYPRESS_INSTALL_BINARY: 0
  111. - run: corepack yarn build:lib
  112. - name: Store output file
  113. run: tar cf /tmp/newVersion.tar packages/@uppy/*/lib
  114. - name: Setup git
  115. run: |
  116. git config --global user.email "actions@github.com"
  117. git config --global user.name "GitHub Actions"
  118. git init /tmp/uppy
  119. echo '*.map' > /tmp/uppy/.gitignore
  120. - name: Install dformat
  121. run: |
  122. curl -fsSL https://dprint.dev/install.sh | sh
  123. cd /tmp/uppy && echo '{"plugins":[]}' > dprint.json && "$HOME/.dprint/bin/dprint" config add typescript
  124. - name: Extract previous version
  125. run: cd /tmp/uppy && tar xf /tmp/previousVersion.tar
  126. - name: Format previous output code
  127. run: cd /tmp/uppy && "$HOME/.dprint/bin/dprint" fmt **/*.js
  128. - name: Commit previous version
  129. run: cd /tmp/uppy && git add -A . && git commit -m 'previous version'
  130. - name: Extract new version
  131. run: cd /tmp/uppy && tar xf /tmp/newVersion.tar
  132. - name: Format new output code
  133. run: cd /tmp/uppy && "$HOME/.dprint/bin/dprint" fmt **/*.js
  134. - name: Build diff
  135. id: diff
  136. run: |
  137. EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
  138. echo "OUTPUT_DIFF<<$EOF" >> "$GITHUB_OUTPUT"
  139. cd /tmp/uppy && git --no-pager diff >> "$GITHUB_OUTPUT"
  140. echo "$EOF" >> "$GITHUB_OUTPUT"
  141. echo "IS_ACCURATE_DIFF=$IS_ACCURATE_DIFF" >> "$GITHUB_OUTPUT"
  142. - name: Add/update comment
  143. uses: marocchino/sticky-pull-request-comment@v2
  144. with:
  145. message: |
  146. <details><summary>Diff output files</summary>
  147. ```diff
  148. ${{ steps.diff.outputs.OUTPUT_DIFF || 'No diff' }}
  149. ```
  150. ${{ env.IS_ACCURATE_DIFF != 'true' && format('The following build files have been modified and might affect the actual diff:\n\n```\n{0}```', steps.build_chain_changes.outputs.MIGHT_CONTAIN_OTHER_CHANGES) || '' }}
  151. </details>
  152. - name: Remove 'safe to test' label if cancelled
  153. if:
  154. cancelled() && github.event.pull_request.head.repo.full_name !=
  155. github.repository
  156. run: gh pr edit "$NUMBER" --remove-label 'safe to test'
  157. env:
  158. NUMBER: ${{ github.event.pull_request.number }}
  159. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  160. toggle-pending-e2e-label:
  161. # Add the 'pending end-to-end tests' label for PRs that come from forks.
  162. # For those PRs, we want to review the code before running e2e tests.
  163. # See https://securitylab.github.com/research/github-actions-preventing-pwn-requests/.
  164. needs: [compare_diff]
  165. if:
  166. github.event.pull_request.state == 'open' &&
  167. github.event.pull_request.head.repo.full_name != github.repository
  168. runs-on: ubuntu-latest
  169. steps:
  170. - name: Add label
  171. if:
  172. (needs.compare_diff.outputs.diff != '' ||
  173. !needs.compare_diff.outputs.is_accurate_diff) &&
  174. (!contains(github.event.pull_request.labels.*.name, 'safe to test') &&
  175. !contains(github.event.pull_request.labels.*.name, 'pending end-to-end
  176. tests'))
  177. env:
  178. NUMBER: ${{ github.event.pull_request.number }}
  179. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  180. run:
  181. gh pr edit "$NUMBER" --repo ${{ github.repository }} --add-label
  182. 'pending end-to-end tests'
  183. - name: Remove label
  184. if:
  185. needs.compare_diff.outputs.diff == '' &&
  186. needs.compare_diff.outputs.is_accurate_diff &&
  187. (contains(github.event.pull_request.labels.*.name, 'safe to test') ||
  188. contains(github.event.pull_request.labels.*.name, 'pending end-to-end
  189. tests'))
  190. env:
  191. NUMBER: ${{ github.event.pull_request.number }}
  192. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  193. run:
  194. gh pr edit "$NUMBER" --remove-label 'safe to test' --remove-label
  195. 'pending end-to-end tests'
  196. e2e:
  197. needs: [compare_diff]
  198. if:
  199. ${{ needs.compare_diff.outputs.diff != '' && (!github.event.pull_request
  200. || (contains(github.event.pull_request.labels.*.name, 'safe to test') &&
  201. github.event.pull_request.state == 'open') ||
  202. (github.event.pull_request.head.repo.full_name == github.repository &&
  203. github.event.event_name != 'labeled')) }}
  204. name: Browser tests
  205. runs-on: ubuntu-latest
  206. steps:
  207. - name: Checkout sources
  208. uses: actions/checkout@v3
  209. with:
  210. ref: ${{ github.event.pull_request.head.sha || github.sha }}
  211. - name: Get yarn cache directory path
  212. id: yarn-cache-dir-path
  213. run:
  214. echo "dir=$(corepack yarn config get cacheFolder)" >> $GITHUB_OUTPUT
  215. - uses: actions/cache@v3
  216. id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
  217. with:
  218. path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
  219. key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
  220. restore-keys: |
  221. ${{ runner.os }}-yarn-
  222. - name: Create cache folder for Cypress
  223. id: cypress-cache-dir-path
  224. run: echo "dir=$(mktemp -d)" >> $GITHUB_OUTPUT
  225. - uses: actions/cache@v3
  226. with:
  227. path: ${{ steps.cypress-cache-dir-path.outputs.dir }}
  228. key: ${{ runner.os }}-cypress
  229. - name: Install Node.js
  230. uses: actions/setup-node@v3
  231. with:
  232. node-version: lts/*
  233. - name: Start Redis
  234. uses: supercharge/redis-github-action@1.4.0
  235. with:
  236. redis-version: 7
  237. - name: Install dependencies
  238. run: corepack yarn install --immutable
  239. env:
  240. # https://docs.cypress.io/guides/references/advanced-installation#Binary-cache
  241. CYPRESS_CACHE_FOLDER: ${{ steps.cypress-cache-dir-path.outputs.dir }}
  242. - name: Build Uppy packages
  243. run: corepack yarn build
  244. - name: Run end-to-end browser tests
  245. run: corepack yarn run e2e:ci
  246. env:
  247. COMPANION_DATADIR: ./output
  248. COMPANION_DOMAIN: localhost:3020
  249. COMPANION_PROTOCOL: http
  250. COMPANION_REDIS_URL: redis://localhost:6379
  251. COMPANION_UNSPLASH_KEY: ${{secrets.COMPANION_UNSPLASH_KEY}}
  252. COMPANION_UNSPLASH_SECRET: ${{secrets.COMPANION_UNSPLASH_SECRET}}
  253. COMPANION_AWS_KEY: ${{secrets.COMPANION_AWS_KEY}}
  254. COMPANION_AWS_SECRET: ${{secrets.COMPANION_AWS_SECRET}}
  255. COMPANION_AWS_BUCKET: ${{secrets.COMPANION_AWS_BUCKET}}
  256. COMPANION_AWS_REGION: ${{secrets.COMPANION_AWS_REGION}}
  257. VITE_COMPANION_URL: http://localhost:3020
  258. VITE_TRANSLOADIT_KEY: ${{secrets.TRANSLOADIT_KEY}}
  259. VITE_TRANSLOADIT_SECRET: ${{secrets.TRANSLOADIT_SECRET}}
  260. VITE_TRANSLOADIT_TEMPLATE: ${{secrets.TRANSLOADIT_TEMPLATE}}
  261. VITE_TRANSLOADIT_SERVICE_URL: ${{secrets.TRANSLOADIT_SERVICE_URL}}
  262. # https://docs.cypress.io/guides/references/advanced-installation#Binary-cache
  263. CYPRESS_CACHE_FOLDER: ${{ steps.cypress-cache-dir-path.outputs.dir }}
  264. - name: Upload videos in case of failure
  265. uses: actions/upload-artifact@v3
  266. if: failure()
  267. with:
  268. name: videos-and-screenshots
  269. path: |
  270. e2e/cypress/videos/
  271. e2e/cypress/screenshots/
  272. - name: Remove labels
  273. if:
  274. always() && github.event.pull_request.head.repo.full_name !=
  275. github.repository
  276. run:
  277. gh pr edit "$NUMBER" --remove-label 'safe to test' --remove-label
  278. 'pending end-to-end tests'
  279. env:
  280. NUMBER: ${{ github.event.pull_request.number }}
  281. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}