diff --git a/.github/workflows/pr-code-format.yml b/.github/workflows/pr-code-format.yml index c021c14f4a49..3a91ffb0b1ad 100644 --- a/.github/workflows/pr-code-format.yml +++ b/.github/workflows/pr-code-format.yml @@ -7,37 +7,17 @@ jobs: code_formatter: runs-on: ubuntu-latest steps: - # Get changed files before checking out the repository to force the action - # to analyze the diff from the Github API rather than looking at the - # shallow clone and erroring out, which is significantly more prone to - # failure. + - name: Fetch LLVM sources + uses: actions/checkout@v4 + with: + fetch-depth: 2 + - name: Get changed files id: changed-files uses: tj-actions/changed-files@v39 with: separator: "," - - - name: Calculate number of commits to fetch - run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}" - - - name: Fetch PR sources - uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.head.ref }} - fetch-depth: ${{ env.PR_FETCH_DEPTH }} - path: pr-sources - - # We need to make sure that we aren't executing/using any code from the - # PR for security reasons as we're using pull_request_target. Checkout - # the target branch with the necessary files. - - name: Fetch LLVM Sources - uses: actions/checkout@v4 - with: - sparse-checkout: | - llvm/utils/git/requirements_formatting.txt - llvm/utils/git/code-format-helper.py - sparse-checkout-cone-mode: false - path: llvm-sources + fetch_depth: 100 # Fetches only the last 10 commits - name: "Listed files" run: | @@ -54,21 +34,21 @@ jobs: with: python-version: '3.11' cache: 'pip' - cache-dependency-path: 'llvm-sources/llvm/utils/git/requirements_formatting.txt' + cache-dependency-path: 'llvm/utils/git/requirements_formatting.txt' - name: Install python dependencies - run: pip install -r llvm-sources/llvm/utils/git/requirements_formatting.txt + run: pip install -r llvm/utils/git/requirements_formatting.txt - name: Run code formatter env: GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }} - PR_DEPTH: ${{ github.event.pull_request.commits }} + START_REV: ${{ github.event.pull_request.base.sha }} + END_REV: ${{ github.event.pull_request.head.sha }} CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} - working-directory: ./pr-sources run: | - python ../llvm-sources/llvm/utils/git/code-format-helper.py \ + python llvm/utils/git/code-format-helper.py \ --token ${{ secrets.GITHUB_TOKEN }} \ --issue-number $GITHUB_PR_NUMBER \ - --start-rev HEAD~$PR_DEPTH \ - --end-rev HEAD \ + --start-rev $START_REV \ + --end-rev $END_REV \ --changed-files "$CHANGED_FILES"