1
0

command-compile.yml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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@23ff15729ef2fc348714a3bb66d2f655ca9066f2 # v3.1.0
  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@b4ffde65f46336ab88eb53be808477a3936bae11 # 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@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0
  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. PUPPETEER_SKIP_DOWNLOAD: true
  78. run: |
  79. npm ci
  80. npm run build --if-present
  81. - name: Commit and push default
  82. if: ${{ needs.init.outputs.arg1 != 'fixup' && needs.init.outputs.arg1 != 'amend' }}
  83. run: |
  84. git add ${{ needs.init.outputs.git_path }}
  85. git commit --signoff -m 'chore(assets): Recompile assets'
  86. git push origin ${{ needs.init.outputs.head_ref }}
  87. - name: Commit and push fixup
  88. if: ${{ needs.init.outputs.arg1 == 'fixup' }}
  89. run: |
  90. git add ${{ needs.init.outputs.git_path }}
  91. git commit --fixup=HEAD --signoff
  92. git push origin ${{ needs.init.outputs.head_ref }}
  93. - name: Commit and push amend
  94. if: ${{ needs.init.outputs.arg1 == 'amend' }}
  95. run: |
  96. git add ${{ needs.init.outputs.git_path }}
  97. git commit --amend --no-edit --signoff
  98. git push --force origin ${{ needs.init.outputs.head_ref }}
  99. - name: Add reaction on failure
  100. uses: peter-evans/create-or-update-comment@23ff15729ef2fc348714a3bb66d2f655ca9066f2 # v3.1.0
  101. if: failure()
  102. with:
  103. token: ${{ secrets.COMMAND_BOT_PAT }}
  104. repository: ${{ github.event.repository.full_name }}
  105. comment-id: ${{ github.event.comment.id }}
  106. reactions: "-1"