Use LLVM apt repository for clang-format-18

This commit is contained in:
Mario Zechner 2025-07-16 04:27:38 +02:00
parent bd3b8186b9
commit a0a86af560

View File

@ -11,29 +11,15 @@ jobs:
- uses: actions/checkout@v3
- name: Setup clang-format Docker alias
- name: Install clang-format 18
run: |
# Create a wrapper script for clang-format that uses Docker
cat > /tmp/clang-format-wrapper << 'EOF'
#!/bin/bash
# Convert relative paths to absolute paths and run clang-format in Docker
args=()
for arg in "$@"; do
if [[ "$arg" == /* ]] || [[ "$arg" == -* ]]; then
# Absolute path or option, use as-is
args+=("$arg")
elif [[ -e "$arg" ]]; then
# Relative path that exists, convert to absolute
args+=("$(realpath "$arg")")
else
# Not a file path, use as-is
args+=("$arg")
fi
done
docker run --rm -i -v "$PWD":"$PWD" -w "$PWD" silkeh/clang:18 clang-format "${args[@]}"
EOF
sudo mv /tmp/clang-format-wrapper /usr/local/bin/clang-format
sudo chmod +x /usr/local/bin/clang-format
# Install clang-format-18 from LLVM apt repository
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-18 main" | sudo tee /etc/apt/sources.list.d/llvm.list
sudo apt-get update
sudo apt-get install -y clang-format-18
# Create symlink
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-18 100
# Verify version
clang-format --version