|  | 
|  | 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@v2 | 
|  | 22 | +        with: | 
|  | 23 | +          require: write | 
|  | 24 | + | 
|  | 25 | +      - name: Add reaction on start | 
|  | 26 | +        uses: peter-evans/create-or-update-comment@v1 | 
|  | 27 | +        with: | 
|  | 28 | +          token: ${{ secrets.COMMAND_BOT_PAT }} | 
|  | 29 | +          repository: ${{ github.event.repository.full_name }} | 
|  | 30 | +          comment-id: ${{ github.event.comment.id }} | 
|  | 31 | +          reaction-type: "+1" | 
|  | 32 | + | 
|  | 33 | +      - name: Parse command | 
|  | 34 | +        uses: skjnldsv/parse-command-comment@master | 
|  | 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 "::set-output name=path::${{ github.workspace }}${{steps.command.outputs.arg1}}" | 
|  | 43 | +          else | 
|  | 44 | +            echo "::set-output name=path::${{ github.workspace }}${{steps.command.outputs.arg2}}" | 
|  | 45 | +          fi | 
|  | 46 | +
 | 
|  | 47 | +      - name: Init branch | 
|  | 48 | +        uses: xt0rted/pull-request-comment-branch@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@v2 | 
|  | 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@v1 | 
|  | 70 | +        id: package-engines-versions | 
|  | 71 | +        with: | 
|  | 72 | +          fallbackNode: '^12' | 
|  | 73 | +          fallbackNpm: '^6' | 
|  | 74 | + | 
|  | 75 | +      - name: Set up node ${{ steps.package-engines-versions.outputs.nodeVersion }} | 
|  | 76 | +        uses: actions/setup-node@v2 | 
|  | 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 'Compile 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@v1 | 
|  | 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 | +          reaction-type: "-1" | 
0 commit comments