[llvm] [Github] Fetch through merge base in code formatting action (PR #72020)
Aiden Grossman via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 11 00:46:07 PST 2023
https://github.com/boomanaiden154 created https://github.com/llvm/llvm-project/pull/72020
This commit adds another step to the Github workflow that runs the code formatting check to fetch through the merge base. This ensures that the necessary history is present to find the changed files and also to run clang-format over. This change massively increases the speed of the action (~10 minutes down to ~2 minutes in most cases from my testing) and also increases the reliability significantly.
>From d8a4632b4d206092d0e8ca2ceabf3bf654ff2719 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <agrossman154 at yahoo.com>
Date: Fri, 10 Nov 2023 23:45:55 -0800
Subject: [PATCH] [Github] Fetch through merge base in code formatting action
This commit adds another step to the Github workflow that runs the code
formatting check to fetch through the merge base. This ensures that the
necessary history is present to find the changed files and also to run
clang-format over. This change massively increases the speed of the
action (~10 minutes down to ~2 minutes in most cases from my testing)
and also increases the reliability significantly.
---
.github/workflows/pr-code-format.yml | 29 +++++++++++++++++++++++-----
1 file changed, 24 insertions(+), 5 deletions(-)
diff --git a/.github/workflows/pr-code-format.yml b/.github/workflows/pr-code-format.yml
index 4fa5c42bca22b02..b7673009aa4f6a9 100644
--- a/.github/workflows/pr-code-format.yml
+++ b/.github/workflows/pr-code-format.yml
@@ -11,14 +11,33 @@ jobs:
- name: Fetch LLVM sources
uses: actions/checkout at v4
with:
- fetch-depth: 2 # Fetches only the last 2 commits
+ ref: ${{ github.event.pull_request.head.ref }}
+
+ - name: Checkout through merge base
+ uses: rmacklin/fetch-through-merge-base at v0
+ with:
+ base_ref: ${{ github.event.pull_request.base.ref }}
+ head_ref: ${{ github.event.pull_request.head.ref }}
+ deepen_length: 500
- 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
+ skip_initial_fetch: true
+
+ # 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 code formatting utils
+ 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: code-format-tools
- name: "Listed files"
run: |
@@ -35,10 +54,10 @@ jobs:
with:
python-version: '3.11'
cache: 'pip'
- cache-dependency-path: 'llvm/utils/git/requirements_formatting.txt'
+ cache-dependency-path: 'code-format-tools/llvm/utils/git/requirements_formatting.txt'
- name: Install python dependencies
- run: pip install -r llvm/utils/git/requirements_formatting.txt
+ run: pip install -r code-format-tools/llvm/utils/git/requirements_formatting.txt
- name: Run code formatter
env:
@@ -47,7 +66,7 @@ jobs:
END_REV: ${{ github.event.pull_request.head.sha }}
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
- python llvm/utils/git/code-format-helper.py \
+ python ./code-format-tools/llvm/utils/git/code-format-helper.py \
--token ${{ secrets.GITHUB_TOKEN }} \
--issue-number $GITHUB_PR_NUMBER \
--start-rev $START_REV \
More information about the llvm-commits
mailing list