Skip to content

Commit

Permalink
perf(docker): Call docker once rather than per-file
Browse files Browse the repository at this point in the history
  • Loading branch information
jidicula committed Mar 12, 2024
1 parent 9d757de commit e9f0d95
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ inputs:
required: false
default: 'llvm'
include-regex:
description: 'A regex to override the C/C++/Protobuf/CUDA filetype regex. that should be checked. Default results in the regex defined in `check.sh`.'
description: 'A regex to override the C/C++/Protobuf/CUDA filetype regex for files that should be checked. Default results in the regex defined in `check.sh`.'
required: false
default: ''

runs:
using: "composite"
steps:
- run: |
"${{ github.action_path }}/check.sh" "${{ inputs.clang-format-version }}" "${{ inputs.check-path }}" "${{ inputs.fallback-style }}" "${{ inputs.exclude-regex }}" "${{ inputs.include-regex }}"
"${{ github.action_path }}/wrapper.sh" "${{ inputs.clang-format-version }}" "${{ inputs.check-path }}" "${{ inputs.fallback-style }}" "${{ inputs.exclude-regex }}" "${{ inputs.include-regex }}"
shell: bash
- name: Save PR head commit SHA
if: failure() && github.event_name == 'pull_request'
Expand Down
10 changes: 2 additions & 8 deletions check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,14 @@ format_diff() {
local filepath="$1"
# Invoke clang-format with dry run and formatting error output
if [[ $CLANG_FORMAT_MAJOR_VERSION -gt "9" ]]; then
local_format="$(docker run \
--volume "$(pwd)":"$(pwd)" \
--workdir "$(pwd)" \
ghcr.io/jidicula/clang-format:"$CLANG_FORMAT_MAJOR_VERSION" \
local_format="$(clang-format \
--dry-run \
--Werror \
--style=file \
--fallback-style="$FALLBACK_STYLE" \
"${filepath}")"
else # Versions below 9 don't have dry run
formatted="$(docker run \
--volume "$(pwd)":"$(pwd)" \
--workdir "$(pwd)" \
ghcr.io/jidicula/clang-format:"$CLANG_FORMAT_MAJOR_VERSION" \
formatted="$(clang-format \
--style=file \
--fallback-style="$FALLBACK_STYLE" \
"${filepath}")"
Expand Down
10 changes: 5 additions & 5 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ CLANG_FORMAT_VERSION="$1"
###############################################################################

# should succeed
"$GITHUB_WORKSPACE"/check.sh "$CLANG_FORMAT_VERSION" "$GITHUB_WORKSPACE/test/known_pass" "$FALLBACK_STYLE" "$EXCLUDE_REGEX"
"$GITHUB_WORKSPACE"/wrapper.sh "$CLANG_FORMAT_VERSION" "$GITHUB_WORKSPACE/test/known_pass" "$FALLBACK_STYLE" "$EXCLUDE_REGEX"
docker_status="$?"
if [[ $docker_status != "0" ]]; then
echo "files that should succeed have failed!"
exit 1
fi

# should fail
"$GITHUB_WORKSPACE"/check.sh "$CLANG_FORMAT_VERSION" "$GITHUB_WORKSPACE/test/known_fail" "$FALLBACK_STYLE" "$EXCLUDE_REGEX"
"$GITHUB_WORKSPACE"/wrapper.sh "$CLANG_FORMAT_VERSION" "$GITHUB_WORKSPACE/test/known_fail" "$FALLBACK_STYLE" "$EXCLUDE_REGEX"
docker_status="$?"
if [[ $docker_status == "0" ]]; then
echo "files that should fail have succeeded!"
Expand All @@ -26,7 +26,7 @@ fi

# load test on known_pass/addition.c copies

"$GITHUB_WORKSPACE"/check.sh "$CLANG_FORMAT_VERSION" "$GITHUB_WORKSPACE/test/load_test" "$FALLBACK_STYLE" "$EXCLUDE_REGEX"
"$GITHUB_WORKSPACE"/wrapper.sh "$CLANG_FORMAT_VERSION" "$GITHUB_WORKSPACE/test/load_test" "$FALLBACK_STYLE" "$EXCLUDE_REGEX"
docker_status="$?"
if [[ $docker_status != "0" ]]; then
echo "files that should succeed have failed in the loadtest!"
Expand All @@ -40,15 +40,15 @@ fi
INCLUDE_REGEX='^.*\.(c|C)'

# should succeed
"$GITHUB_WORKSPACE"/check.sh "$CLANG_FORMAT_VERSION" "$GITHUB_WORKSPACE/test/known_pass" "$FALLBACK_STYLE" "$EXCLUDE_REGEX" "$INCLUDE_REGEX"
"$GITHUB_WORKSPACE"/wrapper.sh "$CLANG_FORMAT_VERSION" "$GITHUB_WORKSPACE/test/known_pass" "$FALLBACK_STYLE" "$EXCLUDE_REGEX" "$INCLUDE_REGEX"
docker_status="$?"
if [[ $docker_status != "0" ]]; then
echo "files that should succeed have failed!"
exit 1
fi

# should fail
"$GITHUB_WORKSPACE"/check.sh "$CLANG_FORMAT_VERSION" "$GITHUB_WORKSPACE/test/known_fail" "$FALLBACK_STYLE" "$EXCLUDE_REGEX" "$INCLUDE_REGEX"
"$GITHUB_WORKSPACE"/wrapper.sh "$CLANG_FORMAT_VERSION" "$GITHUB_WORKSPACE/test/known_fail" "$FALLBACK_STYLE" "$EXCLUDE_REGEX" "$INCLUDE_REGEX"
docker_status="$?"
if [[ $docker_status == "0" ]]; then
echo "files that should fail have succeeded!"
Expand Down
19 changes: 19 additions & 0 deletions wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

CLANG_FORMAT_MAJOR_VERSION="$1"
CHECK_PATH="$2"
FALLBACK_STYLE="$3"
EXCLUDE_REGEX="$4"
INCLUDE_REGEX="$5"

docker run \
--volume "$(pwd)":"$(pwd)" \
--workdir "$(pwd)" \
--interactive \
ghcr.io/jidicula/clang-format:"$CLANG_FORMAT_MAJOR_VERSION" \
"/check.sh \
$CLANG_FORMAT_MAJOR_VERSION \
$CHECK_PATH \
$FALLBACK_STYLE \
$EXCLUDE_REGEX \
$INCLUDE_REGEX"

0 comments on commit e9f0d95

Please sign in to comment.