|
| 1 | +# This workflow is provided via the organization template repository |
| 2 | +# |
| 3 | +# https://github.com/nextcloud/.github |
| 4 | +# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization |
| 5 | +# |
| 6 | +# SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors |
| 7 | +# SPDX-License-Identifier: MIT |
| 8 | + |
| 9 | +name: Compile Command |
| 10 | +on: |
| 11 | + issue_comment: |
| 12 | + types: [created] |
| 13 | + |
| 14 | +jobs: |
| 15 | + init: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + # On pull requests and if the comment starts with `/compile` |
| 19 | + if: github.event.issue.pull_request != '' && startsWith(github.event.comment.body, '/compile') |
| 20 | + |
| 21 | + outputs: |
| 22 | + git_path: ${{ steps.git-path.outputs.path }} |
| 23 | + arg1: ${{ steps.command.outputs.arg1 }} |
| 24 | + arg2: ${{ steps.command.outputs.arg2 }} |
| 25 | + head_ref: ${{ steps.comment-branch.outputs.head_ref }} |
| 26 | + base_ref: ${{ steps.comment-branch.outputs.base_ref }} |
| 27 | + |
| 28 | + steps: |
| 29 | + - name: Get repository from pull request comment |
| 30 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 31 | + id: get-repository |
| 32 | + with: |
| 33 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 34 | + script: | |
| 35 | + const pull = await github.rest.pulls.get({ |
| 36 | + owner: context.repo.owner, |
| 37 | + repo: context.repo.repo, |
| 38 | + pull_number: context.issue.number |
| 39 | + }); |
| 40 | +
|
| 41 | + const repositoryName = pull.data.head?.repo?.full_name |
| 42 | + console.log(repositoryName) |
| 43 | + return repositoryName |
| 44 | +
|
| 45 | + - name: Disabled on forks |
| 46 | + if: ${{ fromJSON(steps.get-repository.outputs.result) != github.repository }} |
| 47 | + run: | |
| 48 | + echo 'Can not execute /compile on forks' |
| 49 | + exit 1 |
| 50 | +
|
| 51 | + - name: Check actor permission |
| 52 | + uses: skjnldsv/check-actor-permission@69e92a3c4711150929bca9fcf34448c5bf5526e7 # v2 |
| 53 | + with: |
| 54 | + require: write |
| 55 | + |
| 56 | + - name: Add reaction on start |
| 57 | + uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0 |
| 58 | + with: |
| 59 | + token: ${{ secrets.COMMAND_BOT_PAT }} |
| 60 | + repository: ${{ github.event.repository.full_name }} |
| 61 | + comment-id: ${{ github.event.comment.id }} |
| 62 | + reactions: '+1' |
| 63 | + |
| 64 | + - name: Parse command |
| 65 | + uses: skjnldsv/parse-command-comment@5c955203c52424151e6d0e58fb9de8a9f6a605a1 # v2 |
| 66 | + id: command |
| 67 | + |
| 68 | + # Init path depending on which command is run |
| 69 | + - name: Init path |
| 70 | + id: git-path |
| 71 | + run: | |
| 72 | + if ${{ startsWith(steps.command.outputs.arg1, '/') }}; then |
| 73 | + echo "path=${{steps.command.outputs.arg1}}" >> $GITHUB_OUTPUT |
| 74 | + else |
| 75 | + echo "path=${{steps.command.outputs.arg2}}" >> $GITHUB_OUTPUT |
| 76 | + fi |
| 77 | +
|
| 78 | + - name: Init branch |
| 79 | + uses: xt0rted/pull-request-comment-branch@d97294d304604fa98a2600a6e2f916a84b596dc7 # v1 |
| 80 | + id: comment-branch |
| 81 | + |
| 82 | + - name: Add reaction on failure |
| 83 | + uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0 |
| 84 | + if: failure() |
| 85 | + with: |
| 86 | + token: ${{ secrets.COMMAND_BOT_PAT }} |
| 87 | + repository: ${{ github.event.repository.full_name }} |
| 88 | + comment-id: ${{ github.event.comment.id }} |
| 89 | + reactions: '-1' |
| 90 | + |
| 91 | + process: |
| 92 | + runs-on: ubuntu-latest |
| 93 | + needs: init |
| 94 | + |
| 95 | + steps: |
| 96 | + - name: Restore cached git repository |
| 97 | + uses: buildjet/cache/save@v4 |
| 98 | + with: |
| 99 | + path: .git |
| 100 | + key: git-repo |
| 101 | + |
| 102 | + - name: Checkout ${{ needs.init.outputs.head_ref }} |
| 103 | + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 |
| 104 | + with: |
| 105 | + token: ${{ secrets.COMMAND_BOT_PAT }} |
| 106 | + fetch-depth: 0 |
| 107 | + ref: ${{ needs.init.outputs.head_ref }} |
| 108 | + |
| 109 | + - name: Setup git |
| 110 | + run: | |
| 111 | + git config --local user.email '[email protected]' |
| 112 | + git config --local user.name 'nextcloud-command' |
| 113 | +
|
| 114 | + - name: Read package.json node and npm engines version |
| 115 | + uses: skjnldsv/read-package-engines-version-actions@06d6baf7d8f41934ab630e97d9e6c0bc9c9ac5e4 # v3 |
| 116 | + id: package-engines-versions |
| 117 | + with: |
| 118 | + fallbackNode: '^20' |
| 119 | + fallbackNpm: '^10' |
| 120 | + |
| 121 | + - name: Set up node ${{ steps.package-engines-versions.outputs.nodeVersion }} |
| 122 | + uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3 |
| 123 | + with: |
| 124 | + node-version: ${{ steps.package-engines-versions.outputs.nodeVersion }} |
| 125 | + cache: npm |
| 126 | + |
| 127 | + - name: Set up npm ${{ steps.package-engines-versions.outputs.npmVersion }} |
| 128 | + run: npm i -g 'npm@${{ steps.package-engines-versions.outputs.npmVersion }}' |
| 129 | + |
| 130 | + - name: Rebase to ${{ needs.init.outputs.base_ref }} |
| 131 | + if: ${{ contains(needs.init.outputs.arg1, 'rebase') }} |
| 132 | + run: | |
| 133 | + git fetch origin '${{ needs.init.outputs.base_ref }}:${{ needs.init.outputs.base_ref }}' |
| 134 | + git rebase 'origin/${{ needs.init.outputs.base_ref }}' |
| 135 | +
|
| 136 | + - name: Install dependencies & build |
| 137 | + env: |
| 138 | + CYPRESS_INSTALL_BINARY: 0 |
| 139 | + PUPPETEER_SKIP_DOWNLOAD: true |
| 140 | + run: | |
| 141 | + npm ci |
| 142 | + npm run build --if-present |
| 143 | +
|
| 144 | + - name: Commit default |
| 145 | + if: ${{ !contains(needs.init.outputs.arg1, 'fixup') && !contains(needs.init.outputs.arg1, 'amend') }} |
| 146 | + run: | |
| 147 | + git add '${{ github.workspace }}${{ needs.init.outputs.git_path }}' |
| 148 | + git commit --signoff -m 'chore(assets): Recompile assets' |
| 149 | +
|
| 150 | + - name: Commit fixup |
| 151 | + if: ${{ contains(needs.init.outputs.arg1, 'fixup') }} |
| 152 | + run: | |
| 153 | + git add '${{ github.workspace }}${{ needs.init.outputs.git_path }}' |
| 154 | + git commit --fixup=HEAD --signoff |
| 155 | +
|
| 156 | + - name: Commit amend |
| 157 | + if: ${{ contains(needs.init.outputs.arg1, 'amend') }} |
| 158 | + run: | |
| 159 | + git add '${{ github.workspace }}${{ needs.init.outputs.git_path }}' |
| 160 | + git commit --amend --no-edit --signoff |
| 161 | + # Remove any [skip ci] from the amended commit |
| 162 | + git commit --amend -m "$(git log -1 --format='%B' | sed '/\[skip ci\]/d')" |
| 163 | +
|
| 164 | + - name: Push normally |
| 165 | + if: ${{ !contains(needs.init.outputs.arg1, 'rebase') && !contains(needs.init.outputs.arg1, 'amend') }} |
| 166 | + run: git push origin '${{ needs.init.outputs.head_ref }}' |
| 167 | + |
| 168 | + - name: Force push |
| 169 | + if: ${{ contains(needs.init.outputs.arg1, 'rebase') || contains(needs.init.outputs.arg1, 'amend') }} |
| 170 | + run: git push --force origin '${{ needs.init.outputs.head_ref }}' |
| 171 | + |
| 172 | + - name: Add reaction on failure |
| 173 | + uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0 |
| 174 | + if: failure() |
| 175 | + with: |
| 176 | + token: ${{ secrets.COMMAND_BOT_PAT }} |
| 177 | + repository: ${{ github.event.repository.full_name }} |
| 178 | + comment-id: ${{ github.event.comment.id }} |
| 179 | + reactions: '-1' |
| 180 | + |
0 commit comments