forked from amete/clang-format-action
-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint.sh
executable file
·41 lines (32 loc) · 1.09 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/sh -l
set -e
# Go to the main directory
cd $GITHUB_WORKSPACE
# Find the C/C++/CUDA source files
SRC=$(git ls-tree --full-tree -r HEAD | grep -e "\.\(c\|h\|hpp\|cpp\|cxx\|cu\|cuh\)\$" | cut -f 2)
# Run clang-format over all the matching files
echo "Using style $1"
clang-format -style=$1 -i $SRC
# Check to see if there is anything to be done
# If so commit and push. Otherwise do nothing
if ! git diff --quiet; then
# Configure the author
echo ">> Configuring the author"
git config --global user.email "clang-format@github-actions"
git config --global user.name "clang-format"
# Allow workspace to be trusted
git config --global --add safe.directory $GITHUB_WORKSPACE
# Commit the changes
echo ">> Committing the changes"
git commit -a -m "Apply clang-format" || true
# Push to the branch
BRANCH=${GITHUB_REF#*refs/heads/}
echo ">> Pushing to $BRANCH"
git push -u origin $BRANCH
# Set a message about what happened
MSG="Changes are applied, committed, and pushed!"
else
MSG="There are no changes, all good!"
fi
# Push the message
echo "::set-output name=message::$MSG"