command-compile.yml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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@e591dbfe838300c007028e1219ca82cc26e8d7c5 # v2
  18. with:
  19. require: write
  20. - name: Add reaction on start
  21. uses: peter-evans/create-or-update-comment@ca08ebd5dc95aa0cd97021e9708fcd6b87138c9b # v3.0.1
  22. with:
  23. token: ${{ secrets.COMMAND_BOT_PAT }}
  24. repository: ${{ github.event.repository.full_name }}
  25. comment-id: ${{ github.event.comment.id }}
  26. reactions: "+1"
  27. - name: Parse command
  28. uses: skjnldsv/parse-command-comment@7cef1df370a99dfd5bf896d50121390c96785db8 # v2
  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 "path=${{ github.workspace }}${{steps.command.outputs.arg1}}" >> $GITHUB_OUTPUT
  36. else
  37. echo "path=${{ github.workspace }}${{steps.command.outputs.arg2}}" >> $GITHUB_OUTPUT
  38. fi
  39. - name: Init branch
  40. uses: xt0rted/pull-request-comment-branch@d97294d304604fa98a2600a6e2f916a84b596dc7 # 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@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
  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@0ce2ed60f6df073a62a77c0a4958dd0fc68e32e7 # v2.1
  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@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
  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: Build css
  74. run: npm run --if-present sass
  75. - name: Build icons css
  76. run: npm run --if-present sass:icons
  77. - name: Commit and push default
  78. if: ${{ needs.init.outputs.arg1 != 'fixup' && needs.init.outputs.arg1 != 'amend' }}
  79. run: |
  80. git add ${{ needs.init.outputs.git_path }}
  81. git commit --signoff -m 'chore(assets): Recompile assets'
  82. git push origin ${{ needs.init.outputs.head_ref }}
  83. - name: Commit and push fixup
  84. if: ${{ needs.init.outputs.arg1 == 'fixup' }}
  85. run: |
  86. git add ${{ needs.init.outputs.git_path }}
  87. git commit --fixup=HEAD --signoff
  88. git push origin ${{ needs.init.outputs.head_ref }}
  89. - name: Commit and push amend
  90. if: ${{ needs.init.outputs.arg1 == 'amend' }}
  91. run: |
  92. git add ${{ needs.init.outputs.git_path }}
  93. git commit --amend --no-edit --signoff
  94. git push --force origin ${{ needs.init.outputs.head_ref }}
  95. - name: Add reaction on failure
  96. uses: peter-evans/create-or-update-comment@ca08ebd5dc95aa0cd97021e9708fcd6b87138c9b # v3.0.1
  97. if: failure()
  98. with:
  99. token: ${{ secrets.COMMAND_BOT_PAT }}
  100. repository: ${{ github.event.repository.full_name }}
  101. comment-id: ${{ github.event.comment.id }}
  102. reactions: "-1"