Skip to content

Commit 6acbbbf

Browse files
riversand963facebook-github-bot
authored andcommitted
Add Github Action for some basic sanity test of PR (facebook#6761)
Summary: Add Github Action to perform some basic sanity check for PR, inclding the following. 1) Buck TARGETS file. On the one hand, The TARGETS file is used for internal buck, and we do not manually update it. On the other hand, we need to run the buckifier scripts to update TARGETS whenever new files are added, etc. With this Github Action, we make sure that every PR does not forget this step. The GH Action uses a Makefile target called check-buck-targets. Users can manually run `make check-buck-targets` on local machine. 2) Code format We use clang-format-diff.py to format our code. The GH Action in this PR makes sure this step is not skipped. The checking script build_tools/format-diff.sh assumes that `clang-format-diff.py` is executable. On host running GH Action, it is difficult to download `clang-format-diff.py` and make it executable. Therefore, we modified build_tools/format-diff.sh to handle the case in which there is a non-executable clang-format-diff.py file in the top-level rocksdb repo directory. Test Plan (Github and devserver): Watch for Github Action result in the `Checks` tab. On dev server ``` make check-format make check-buck-targets make check ``` Pull Request resolved: facebook#6761 Test Plan: Watch for Github Action result in the `Checks` tab. Reviewed By: pdillinger Differential Revision: D21260209 Pulled By: riversand963 fbshipit-source-id: c646e2f37c6faf9f0614b68aa0efc818cff96787
1 parent 6504ae0 commit 6acbbbf

File tree

4 files changed

+130
-12
lines changed

4 files changed

+130
-12
lines changed

.github/workflows/sanity_check.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Check buck targets and code format
2+
on: [push, pull_request]
3+
jobs:
4+
check:
5+
name: Check TARGETS file and code format
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Checkout feature branch
9+
uses: actions/checkout@v2
10+
with:
11+
fetch-depth: 0
12+
13+
- name: Fetch from upstream
14+
run: |
15+
git remote add upstream https://github.com/facebook/rocksdb.git && git fetch upstream
16+
17+
- name: Where am I
18+
run: |
19+
echo git status && git status
20+
echo "git remote -v" && git remote -v
21+
echo git branch && git branch
22+
23+
- name: Setup Python
24+
uses: actions/setup-python@v1
25+
26+
- name: Install Dependencies
27+
run: python -m pip install --upgrade pip
28+
29+
- name: Install argparse
30+
run: pip install argparse
31+
32+
- name: Download clang-format-diff.py
33+
uses: wei/wget@v1
34+
with:
35+
args: https://raw.githubusercontent.com/llvm-mirror/clang/master/tools/clang-format/clang-format-diff.py
36+
37+
- name: Check format
38+
run: make check-format
39+
40+
- name: Compare buckify output
41+
run: make check-buck-targets

Makefile

+8
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,8 @@ ifeq ($(filter -DROCKSDB_LITE,$(OPT)),)
976976
sh tools/rocksdb_dump_test.sh
977977
endif
978978
endif
979+
$(MAKE) check-format
980+
$(MAKE) check-buck-targets
979981

980982
# TODO add ldb_tests
981983
check_some: $(SUBSET)
@@ -1196,6 +1198,12 @@ tags0:
11961198
format:
11971199
build_tools/format-diff.sh
11981200

1201+
check-format:
1202+
build_tools/format-diff.sh -c
1203+
1204+
check-buck-targets:
1205+
buckifier/check_buck_targets.sh
1206+
11991207
package:
12001208
bash build_tools/make_package.sh $(SHARED_MAJOR).$(SHARED_MINOR)
12011209

buckifier/check_buck_targets.sh

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
# If clang_format_diff.py command is not specfied, we assume we are able to
4+
# access directly without any path.
5+
6+
TGT_DIFF=`git diff TARGETS | head -n 1`
7+
8+
if [ ! -z "$TGT_DIFF" ]
9+
then
10+
echo "TARGETS file has uncommitted changes. Skip this check."
11+
exit 0
12+
fi
13+
14+
echo Backup original TARGETS file.
15+
16+
cp TARGETS TARGETS.bkp
17+
18+
python buckifier/buckify_rocksdb.py
19+
20+
TGT_DIFF=`git diff TARGETS | head -n 1`
21+
22+
if [ -z "$TGT_DIFF" ]
23+
then
24+
mv TARGETS.bkp TARGETS
25+
exit 0
26+
else
27+
echo "Please run 'python buckifier/buckify_rocksdb.py' to update TARGETS file."
28+
echo "Do not manually update TARGETS file."
29+
mv TARGETS.bkp TARGETS
30+
exit 1
31+
fi

build_tools/format-diff.sh

+50-12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@
22
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
33
# If clang_format_diff.py command is not specfied, we assume we are able to
44
# access directly without any path.
5+
6+
print_usage () {
7+
echo "Usage:"
8+
echo "format-diff.sh [OPTIONS]"
9+
echo "-c: check only."
10+
echo "-h: print this message."
11+
}
12+
13+
while getopts ':ch' OPTION; do
14+
case "$OPTION" in
15+
c)
16+
CHECK_ONLY=1
17+
;;
18+
h)
19+
print_usage
20+
exit 1
21+
;;
22+
?)
23+
print_usage
24+
exit 1
25+
;;
26+
esac
27+
done
28+
529
if [ -z $CLANG_FORMAT_DIFF ]
630
then
731
CLANG_FORMAT_DIFF="clang-format-diff.py"
@@ -10,18 +34,28 @@ fi
1034
# Check clang-format-diff.py
1135
if ! which $CLANG_FORMAT_DIFF &> /dev/null
1236
then
13-
echo "You didn't have clang-format-diff.py and/or clang-format available in your computer!"
14-
echo "You can download clang-format-diff.py by running: "
15-
echo " curl --location http://goo.gl/iUW1u2 -o ${CLANG_FORMAT_DIFF}"
16-
echo "You can download clang-format by running:"
17-
echo " brew install clang-format"
18-
echo " Or"
19-
echo " apt install clang-format"
20-
echo " This might work too:"
21-
echo " yum install git-clang-format"
22-
echo "Then, move both files (i.e. ${CLANG_FORMAT_DIFF} and clang-format) to some directory within PATH=${PATH}"
23-
echo "and make sure ${CLANG_FORMAT_DIFF} is executable."
24-
exit 128
37+
if [ ! -f ./clang-format-diff.py ]
38+
then
39+
echo "You didn't have clang-format-diff.py and/or clang-format available in your computer!"
40+
echo "You can download clang-format-diff.py by running: "
41+
echo " curl --location http://goo.gl/iUW1u2 -o ${CLANG_FORMAT_DIFF}"
42+
echo "You can download clang-format by running:"
43+
echo " brew install clang-format"
44+
echo " Or"
45+
echo " apt install clang-format"
46+
echo " This might work too:"
47+
echo " yum install git-clang-format"
48+
echo "Then, move both files (i.e. ${CLANG_FORMAT_DIFF} and clang-format) to some directory within PATH=${PATH}"
49+
echo "and make sure ${CLANG_FORMAT_DIFF} is executable."
50+
exit 128
51+
else
52+
if [ -x ./clang-format-diff.py ]
53+
then
54+
PATH=$PATH:.
55+
else
56+
CLANG_FORMAT_DIFF="python ./clang-format-diff.py"
57+
fi
58+
fi
2559
fi
2660

2761
# Check argparse, a library that clang-format-diff.py requires.
@@ -87,6 +121,10 @@ if [ -z "$diffs" ]
87121
then
88122
echo "Nothing needs to be reformatted!"
89123
exit 0
124+
elif [ $CHECK_ONLY ]
125+
then
126+
echo "Your change has unformatted code. Please run make format!"
127+
exit 1
90128
fi
91129

92130
# Highlight the insertion/deletion from the clang-format-diff.py's output

0 commit comments

Comments
 (0)