Skip to content

Commit 173a223

Browse files
committed
Use Banana rather than ugly ruby program that do brroroborororr (drowning)
1 parent 23bdd25 commit 173a223

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ runc: test
4141
@gcovr --exclude */tests.c --exclude-unreachable-branches --sort-percentage --print-summary
4242

4343
norm:
44-
@ruby normono.rb
44+
@./csc.sh exercises .
4545

4646
.PHONY: all clean fclean re test run runc norm

csc.sh

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
3+
function my_readlink() {
4+
cd $1
5+
pwd
6+
cd - > /dev/null
7+
}
8+
9+
function cat_readme() {
10+
echo ""
11+
echo "Usage: $(basename $0) DELIVERY_DIR REPORTS_DIR"
12+
echo -e "\tDELIVERY_DIR\tShould be the directory where your project files are"
13+
echo -e "\tREPORTS_DIR\tShould be the directory where we output the reports"
14+
echo -e "\t\t\tTake note that existing reports will be overriden"
15+
echo ""
16+
}
17+
18+
if [ $# == 1 ] && [ $1 == "--help" ]; then
19+
cat_readme
20+
elif [ $# = 2 ];
21+
then
22+
DELIVERY_DIR=$(my_readlink "$1")
23+
REPORTS_DIR=$(my_readlink "$2")
24+
DOCKER_SOCKET_PATH=/var/run/docker.sock
25+
HAS_SOCKET_ACCESS=$(test -r $DOCKER_SOCKET_PATH; echo "$?")
26+
GHCR_REGISTRY_TOKEN=$(curl -s "https://ghcr.io/token?service=ghcr.io&scope=repository:epitech/coding-style-checker:pull" | grep -o '"token":"[^"]*' | grep -o '[^"]*$')
27+
GHCR_REPOSITORY_STATUS=$(curl -I -f -s -o /dev/null -H "Authorization: Bearer $GHCR_REGISTRY_TOKEN" "https://ghcr.io/v2/epitech/coding-style-checker/manifests/latest" && echo 0 || echo 1)
28+
BASE_EXEC_CMD="docker"
29+
EXPORT_FILE="$REPORTS_DIR"/coding-style-reports.log
30+
### delete existing report file
31+
rm -f "$EXPORT_FILE"
32+
33+
### Pull new version of docker image and clean olds
34+
35+
if [ $HAS_SOCKET_ACCESS -ne 0 ]; then
36+
echo "WARNING: Socket access is denied"
37+
echo "To fix this we will add the current user to docker group with : sudo usermod -a -G docker $USER"
38+
read -p "Do you want to proceed? (yes/no) " yn
39+
case $yn in
40+
yes | Y | y | Yes | YES) echo "ok, we will proceed";
41+
sudo usermod -a -G docker $USER;
42+
echo "You must reboot your computer for the changes to take effect";;
43+
no | N | n | No | NO) echo "ok, Skipping";;
44+
* ) echo "invalid response, Skipping";;
45+
esac
46+
BASE_EXEC_CMD="sudo ${BASE_EXEC_CMD}"
47+
fi
48+
49+
50+
if [ $GHCR_REPOSITORY_STATUS -eq 0 ]; then
51+
echo "Downloading new image and cleaning old one..."
52+
$BASE_EXEC_CMD pull ghcr.io/epitech/coding-style-checker:latest && $BASE_EXEC_CMD image prune -f
53+
echo "Download OK"
54+
else
55+
echo "WARNING: Skipping image download"
56+
fi
57+
58+
59+
### generate reports
60+
$BASE_EXEC_CMD run --rm --security-opt "label:disable" -i -v "$DELIVERY_DIR":"/mnt/delivery" -v "$REPORTS_DIR":"/mnt/reports" ghcr.io/epitech/coding-style-checker:latest "/mnt/delivery" "/mnt/reports"
61+
[[ -f "$EXPORT_FILE" ]] && echo "$(wc -l < "$EXPORT_FILE") coding style error(s) reported in "$EXPORT_FILE", $(grep -c ": MAJOR:" "$EXPORT_FILE") major, $(grep -c ": MINOR:" "$EXPORT_FILE") minor, $(grep -c ": INFO:" "$EXPORT_FILE") info"
62+
else
63+
cat_readme
64+
fi

0 commit comments

Comments
 (0)