1
0

command-compile.yml 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. # This workflow is provided via the organization template repository
  2. #
  3. # https://github.com/nextcloud/.github
  4. # https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization
  5. #
  6. # SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors
  7. # SPDX-License-Identifier: MIT
  8. name: Compile Command
  9. on:
  10. issue_comment:
  11. types: [created]
  12. jobs:
  13. init:
  14. runs-on: ubuntu-latest
  15. # On pull requests and if the comment starts with `/compile`
  16. if: github.event.issue.pull_request != '' && startsWith(github.event.comment.body, '/compile')
  17. outputs:
  18. git_path: ${{ steps.git-path.outputs.path }}
  19. arg1: ${{ steps.command.outputs.arg1 }}
  20. arg2: ${{ steps.command.outputs.arg2 }}
  21. head_ref: ${{ steps.comment-branch.outputs.head_ref }}
  22. base_ref: ${{ steps.comment-branch.outputs.base_ref }}
  23. steps:
  24. - name: Get repository from pull request comment
  25. uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
  26. id: get-repository
  27. with:
  28. github-token: ${{secrets.GITHUB_TOKEN}}
  29. script: |
  30. const pull = await github.rest.pulls.get({
  31. owner: context.repo.owner,
  32. repo: context.repo.repo,
  33. pull_number: context.issue.number
  34. });
  35. const repositoryName = pull.data.head?.repo?.full_name
  36. console.log(repositoryName)
  37. return repositoryName
  38. - name: Disabled on forks
  39. if: ${{ fromJSON(steps.get-repository.outputs.result) != github.repository }}
  40. run: |
  41. echo 'Can not execute /compile on forks'
  42. exit 1
  43. - name: Check actor permission
  44. uses: skjnldsv/check-actor-permission@69e92a3c4711150929bca9fcf34448c5bf5526e7 # v2
  45. with:
  46. require: write
  47. - name: Add reaction on start
  48. uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
  49. with:
  50. token: ${{ secrets.COMMAND_BOT_PAT }}
  51. repository: ${{ github.event.repository.full_name }}
  52. comment-id: ${{ github.event.comment.id }}
  53. reactions: '+1'
  54. - name: Parse command
  55. uses: skjnldsv/parse-command-comment@5c955203c52424151e6d0e58fb9de8a9f6a605a1 # v2
  56. id: command
  57. # Init path depending on which command is run
  58. - name: Init path
  59. id: git-path
  60. run: |
  61. if ${{ startsWith(steps.command.outputs.arg1, '/') }}; then
  62. echo "path=${{steps.command.outputs.arg1}}" >> $GITHUB_OUTPUT
  63. else
  64. echo "path=${{steps.command.outputs.arg2}}" >> $GITHUB_OUTPUT
  65. fi
  66. - name: Init branch
  67. uses: xt0rted/pull-request-comment-branch@d97294d304604fa98a2600a6e2f916a84b596dc7 # v1
  68. id: comment-branch
  69. - name: Add reaction on failure
  70. uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
  71. if: failure()
  72. with:
  73. token: ${{ secrets.COMMAND_BOT_PAT }}
  74. repository: ${{ github.event.repository.full_name }}
  75. comment-id: ${{ github.event.comment.id }}
  76. reactions: "-1"
  77. process:
  78. runs-on: ubuntu-latest
  79. needs: init
  80. steps:
  81. - name: Restore cached git repository
  82. uses: buildjet/cache@e376f15c6ec6dc595375c78633174c7e5f92dc0e # v3
  83. with:
  84. path: .git
  85. key: git-repo
  86. - name: Checkout ${{ needs.init.outputs.head_ref }}
  87. uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
  88. with:
  89. token: ${{ secrets.COMMAND_BOT_PAT }}
  90. fetch-depth: 0
  91. ref: ${{ needs.init.outputs.head_ref }}
  92. - name: Setup git
  93. run: |
  94. git config --local user.email 'nextcloud-command@users.noreply.github.com'
  95. git config --local user.name 'nextcloud-command'
  96. - name: Read package.json node and npm engines version
  97. uses: skjnldsv/read-package-engines-version-actions@06d6baf7d8f41934ab630e97d9e6c0bc9c9ac5e4 # v3
  98. id: package-engines-versions
  99. with:
  100. fallbackNode: '^20'
  101. fallbackNpm: '^10'
  102. - name: Set up node ${{ steps.package-engines-versions.outputs.nodeVersion }}
  103. uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v3
  104. with:
  105. node-version: ${{ steps.package-engines-versions.outputs.nodeVersion }}
  106. cache: npm
  107. - name: Set up npm ${{ steps.package-engines-versions.outputs.npmVersion }}
  108. run: npm i -g 'npm@${{ steps.package-engines-versions.outputs.npmVersion }}'
  109. - name: Rebase to ${{ needs.init.outputs.base_ref }}
  110. if: ${{ contains(needs.init.outputs.arg1, 'rebase') }}
  111. run: |
  112. git fetch origin '${{ needs.init.outputs.base_ref }}:${{ needs.init.outputs.base_ref }}'
  113. git rebase 'origin/${{ needs.init.outputs.base_ref }}'
  114. - name: Install dependencies & build
  115. env:
  116. CYPRESS_INSTALL_BINARY: 0
  117. PUPPETEER_SKIP_DOWNLOAD: true
  118. run: |
  119. npm ci
  120. npm run build --if-present
  121. - name: Commit default
  122. if: ${{ !contains(needs.init.outputs.arg1, 'fixup') && !contains(needs.init.outputs.arg1, 'amend') }}
  123. run: |
  124. git add '${{ github.workspace }}${{ needs.init.outputs.git_path }}'
  125. git commit --signoff -m 'chore(assets): Recompile assets'
  126. - name: Commit fixup
  127. if: ${{ contains(needs.init.outputs.arg1, 'fixup') }}
  128. run: |
  129. git add '${{ github.workspace }}${{ needs.init.outputs.git_path }}'
  130. git commit --fixup=HEAD --signoff
  131. - name: Commit amend
  132. if: ${{ contains(needs.init.outputs.arg1, 'amend') }}
  133. run: |
  134. git add '${{ github.workspace }}${{ needs.init.outputs.git_path }}'
  135. git commit --amend --no-edit --signoff
  136. # Remove any [skip ci] from the amended commit
  137. git commit --amend -m "$(git log -1 --format='%B' | sed '/\[skip ci\]/d')"
  138. - name: Push normally
  139. if: ${{ !contains(needs.init.outputs.arg1, 'rebase') && !contains(needs.init.outputs.arg1, 'amend') }}
  140. run: git push origin '${{ needs.init.outputs.head_ref }}'
  141. - name: Force push
  142. if: ${{ contains(needs.init.outputs.arg1, 'rebase') || contains(needs.init.outputs.arg1, 'amend') }}
  143. run: git push --force origin '${{ needs.init.outputs.head_ref }}'
  144. - name: Add reaction on failure
  145. uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
  146. if: failure()
  147. with:
  148. token: ${{ secrets.COMMAND_BOT_PAT }}
  149. repository: ${{ github.event.repository.full_name }}
  150. comment-id: ${{ github.event.comment.id }}
  151. reactions: "-1"