Move clang-format to Github Actions
Refactor clang-format, add Github Action Remove clang-format step from travismaster
parent
c2f3305730
commit
b7cfc56b59
|
@ -0,0 +1,40 @@
|
||||||
|
# Check all pull requests against the clang-format rules.
|
||||||
|
|
||||||
|
name: Clang Format
|
||||||
|
|
||||||
|
# Controls when the action will run.
|
||||||
|
# Run clang-format checks on all pull-requests
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- 'src/**.cpp'
|
||||||
|
- 'src/**.h'
|
||||||
|
|
||||||
|
paths-ignore:
|
||||||
|
- 'contrib/'
|
||||||
|
|
||||||
|
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
|
||||||
|
jobs:
|
||||||
|
clang-format-check:
|
||||||
|
timeout-minutes: 5
|
||||||
|
|
||||||
|
# Ubuntu 18.04 at the time of writing includes clang-format-9 as default
|
||||||
|
runs-on: [ubuntu-18.04]
|
||||||
|
|
||||||
|
# We want to check all changed files between the pull-request base and the head of the pull request
|
||||||
|
env:
|
||||||
|
FORMAT_BASE: ${{ github.base_ref }}
|
||||||
|
|
||||||
|
# Steps represent a sequence of tasks that will be executed as part of the job
|
||||||
|
steps:
|
||||||
|
|
||||||
|
# Checkout the repository as $GITHUB_WORKSPACE
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
# Make sure to include the base we want to merge into
|
||||||
|
- run: |
|
||||||
|
git fetch --no-tags --depth=1 origin ${{ github.base_ref }}
|
||||||
|
|
||||||
|
# Run the clang-format command (in $GITHUB_WORKSPACE, which is where the repo is checked out to)
|
||||||
|
- name: Run clang-format
|
||||||
|
run: ./scripts/clang-format
|
30
.travis.yml
30
.travis.yml
|
@ -31,22 +31,6 @@ addons:
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
# OSX is faster to boot and execute the checks, but has more contention for VM instances.
|
|
||||||
# Not waiting fifteen minutes for an instance to come available is faster.
|
|
||||||
- name: Static Checks
|
|
||||||
os: linux
|
|
||||||
env: STATIC_CHECKS=yes
|
|
||||||
deploy:
|
|
||||||
provider: null
|
|
||||||
before_install: skip
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
sources:
|
|
||||||
- ubuntu-toolchain-r-test
|
|
||||||
packages:
|
|
||||||
- clang-format
|
|
||||||
script: bash ./scripts/clang-format.sh
|
|
||||||
|
|
||||||
- name: Build GCC
|
- name: Build GCC
|
||||||
os: linux
|
os: linux
|
||||||
|
|
||||||
|
@ -74,17 +58,3 @@ deploy:
|
||||||
on:
|
on:
|
||||||
repo: pioneerspacesim/pioneer
|
repo: pioneerspacesim/pioneer
|
||||||
tags: true
|
tags: true
|
||||||
condition: $STATIC_CHECKS != yes
|
|
||||||
|
|
||||||
notifications:
|
|
||||||
irc:
|
|
||||||
channels:
|
|
||||||
- "ircs://chat.freenode.net:6669/#pioneer"
|
|
||||||
on_success: always
|
|
||||||
on_failure: always
|
|
||||||
template:
|
|
||||||
- "%{repository_slug}#%{build_number} (%{branch} - %{commit} : %{author}): %{message}"
|
|
||||||
- "Change view : %{compare_url}"
|
|
||||||
- "Build details : %{build_url}"
|
|
||||||
nick: travis-jameson
|
|
||||||
password: flyordie
|
|
||||||
|
|
12
autoformat
12
autoformat
|
@ -1,20 +1,22 @@
|
||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
|
./scripts/clang-format.sh "$@"
|
||||||
|
|
||||||
./scripts/clang-format.sh
|
|
||||||
# Run clang-format, storing the output in MSG
|
# Run clang-format, storing the output in MSG
|
||||||
# Git runs hooks in the base directory, so we don't need to do any fancy dirname stuff.
|
# Git runs hooks in the base directory, so we don't need to do any fancy dirname stuff.
|
||||||
# $? will be non-zero if clang-format detected formatting issues.
|
# $? will be non-zero if clang-format detected formatting issues.
|
||||||
if [ "$?" != 0 ]; then
|
format_ok=$?
|
||||||
|
if ((format_ok == 1)); then
|
||||||
# We've had a major malfunction!
|
# We've had a major malfunction!
|
||||||
read -p "Do you want to automatically apply these changes (y/N)?" apply
|
read -p "Do you want to automatically apply these changes (y/N)?" apply
|
||||||
case $apply in
|
case $apply in
|
||||||
y|Y)
|
y|Y)
|
||||||
# Get the patch info from the message and apply it to the staged changes.
|
# Get the patch info from the message and apply it to the staged changes.
|
||||||
PATCH_MODE=1 ./scripts/clang-format.sh | git apply --index -
|
PATCH_MODE=1 ./scripts/clang-format.sh "$@" | git apply --index -
|
||||||
;;
|
;;
|
||||||
*) exit 1;;
|
*) exit 1;;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
# All good, carry on.
|
# All good, carry on.
|
||||||
exit 0
|
exit $format_ok
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -1,32 +1,43 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
CLANG_FORMAT=`which "clang-format"`
|
CLANG_FORMAT=$(which clang-format)
|
||||||
if [ ! $PATCH_MODE ]; then
|
|
||||||
|
# Github Actions compatibility
|
||||||
|
if [[ $GITHUB_WORKSPACE ]]; then cd $GIT_WORKSPACE; fi
|
||||||
|
|
||||||
|
# if PATCH_MODE is set to 0, then set it to the empty string so $PATCH_MODE continues to work
|
||||||
|
if ((PATCH_MODE == 0)); then PATCH_MODE=""; fi
|
||||||
|
|
||||||
|
if [[ $PATCH_MODE ]]; then
|
||||||
echo "clang-format = $CLANG_FORMAT"
|
echo "clang-format = $CLANG_FORMAT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
|
if [[ $TRAVIS_PULL_REQUEST && $TRAVIS_PULL_REQUEST != "false" ]]; then
|
||||||
# Check the whole commit range against $TRAVIS_BRANCH, the base merge branch
|
# Check the whole commit range against $TRAVIS_BRANCH, the base merge branch
|
||||||
# We could use $TRAVIS_COMMIT_RANGE but it doesn't play well with force pushes
|
# We could use $TRAVIS_COMMIT_RANGE but it doesn't play well with force pushes
|
||||||
RANGE="$(git rev-parse $TRAVIS_BRANCH) HEAD"
|
RANGE_BASE=$(git rev-parse $TRAVIS_BRANCH)
|
||||||
else
|
elif [[ $FORMAT_BASE ]]; then
|
||||||
# Test only the last commit
|
# Test all commits between the $FORMAT_BASE commit and HEAD
|
||||||
RANGE=HEAD
|
RANGE_BASE=$(git rev-parse $FORMAT_BASE)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$TRAVIS" ]; then
|
if [[ $RANGE_BASE ]]; then
|
||||||
|
# if we're comparing against a certain commit, diff the tree
|
||||||
GIT_DIFF_TOOL="git diff-tree"
|
GIT_DIFF_TOOL="git diff-tree"
|
||||||
else
|
else
|
||||||
|
# otherwise, only diff the HEAD against the index
|
||||||
GIT_DIFF_TOOL="git diff-index --cached"
|
GIT_DIFF_TOOL="git diff-index --cached"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
FILES="$@"
|
|
||||||
# Allow manually specifiying the files.
|
# Allow manually specifiying the files.
|
||||||
if [ -z "$FILES" ]; then
|
FILES="$@"
|
||||||
FILES=$($GIT_DIFF_TOOL --no-commit-id --name-only --diff-filter=d -r $RANGE | grep -v contrib/ | grep -E "\.(c|h|cpp|hpp|cc|hh|cxx|m|mm|inc)$")
|
|
||||||
|
# Otherwise, get a list of all files changed between our RANGE_BASE and the current HEAD
|
||||||
|
if [[ -z $FILES ]]; then
|
||||||
|
FILES=$($GIT_DIFF_TOOL --no-commit-id --name-only --diff-filter=d $RANGE_BASE HEAD | grep -v contrib/ | grep -E "\.(c|h|cpp|hpp|cc|hh|cxx|m|mm|inc)$")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! $PATCH_MODE ]; then
|
if [[ -z $PATCH_MODE ]]; then
|
||||||
echo -e "Checking files:"
|
echo -e "Checking files:"
|
||||||
for file in $FILES; do
|
for file in $FILES; do
|
||||||
echo -e "\t$file"
|
echo -e "\t$file"
|
||||||
|
@ -37,7 +48,7 @@ prefix="static-check-clang-format"
|
||||||
suffix="$(date +%s)"
|
suffix="$(date +%s)"
|
||||||
patch="/tmp/$prefix-$suffix.patch"
|
patch="/tmp/$prefix-$suffix.patch"
|
||||||
|
|
||||||
if [ -z "$TRAVIS" ] && [ ! $PATCH_MODE ]; then
|
if [[ -z $PATCH_MODE ]]; then
|
||||||
DIFF_COLOR="--color=always"
|
DIFF_COLOR="--color=always"
|
||||||
else
|
else
|
||||||
DIFF_COLOR=""
|
DIFF_COLOR=""
|
||||||
|
@ -53,14 +64,14 @@ for file in $FILES; do
|
||||||
done
|
done
|
||||||
|
|
||||||
# if no patch has been generated all is ok, clean up the file stub and exit
|
# if no patch has been generated all is ok, clean up the file stub and exit
|
||||||
if [ ! -s "$patch" ] ; then
|
if [[ ! -s $patch ]] ; then
|
||||||
printf "Files in this commit comply with the clang-format rules.\n"
|
printf "Files in this commit comply with the clang-format rules.\n"
|
||||||
rm -f "$patch"
|
rm -f "$patch"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $PATCH_MODE ]; then
|
if [[ $PATCH_MODE ]]; then
|
||||||
# Print the filename of the generated patch.
|
# Print the generated patch to stdout.
|
||||||
cat "$patch"
|
cat "$patch"
|
||||||
rm -f "$patch"
|
rm -f "$patch"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
Loading…
Reference in New Issue