1
0

command-compile.yml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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@c6c9a1a66007646a28c153e2a8580a5bad27bcfa # v3.0.2
  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: Restore cached git repository
  47. uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2
  48. with:
  49. path: .git
  50. key: git-repo
  51. - name: Checkout ${{ needs.init.outputs.head_ref }}
  52. uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v3.6.0
  53. with:
  54. token: ${{ secrets.COMMAND_BOT_PAT }}
  55. fetch-depth: 0
  56. ref: ${{ needs.init.outputs.head_ref }}
  57. - name: Setup git
  58. run: |
  59. git config --local user.email "nextcloud-command@users.noreply.github.com"
  60. git config --local user.name "nextcloud-command"
  61. - name: Read package.json node and npm engines version
  62. uses: skjnldsv/read-package-engines-version-actions@8205673bab74a63eb9b8093402fd9e0e018663a1 # v2.2
  63. id: package-engines-versions
  64. with:
  65. fallbackNode: '^20'
  66. fallbackNpm: '^9'
  67. - name: Set up node ${{ steps.package-engines-versions.outputs.nodeVersion }}
  68. uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3
  69. with:
  70. node-version: ${{ steps.package-engines-versions.outputs.nodeVersion }}
  71. cache: npm
  72. - name: Set up npm ${{ steps.package-engines-versions.outputs.npmVersion }}
  73. run: npm i -g npm@"${{ steps.package-engines-versions.outputs.npmVersion }}"
  74. - name: Install dependencies & build
  75. env:
  76. CYPRESS_INSTALL_BINARY: 0
  77. run: |
  78. npm ci
  79. npm run build --if-present
  80. - name: Commit and push default
  81. if: ${{ needs.init.outputs.arg1 != 'fixup' && needs.init.outputs.arg1 != 'amend' }}
  82. run: |
  83. git add ${{ needs.init.outputs.git_path }}
  84. git commit --signoff -m 'chore(assets): Recompile assets'
  85. git push origin ${{ needs.init.outputs.head_ref }}
  86. - name: Commit and push fixup
  87. if: ${{ needs.init.outputs.arg1 == 'fixup' }}
  88. run: |
  89. git add ${{ needs.init.outputs.git_path }}
  90. git commit --fixup=HEAD --signoff
  91. git push origin ${{ needs.init.outputs.head_ref }}
  92. - name: Commit and push amend
  93. if: ${{ needs.init.outputs.arg1 == 'amend' }}
  94. run: |
  95. git add ${{ needs.init.outputs.git_path }}
  96. git commit --amend --no-edit --signoff
  97. git push --force origin ${{ needs.init.outputs.head_ref }}
  98. - name: Add reaction on failure
  99. uses: peter-evans/create-or-update-comment@c6c9a1a66007646a28c153e2a8580a5bad27bcfa # v3.0.2
  100. if: failure()
  101. with:
  102. token: ${{ secrets.COMMAND_BOT_PAT }}
  103. repository: ${{ github.event.repository.full_name }}
  104. comment-id: ${{ github.event.comment.id }}
  105. reactions: "-1"