Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
- 19
- 20
- 21
- 21.1.6
steps:
- uses: actions/checkout@v6
- name: Build and test the Docker image
Expand Down Expand Up @@ -71,6 +72,7 @@ jobs:
- 19
- 20
- 21
- 21.1.6
path:
- check: 'test/known_fail'
exclude: 'capital'
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ branding:

inputs:
clang-format-version:
description: 'The major version of clang-format that you want to use.'
description: 'The version of clang-format that you want to use. Use either major version, or exact one.'
required: false
default: '21'
check-path:
Expand Down
9 changes: 5 additions & 4 deletions check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ format_diff() {
local_format="$(docker run \
--volume "$(pwd)":"$(pwd)" \
--workdir "$(pwd)" \
ghcr.io/jidicula/clang-format:"$CLANG_FORMAT_MAJOR_VERSION" \
ghcr.io/jidicula/clang-format:"$CLANG_FORMAT_VERSION" \
--dry-run \
--Werror \
--style=file \
Expand All @@ -34,7 +34,7 @@ format_diff() {
formatted="$(docker run \
--volume "$(pwd)":"$(pwd)" \
--workdir "$(pwd)" \
ghcr.io/jidicula/clang-format:"$CLANG_FORMAT_MAJOR_VERSION" \
ghcr.io/jidicula/clang-format:"$CLANG_FORMAT_VERSION" \
--style=file \
--fallback-style="$FALLBACK_STYLE" \
"${filepath}")"
Expand All @@ -55,7 +55,8 @@ format_diff() {
return 0
}

CLANG_FORMAT_MAJOR_VERSION="$1"
CLANG_FORMAT_VERSION="$1"
CLANG_FORMAT_MAJOR_VERSION="${CLANG_FORMAT_VERSION%%.*}"
CHECK_PATH="$2"
FALLBACK_STYLE="$3"
EXCLUDE_REGEX="$4"
Expand Down Expand Up @@ -91,7 +92,7 @@ exit_code=0
docker run \
--volume "$(pwd)":"$(pwd)" \
--workdir "$(pwd)" \
ghcr.io/jidicula/clang-format:"$CLANG_FORMAT_MAJOR_VERSION" --version
ghcr.io/jidicula/clang-format:"$CLANG_FORMAT_VERSION" --version

# All files improperly formatted will be printed to the output.
src_files=$(find "$CHECK_PATH" -name .git -prune -o -regextype posix-egrep -regex "$INCLUDE_REGEX" -print)
Expand Down
12 changes: 9 additions & 3 deletions clang-format-docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ ARG UBUNTU_VERSION
FROM ubuntu:${UBUNTU_VERSION}

ARG CLANG_FORMAT_VERSION
ENV PIP_ROOT_USER_ACTION=ignore
ENV PIP_BREAK_SYSTEM_PACKAGES=1

RUN apt-get update \
&& apt-get install --no-install-recommends -y \
clang-format-${CLANG_FORMAT_VERSION} \
&& apt-get install --no-install-recommends -y python3-pip \
&& pip install -v "$( \
echo "$CLANG_FORMAT_VERSION" | grep -qF '.' \
&& echo "clang-format==${CLANG_FORMAT_VERSION}" \
|| echo "clang-format==${CLANG_FORMAT_VERSION}.*" \
)" \
# Clean cache
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If serious about minimizing image, might want to purge python3-pip as well.

&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
&& apt-get clean -y && rm -rf /var/lib/apt/lists/* \
&& mv /usr/bin/clang-format-${CLANG_FORMAT_VERSION} /usr/bin/clang-format
&& mv /usr/local/bin/clang-format /usr/bin/clang-format

WORKDIR /

Expand Down
Loading