[llvm] [GitHub][CI] Run clang-format natively in ci-ubuntu container (PR #161073)

Baranov Victor via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 28 04:09:45 PDT 2025


https://github.com/vbvictor created https://github.com/llvm/llvm-project/pull/161073

Tested in https://github.com/llvm/llvm-project/pull/160193 ([run logs](https://github.com/llvm/llvm-project/actions/runs/18073219195/job/51425979254?pr=160193)).
With this patch, we skip "Install clang-format" step which usually take 30sec (but can be up to 120sec) but add new step "Initialize containers" which add 17sec.

If we calculate total time, this patch code-format job will take ~1m50sec vs ~2min for code-format job in `main`.

But also this patch gives us a lot of opportunities for improvements, e.g.:

- Shrink docker image size by creating a dedicated clang-format container. Most of "Initialize containers" time is spent in pulling so smaller image means less time
- Create venv, install dependencies inside `docker build`, which would give ~6sec speed up.

>From 2470dc198fc33f02e4204ed256bdcc4c7b8f5d02 Mon Sep 17 00:00:00 2001
From: Victor Baranov <bar.victor.2002 at gmail.com>
Date: Sun, 28 Sep 2025 14:09:18 +0300
Subject: [PATCH] [GitHub][CI] Run clang-format natively in ci-ubuntu container

---
 .github/workflows/pr-code-format.yml | 25 ++++++++-----------------
 1 file changed, 8 insertions(+), 17 deletions(-)

diff --git a/.github/workflows/pr-code-format.yml b/.github/workflows/pr-code-format.yml
index 61c8680cd72a1..841b601ed3f4f 100644
--- a/.github/workflows/pr-code-format.yml
+++ b/.github/workflows/pr-code-format.yml
@@ -12,6 +12,8 @@ on:
 jobs:
   code_formatter:
     runs-on: ubuntu-24.04
+    container:
+      image: 'ghcr.io/llvm/ci-ubuntu-24.04:latest'
     timeout-minutes: 30
     concurrency:
       group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
@@ -38,24 +40,13 @@ jobs:
         run: |
           echo "Formatting files:"
           echo "$CHANGED_FILES"
-
-      # The clang format version should always be upgraded to the first version
-      # of a release cycle (x.1.0) or the last version of a release cycle, or
-      # if there have been relevant clang-format backports.
-      - name: Install clang-format
-        uses: aminya/setup-cpp at 17c11551771948abc5752bbf3183482567c7caf0 # v1.1.1
-        with:
-          clangformat: 21.1.0
-
-      - name: Setup Python env
-        uses: actions/setup-python at 42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
-        with:
-          python-version: '3.11'
-          cache: 'pip'
-          cache-dependency-path: 'llvm/utils/git/requirements_formatting.txt'
+      
+      - name: Create python venv
+        run: |
+          python -m venv venv
 
       - name: Install python dependencies
-        run: pip install -r llvm/utils/git/requirements_formatting.txt
+        run: venv/bin/pip install -r llvm/utils/git/requirements_formatting.txt
 
       - name: Run code formatter
         env:
@@ -64,7 +55,7 @@ jobs:
         # Create an empty comments file so the pr-write job doesn't fail.
         run: |
           echo "[]" > comments &&
-          python ./llvm/utils/git/code-format-helper.py \
+          venv/bin/python ./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