forked from mozilla/rust-code-analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-submodules.sh
More file actions
executable file
·75 lines (61 loc) · 2.19 KB
/
Copy pathcheck-submodules.sh
File metadata and controls
executable file
·75 lines (61 loc) · 2.19 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# Checks out if a submodule has been updated
SUBMODULES=`git submodule--helper list | awk '{ print $4 }'`
RUN_CI="no"
for SUBMODULE in $SUBMODULES
do
git diff --exit-code HEAD^ $SUBMODULE
CHANGED=$? # Get git diff exit code
if [ $CHANGED -eq 1 ]
then
RUN_CI="yes"
SUBMODULE_NAME=$SUBMODULE
break
fi
done
# If no submodule has been updated, exit the script
if [ "$RUN_CI" = "no" ]; then
exit 0
fi
# Install json minimal tests
JMT_LINK="https://github.com/Luni-4/json-minimal-tests/releases/download"
JMT_VERSION="0.1.4"
curl -L "$JMT_LINK/v$JMT_VERSION/json-minimal-tests-linux.tar.gz" |
tar xz -C $CARGO_HOME/bin
# Download mozilla-central repository
MOZILLA_CENTRAL_REPO="https://github.com/mozilla/gecko-dev"
[ ! -d "/cache/gecko-dev" ] &&
git clone --quiet $MOZILLA_CENTRAL_REPO /cache/gecko-dev || true
pushd /cache/gecko-dev && git pull origin master && popd
# Compute metrics
./check-submodule.py compute-ci-metrics -p /cache/gecko-dev -l $SUBMODULE_NAME
# Compare metrics
./check-submodule.py compare-metrics -l $SUBMODULE_NAME
# Count files in metrics directories
ls /tmp/$SUBMODULE_NAME-old | wc -l
ls /tmp/$SUBMODULE_NAME-new | wc -l
# Create artifacts to be uploaded (if there are any)
COMPARE=/tmp/$SUBMODULE_NAME-compare
if [ "$(ls -A $COMPARE)" ]; then
# Maximum number of considered minimal tests for a metric
MT_THRESHOLD=30
# Array containing the considered metrics
# TODO: Implement a command into rust-code-analysis-cli that returns all
# computed metrics https://github.com/mozilla/rust-code-analysis/issues/478
METRICS=("cognitive" "sloc" "ploc" "lloc" "cloc" "blank" "cyclomatic" "halstead" "nom" "nexits" "nargs")
# Output directory name
OUTPUT_DIR=/tmp/output-$SUBMODULE_NAME
# Create output directory
mkdir -p $OUTPUT_DIR
# Retrieve minimal tests for a metric
for METRIC in "${METRICS[@]}"
do
FILES=`grep -r -i -l $METRIC $COMPARE | head -$MT_THRESHOLD`
if [ ${#FILES[@]} -ne 0 ]
then
mkdir -p $OUTPUT_DIR/$METRIC
cp $FILES $OUTPUT_DIR/$METRIC
fi
done
tar -czvf /tmp/json-diffs-and-minimal-tests.tar.gz $COMPARE $OUTPUT_DIR
fi