javascript-format-build.yml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. name: Javascript
  2. # This action works with pull requests and pushes
  3. on:
  4. push:
  5. paths:
  6. - web/**
  7. - '!**.md'
  8. pull_request:
  9. paths:
  10. - web/**
  11. - '!**.md'
  12. jobs:
  13. formatting:
  14. name: Code formatting
  15. runs-on: ubuntu-latest
  16. defaults:
  17. run:
  18. working-directory: ./web
  19. steps:
  20. - id: skip_check
  21. uses: fkirc/skip-duplicate-actions@v5
  22. with:
  23. concurrent_skipping: 'same_content_newer'
  24. cancel_others: 'true'
  25. skip_after_successful_duplicate: 'true'
  26. - name: Checkout
  27. uses: actions/checkout@v4
  28. with:
  29. # Make sure the actual branch is checked out when running on pull requests
  30. ref: ${{ github.event.pull_request.head.ref }}
  31. repository: ${{ github.event.pull_request.head.repo.full_name }}
  32. fetch-depth: 0
  33. persist-credentials: true
  34. - name: Get changed files
  35. id: changed-files-yaml
  36. uses: tj-actions/changed-files@v40
  37. with:
  38. path: 'web'
  39. files_ignore: |
  40. static/**
  41. web/next.config.js
  42. files_yaml: |
  43. src:
  44. - '**/*.{js,ts,tsx,jsx,css,md}'
  45. - name: Cache node modules
  46. uses: actions/cache@v3
  47. env:
  48. cache-name: cache-node-modules-bundle-web-app
  49. with:
  50. path: ~/.npm
  51. key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('web/package-lock.json') }}
  52. restore-keys: |
  53. ${{ runner.os }}-build-${{ env.cache-name }}-
  54. ${{ runner.os }}-build-
  55. ${{ runner.os }}-
  56. - name: Install Dependencies
  57. run: npm install
  58. - name: Lint
  59. if: steps.changed-files-yaml.outputs.src_any_changed == 'true'
  60. run: npx eslint --fix ${{ steps.changed-files-yaml.outputs.src_all_changed_files }}
  61. - name: Prettier
  62. if: steps.changed-files-yaml.outputs.src_any_changed == 'true'
  63. run: npx prettier --write ${{ steps.changed-files-yaml.outputs.src_all_changed_files }}
  64. - name: Commit changes
  65. if: steps.changed-files-yaml.outputs.src_any_changed == 'true'
  66. uses: EndBug/add-and-commit@v9
  67. with:
  68. author_name: Owncast
  69. author_email: owncast@owncast.online
  70. message: 'Javascript formatting autofixes'
  71. add: ${{ steps.changed-files-yaml.outputs.src_all_changed_files }}
  72. pull: '--rebase --autostash'
  73. unused-code:
  74. name: Test for unused code
  75. runs-on: ubuntu-latest
  76. defaults:
  77. run:
  78. working-directory: ./web
  79. steps:
  80. - id: skip_check
  81. uses: fkirc/skip-duplicate-actions@v5
  82. with:
  83. concurrent_skipping: 'same_content_newer'
  84. cancel_others: 'true'
  85. skip_after_successful_duplicate: 'true'
  86. - name: Checkout
  87. uses: actions/checkout@v4
  88. with:
  89. # Make sure the actual branch is checked out when running on pull requests
  90. ref: ${{ github.event.pull_request.head.ref }}
  91. repository: ${{ github.event.pull_request.head.repo.full_name }}
  92. fetch-depth: 0
  93. - name: Cache node modules
  94. uses: actions/cache@v3
  95. env:
  96. cache-name: cache-node-modules-bundle-web-app
  97. with:
  98. path: ~/.npm
  99. key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('web/package-lock.json') }}
  100. restore-keys: |
  101. ${{ runner.os }}-build-${{ env.cache-name }}-
  102. ${{ runner.os }}-build-
  103. ${{ runner.os }}-
  104. - name: Install Dependencies
  105. run: npm install
  106. - name: Check for unused JS code and dependencies
  107. run: npx knip --include dependencies,files,exports
  108. # After any formatting and linting is complete we can run the build
  109. # and bundle step. This both will verify that the build is successful as
  110. # well as commiting the updated static files into the repository for use.
  111. web-bundle:
  112. name: Build and bundle web project
  113. runs-on: ubuntu-latest
  114. if: github.repository == 'owncast/owncast'
  115. needs: [formatting, unused-code]
  116. steps:
  117. - id: skip_check
  118. uses: fkirc/skip-duplicate-actions@v5
  119. with:
  120. concurrent_skipping: 'same_content_newer'
  121. cancel_others: 'true'
  122. skip_after_successful_duplicate: 'true'
  123. - name: Cache node modules
  124. uses: actions/cache@v3
  125. env:
  126. cache-name: cache-node-modules-bundle-web-app
  127. with:
  128. path: ~/.npm
  129. key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('web/package-lock.json') }}
  130. restore-keys: |
  131. ${{ runner.os }}-build-${{ env.cache-name }}-
  132. ${{ runner.os }}-build-
  133. ${{ runner.os }}-
  134. - name: Checkout
  135. uses: actions/checkout@v4
  136. with:
  137. # Make sure the actual branch is checked out when running on pull requests
  138. ref: ${{ github.event.pull_request.head.ref }}
  139. repository: ${{ github.event.pull_request.head.repo.full_name }}
  140. fetch-depth: 0
  141. - name: Bundle web app (next.js build)
  142. run: build/web/bundleWeb.sh
  143. - name: Rebase
  144. if: ${{ github.ref == 'refs/heads/develop' }}
  145. run: |
  146. git add static/web
  147. git pull --rebase --autostash
  148. # Only commit built web project files on develop.
  149. - name: Commit changes
  150. if: ${{ github.ref == 'refs/heads/develop' }}
  151. uses: EndBug/add-and-commit@v9
  152. with:
  153. message: 'Bundle embedded web app'
  154. add: 'static/web'
  155. author_name: Owncast
  156. author_email: owncast@owncast.online
  157. - name: Push changes
  158. if: ${{ github.ref == 'refs/heads/develop' }}
  159. run: |
  160. git pull --rebase --autostash
  161. git push