Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Speed up execution #174

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
22 changes: 11 additions & 11 deletions check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
###############################################################################
# check.sh #
###############################################################################
# USAGE: ./entrypoint.sh [<path>] [<fallback style>]
# USAGE: ./check.sh [<path>] [<fallback style>]
#
# Checks all C/C++/Protobuf/CUDA files (.h, .H, .hpp, .hh, .h++, .hxx and .c,
# .C, .cpp, .cc, .c++, .cxx, .proto, .cu) in the provided GitHub repository path
Expand All @@ -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 Expand Up @@ -94,12 +88,18 @@ docker run \
ghcr.io/jidicula/clang-format:"$CLANG_FORMAT_MAJOR_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)
src_files=$(find \
"$CHECK_PATH" \
-name .git \
-prune \
-o \
-regextype posix-egrep \
-regex "$INCLUDE_REGEX" \
-print)

# check formatting in each source file
IFS=$'\n' # Loop below should separate on new lines, not spaces.
for file in $src_files; do
# Only check formatting if the path doesn't match the regex
if ! [[ ${file} =~ $EXCLUDE_REGEX ]]; then
format_diff "${file}"
fi
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"