[llvm] Reland pr code format updates (PR #71131)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 2 18:52:25 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-github-workflow
Author: Aiden Grossman (boomanaiden154)
<details>
<summary>Changes</summary>
This PR relands https://github.com/llvm/llvm-project/pull/69766 after it caused failures due to being unable to fetch branches from forks. I was using the wrong ref, so it tried to pull the same branch name from `llvm/llvm-project` rather than trying to pull the branch from the fork that the PR was created from. This is also why it didn't show up in my testing on my fork as I was only testing PRs on branches from within the same repository.
---
Full diff: https://github.com/llvm/llvm-project/pull/71131.diff
1 Files Affected:
- (modified) .github/workflows/pr-code-format.yml (+40-13)
``````````diff
diff --git a/.github/workflows/pr-code-format.yml b/.github/workflows/pr-code-format.yml
index fa0e69211b14788..555081471a7ef7b 100644
--- a/.github/workflows/pr-code-format.yml
+++ b/.github/workflows/pr-code-format.yml
@@ -7,17 +7,44 @@ jobs:
code_formatter:
runs-on: ubuntu-latest
steps:
- - name: Fetch LLVM sources
- uses: actions/checkout at v4
- with:
- fetch-depth: 2 # Fetches only the last 2 commits
-
+ # 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: Get changed files
id: changed-files
uses: tj-actions/changed-files at v39
with:
separator: ","
- fetch_depth: 2000 # Fetches only the last 2000 commits
+
+ - 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 at v4
+ with:
+ ref: ${{ github.event.pull_request.head.sha }}
+ fetch-depth: ${{ env.PR_FETCH_DEPTH }}
+ path: pr-sources
+
+ - name: Print commits being evaluated
+ working-directory: ./pr-sources
+ env:
+ PR_DEPTH: ${{ github.event.pull_request.commits }}
+ run: |
+ git log HEAD~$PR_DEPTH...HEAD
+
+ # 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 at 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
- name: "Listed files"
run: |
@@ -34,21 +61,21 @@ jobs:
with:
python-version: '3.11'
cache: 'pip'
- cache-dependency-path: 'llvm/utils/git/requirements_formatting.txt'
+ cache-dependency-path: 'llvm-sources/llvm/utils/git/requirements_formatting.txt'
- name: Install python dependencies
- run: pip install -r llvm/utils/git/requirements_formatting.txt
+ run: pip install -r llvm-sources/llvm/utils/git/requirements_formatting.txt
- name: Run code formatter
env:
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
- START_REV: ${{ github.event.pull_request.base.sha }}
- END_REV: ${{ github.event.pull_request.head.sha }}
+ PR_DEPTH: ${{ github.event.pull_request.commits }}
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
+ working-directory: ./pr-sources
run: |
- python llvm/utils/git/code-format-helper.py \
+ python ../llvm-sources/llvm/utils/git/code-format-helper.py \
--token ${{ secrets.GITHUB_TOKEN }} \
--issue-number $GITHUB_PR_NUMBER \
- --start-rev $START_REV \
- --end-rev $END_REV \
+ --start-rev HEAD~$PR_DEPTH \
+ --end-rev HEAD \
--changed-files "$CHANGED_FILES"
``````````
</details>
https://github.com/llvm/llvm-project/pull/71131
More information about the llvm-commits
mailing list