command-compile.yml 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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: Check actor permission
  25. uses: skjnldsv/check-actor-permission@69e92a3c4711150929bca9fcf34448c5bf5526e7 # v2
  26. with:
  27. require: write
  28. - name: Add reaction on start
  29. uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
  30. with:
  31. token: ${{ secrets.COMMAND_BOT_PAT }}
  32. repository: ${{ github.event.repository.full_name }}
  33. comment-id: ${{ github.event.comment.id }}
  34. reactions: "+1"
  35. - name: Parse command
  36. uses: skjnldsv/parse-command-comment@5c955203c52424151e6d0e58fb9de8a9f6a605a1 # v2
  37. id: command
  38. # Init path depending on which command is run
  39. - name: Init path
  40. id: git-path
  41. run: |
  42. if ${{ startsWith(steps.command.outputs.arg1, '/') }}; then
  43. echo "path=${{steps.command.outputs.arg1}}" >> $GITHUB_OUTPUT
  44. else
  45. echo "path=${{steps.command.outputs.arg2}}" >> $GITHUB_OUTPUT
  46. fi
  47. - name: Init branch
  48. uses: xt0rted/pull-request-comment-branch@d97294d304604fa98a2600a6e2f916a84b596dc7 # v1
  49. id: comment-branch
  50. process:
  51. runs-on: ubuntu-latest
  52. needs: init
  53. steps:
  54. - name: Restore cached git repository
  55. uses: buildjet/cache@e376f15c6ec6dc595375c78633174c7e5f92dc0e # v3
  56. with:
  57. path: .git
  58. key: git-repo
  59. - name: Checkout ${{ needs.init.outputs.head_ref }}
  60. uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
  61. with:
  62. token: ${{ secrets.COMMAND_BOT_PAT }}
  63. fetch-depth: 0
  64. ref: ${{ needs.init.outputs.head_ref }}
  65. - name: Setup git
  66. run: |
  67. git config --local user.email "nextcloud-command@users.noreply.github.com"
  68. git config --local user.name "nextcloud-command"
  69. - name: Read package.json node and npm engines version
  70. uses: skjnldsv/read-package-engines-version-actions@06d6baf7d8f41934ab630e97d9e6c0bc9c9ac5e4 # v3
  71. id: package-engines-versions
  72. with:
  73. fallbackNode: '^20'
  74. fallbackNpm: '^10'
  75. - name: Set up node ${{ steps.package-engines-versions.outputs.nodeVersion }}
  76. uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v3
  77. with:
  78. node-version: ${{ steps.package-engines-versions.outputs.nodeVersion }}
  79. cache: npm
  80. - name: Set up npm ${{ steps.package-engines-versions.outputs.npmVersion }}
  81. run: npm i -g npm@"${{ steps.package-engines-versions.outputs.npmVersion }}"
  82. - name: Rebase to ${{ needs.init.outputs.base_ref }}
  83. if: ${{ contains(needs.init.outputs.arg1, 'rebase') }}
  84. run: |
  85. git fetch origin ${{ needs.init.outputs.base_ref }}:${{ needs.init.outputs.base_ref }}
  86. git rebase origin/${{ needs.init.outputs.base_ref }}
  87. - name: Install dependencies & build
  88. env:
  89. CYPRESS_INSTALL_BINARY: 0
  90. PUPPETEER_SKIP_DOWNLOAD: true
  91. run: |
  92. npm ci
  93. npm run build --if-present
  94. - name: Commit default
  95. if: ${{ !contains(needs.init.outputs.arg1, 'fixup') && !contains(needs.init.outputs.arg1, 'amend') }}
  96. run: |
  97. git add ${{ github.workspace }}${{ needs.init.outputs.git_path }}
  98. git commit --signoff -m 'chore(assets): Recompile assets'
  99. - name: Commit fixup
  100. if: ${{ contains(needs.init.outputs.arg1, 'fixup') }}
  101. run: |
  102. git add ${{ github.workspace }}${{ needs.init.outputs.git_path }}
  103. git commit --fixup=HEAD --signoff
  104. - name: Commit amend
  105. if: ${{ contains(needs.init.outputs.arg1, 'amend') }}
  106. run: |
  107. git add ${{ github.workspace }}${{ needs.init.outputs.git_path }}
  108. git commit --amend --no-edit --signoff
  109. # Remove any [skip ci] from the amended commit
  110. git commit --amend -m "$(git log -1 --format='%B' | sed '/\[skip ci\]/d')"
  111. - name: Push normally
  112. if: ${{ !contains(needs.init.outputs.arg1, 'rebase') && !contains(needs.init.outputs.arg1, 'amend') }}
  113. run: git push origin ${{ needs.init.outputs.head_ref }}
  114. - name: Force push
  115. if: ${{ contains(needs.init.outputs.arg1, 'rebase') || contains(needs.init.outputs.arg1, 'amend') }}
  116. run: git push --force origin ${{ needs.init.outputs.head_ref }}
  117. - name: Add reaction on failure
  118. uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
  119. if: failure()
  120. with:
  121. token: ${{ secrets.COMMAND_BOT_PAT }}
  122. repository: ${{ github.event.repository.full_name }}
  123. comment-id: ${{ github.event.comment.id }}
  124. reactions: "-1"