command-compile.yml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. name: Compile Command
  2. on:
  3. issue_comment:
  4. types: [created]
  5. jobs:
  6. init:
  7. runs-on: ubuntu-latest
  8. # On pull requests and if the comment starts with `/compile`
  9. if: github.event.issue.pull_request != '' && startsWith(github.event.comment.body, '/compile')
  10. outputs:
  11. git_path: ${{ steps.git-path.outputs.path }}
  12. arg1: ${{ steps.command.outputs.arg1 }}
  13. arg2: ${{ steps.command.outputs.arg2 }}
  14. head_ref: ${{ steps.comment-branch.outputs.head_ref }}
  15. steps:
  16. - name: Check actor permission
  17. uses: skjnldsv/check-actor-permission@v2
  18. with:
  19. require: write
  20. - name: Add reaction on start
  21. uses: peter-evans/create-or-update-comment@v1
  22. with:
  23. token: ${{ secrets.COMMAND_BOT_PAT }}
  24. repository: ${{ github.event.repository.full_name }}
  25. comment-id: ${{ github.event.comment.id }}
  26. reaction-type: "+1"
  27. - name: Parse command
  28. uses: skjnldsv/parse-command-comment@master
  29. id: command
  30. # Init path depending on which command is run
  31. - name: Init path
  32. id: git-path
  33. run: |
  34. if ${{ startsWith(steps.command.outputs.arg1, '/') }}; then
  35. echo "::set-output name=path::${{ github.workspace }}${{steps.command.outputs.arg1}}"
  36. else
  37. echo "::set-output name=path::${{ github.workspace }}${{steps.command.outputs.arg2}}"
  38. fi
  39. - name: Init branch
  40. uses: xt0rted/pull-request-comment-branch@v1
  41. id: comment-branch
  42. process:
  43. runs-on: ubuntu-latest
  44. needs: init
  45. steps:
  46. - name: Checkout ${{ needs.init.outputs.head_ref }}
  47. uses: actions/checkout@v2
  48. with:
  49. token: ${{ secrets.COMMAND_BOT_PAT }}
  50. fetch-depth: 0
  51. ref: ${{ needs.init.outputs.head_ref }}
  52. - name: Setup git
  53. run: |
  54. git config --local user.email "nextcloud-command@users.noreply.github.com"
  55. git config --local user.name "nextcloud-command"
  56. - name: Read package.json node and npm engines version
  57. uses: skjnldsv/read-package-engines-version-actions@v1
  58. id: package-engines-versions
  59. with:
  60. fallbackNode: '^12'
  61. fallbackNpm: '^6'
  62. - name: Set up node ${{ steps.package-engines-versions.outputs.nodeVersion }}
  63. uses: actions/setup-node@v2
  64. with:
  65. node-version: ${{ steps.package-engines-versions.outputs.nodeVersion }}
  66. cache: npm
  67. - name: Set up npm ${{ steps.package-engines-versions.outputs.npmVersion }}
  68. run: npm i -g npm@"${{ steps.package-engines-versions.outputs.npmVersion }}"
  69. - name: Install dependencies & build
  70. run: |
  71. npm ci
  72. npm run build --if-present
  73. - name: Commit and push default
  74. if: ${{ needs.init.outputs.arg1 != 'fixup' && needs.init.outputs.arg1 != 'amend' }}
  75. run: |
  76. git add ${{ needs.init.outputs.git_path }}
  77. git commit --signoff -m 'Compile assets'
  78. git push origin ${{ needs.init.outputs.head_ref }}
  79. - name: Commit and push fixup
  80. if: ${{ needs.init.outputs.arg1 == 'fixup' }}
  81. run: |
  82. git add ${{ needs.init.outputs.git_path }}
  83. git commit --fixup=HEAD --signoff
  84. git push origin ${{ needs.init.outputs.head_ref }}
  85. - name: Commit and push amend
  86. if: ${{ needs.init.outputs.arg1 == 'amend' }}
  87. run: |
  88. git add ${{ needs.init.outputs.git_path }}
  89. git commit --amend --no-edit --signoff
  90. git push --force origin ${{ needs.init.outputs.head_ref }}
  91. - name: Add reaction on failure
  92. uses: peter-evans/create-or-update-comment@v1
  93. if: failure()
  94. with:
  95. token: ${{ secrets.COMMAND_BOT_PAT }}
  96. repository: ${{ github.event.repository.full_name }}
  97. comment-id: ${{ github.event.comment.id }}
  98. reaction-type: "-1"