[llvm] [workflows] Always pull code-format-helper.py from the main branch (PR #80495)

Tom Stellard via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 2 13:06:54 PST 2024


https://github.com/tstellar created https://github.com/llvm/llvm-project/pull/80495

After bc06cd5cbcfc22dd976f6742d10bc934e1353b8a we started pulling code-fromat-helper.py from the pull request branch, but if the pull request branch is not up-to-date, then the job will fail, because this workflow is incompatible with the old version of the script.

In order to fix this, we need to pull the script from the main branch like we were doing before to ensure that it always gets the latest version of the script.

>From f89641d2ab6b6a6db455ef5839dde87cf9487fff Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Fri, 2 Feb 2024 11:48:05 -0800
Subject: [PATCH] [workflows] Always pull code-format-helper.py from the main
 branch

After bc06cd5cbcfc22dd976f6742d10bc934e1353b8a we started pulling
code-fromat-helper.py from the pull request branch, but if the pull
request branch is not up-to-date, then the job will fail, because
this workflow is incompatible with the old version of the script.

In order to fix this, we need to pull the script from the main branch
like we were doing before to ensure that it always gets the latest
version of the script.
---
 .github/workflows/pr-code-format.yml | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/.github/workflows/pr-code-format.yml b/.github/workflows/pr-code-format.yml
index 1475d872498d4..3aa40a29852c9 100644
--- a/.github/workflows/pr-code-format.yml
+++ b/.github/workflows/pr-code-format.yml
@@ -25,6 +25,20 @@ jobs:
           separator: ","
           skip_initial_fetch: true
 
+      # We need to pull the script from the main branch, so that we ensure
+      # we get a version of the script that supports the --wirte-comment-to-file
+      # option.
+      - name: Fetch code formatting utils
+        uses: actions/checkout at v4
+        with:
+          reository: ${{ github.repository }}
+          ref: ${{ github.base_ref }}
+          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"
         env:
           CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
@@ -42,10 +56,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:
@@ -58,7 +72,7 @@ jobs:
         # explicitly in code-format-helper.py and not have to diff starting at
         # the merge base.
         run: |
-          python ./llvm/utils/git/code-format-helper.py \
+          python ./code-format-tools/llvm/utils/git/code-format-helper.py \
             --write-comment-to-file \
             --token ${{ secrets.GITHUB_TOKEN }} \
             --issue-number $GITHUB_PR_NUMBER \



More information about the llvm-commits mailing list