command-compile.yml 5.2 KB

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