Codebase list votca-xtp / upstream/1.6.4 .github / workflows / format.yml
upstream/1.6.4

Tree @upstream/1.6.4 (Download .tar.gz)

format.yml @upstream/1.6.4raw · history · blame

name: Format
on:
  issue_comment:
    types: [created]
jobs:
  edit:
    name: clang-format
    if: ${{ github.event.comment.body == '@votca-bot format' }}
    runs-on: ubuntu-latest
    container: ghcr.io/votca/buildenv/format:latest
    steps:
      - name: Check if message comes from PR
        uses: octokit/request-action@v2.x
        id: issue_info
        with:
          route: GET /repos/:repository/issues/:pull_number
          repository: ${{ github.repository }}
          pull_number: ${{ github.event.issue.number }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Get PR info
        if: ${{ fromJSON(steps.issue_info.outputs.data).pull_request }}
        uses: octokit/request-action@v2.x
        id: pr_info
        with:
          route: GET /repos/:repository/pulls/:pull_number
          repository: ${{ github.repository }}
          pull_number: ${{ github.event.issue.number }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Checkout head branch from PR
        if: ${{ fromJSON(steps.issue_info.outputs.data).pull_request }}
        uses: actions/checkout@master
        with:
          repository: ${{ fromJSON(steps.pr_info.outputs.data).head.repo.full_name }}
          ref: ${{ fromJSON(steps.pr_info.outputs.data).head.ref }}
          token: ${{ secrets.VOTCA_BOT_TOKEN }}
      - name: Run clang-format
        if: ${{ fromJSON(steps.issue_info.outputs.data).pull_request }}
        run: |
          curl -OL https://github.com/votca/votca/raw/master/.clang-format
          find . -type f -regex ".*\.\(c\|h\|cc\|cpp\|hpp\)" -print0 | xargs -0 clang-format -i -style=file
      - name: Commit and push
        if: ${{ fromJSON(steps.issue_info.outputs.data).pull_request }}
        run: |
          git config --global user.name "Votca Bot"
          git config --global user.email "github@votca.org"
          git add -u
          git commit -m "Format code using $(clang-format --version)" || true
          git push