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