From 2737a16b8fc35ee136a230c3dd62b3cca46097c2 Mon Sep 17 00:00:00 2001 From: Noge <146479712+nogebeat@users.noreply.github.com> Date: Thu, 27 Feb 2025 11:19:07 +0100 Subject: [PATCH 01/10] Update coding-style.sh --- coding-style.sh | 130 +++++++++++++++++++++++++++++------------------- 1 file changed, 80 insertions(+), 50 deletions(-) diff --git a/coding-style.sh b/coding-style.sh index 0aaf183..f9da472 100755 --- a/coding-style.sh +++ b/coding-style.sh @@ -1,71 +1,101 @@ #!/bin/bash function my_readlink() { - cd $1 + cd "$1" pwd cd - > /dev/null } function cat_readme() { echo "" - echo "Usage: $(basename $0) DELIVERY_DIR REPORTS_DIR" + echo "Usage: $(basename "$0") DELIVERY_DIR REPORTS_DIR [HASKELL_FILE]" echo -e "\tDELIVERY_DIR\tShould be the directory where your project files are" echo -e "\tREPORTS_DIR\tShould be the directory where we output the reports" - echo -e "\t\t\tTake note that existing reports will be overriden" + echo -e "\tHASKELL_FILE\t(Optional) If a Haskell file is provided, it will be checked with lambdananas" + echo -e "\t\t\tTake note that existing reports will be overridden" echo "" } -if [ $# == 1 ] && [ $1 == "--help" ]; then - cat_readme -elif [ $# == 1 ] || [ $# = 2 ]; -then - if [ $# == 1 ]; - then - REPORTS_DIR=$(my_readlink ".") - elif [ $# = 2 ]; - then - REPORTS_DIR=$(my_readlink "$2") - fi +IMAGE_HASKELL="ghcr.io/nogebeat/lambdananas:latest" +LOCAL_BINARY="/usr/local/bin/lambdananas" - DELIVERY_DIR=$(my_readlink "$1") - DOCKER_SOCKET_PATH=/var/run/docker.sock - HAS_SOCKET_ACCESS=$(test -r $DOCKER_SOCKET_PATH; echo "$?") - GHCR_REGISTRY_TOKEN=$(curl -s "https://ghcr.io/token?service=ghcr.io&scope=repository:epitech/coding-style-checker:pull" | grep -o '"token":"[^"]*' | grep -o '[^"]*$') - 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) - BASE_EXEC_CMD="docker" - EXPORT_FILE="$REPORTS_DIR"/coding-style-reports.log - ### delete existing report file - rm -f "$EXPORT_FILE" - - ### Pull new version of docker image and clean olds - - if [ $HAS_SOCKET_ACCESS -ne 0 ]; then - echo "WARNING: Socket access is denied" - echo "To fix this we will add the current user to docker group with : sudo usermod -a -G docker $USER" - read -p "Do you want to proceed? (yes/no) " yn - case $yn in - yes | Y | y | Yes | YES) echo "ok, we will proceed"; - sudo usermod -a -G docker $USER; - echo "You must reboot your computer for the changes to take effect";; - no | N | n | No | NO) echo "ok, Skipping";; - * ) echo "invalid response, Skipping";; - esac - BASE_EXEC_CMD="sudo ${BASE_EXEC_CMD}" - fi +if ! command -v lambdananas &> /dev/null; then + echo "lambdananas not found. Installing via Docker..." + docker run --rm --entrypoint cat "$IMAGE_HASKELL" /usr/local/bin/lambdananas > lambdananas + chmod +x lambdananas + sudo mv lambdananas "$LOCAL_BINARY" - if [ $GHCR_REPOSITORY_STATUS -eq 0 ]; then - echo "Downloading new image and cleaning old one..." - $BASE_EXEC_CMD pull ghcr.io/epitech/coding-style-checker:latest && $BASE_EXEC_CMD image prune -f - echo "Download OK" - else - echo "WARNING: Skipping image download" + if ! command -v lambdananas &> /dev/null; then + echo "Installation failed." + exit 1 fi - +fi - ### generate reports - $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" - [[ -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" -else + +if [ "$#" -eq 1 ] && [[ "$1" == *.hs ]]; then + echo "Detected Haskell file. Running lambdananas..." + lambdananas "$1" + exit 0 +fi + +if [ "$#" == 1 ] && [ "$1" == "--help" ]; then + cat_readme + exit 0 +fi + +if [ "$#" -ne 2 ]; then cat_readme + exit 1 +fi + +mkdir -p /tmp/noge/ +DELIVERY_DIR=$(my_readlink "$1") +REPORTS_DIR=/tmp/noge/ +DOCKER_SOCKET_PATH=/var/run/docker.sock +HAS_SOCKET_ACCESS=$(test -r "$DOCKER_SOCKET_PATH"; echo "$?") +IMAGE_NAME="ghcr.io/epitech/coding-style-checker:latest" +EXPORT_FILE="/tmp/noge/coding-style-reports.log" +BASE_EXEC_CMD="docker" + +rm -f "$EXPORT_FILE" +chown -R $USER:$USER "$REPORTS_DIR" +chmod -R 777 "$REPORTS_DIR" + +if [ "$HAS_SOCKET_ACCESS" -ne 0 ]; then + echo "WARNING: Socket access is denied" + echo "To fix this, add the current user to the docker group: sudo usermod -a -G docker $USER" + read -p "Do you want to proceed? (yes/no) " yn + case $yn in + yes | Y | y | Yes | YES) + sudo usermod -a -G docker "$USER" + echo "You must reboot your computer for the changes to take effect." + ;; + *) + echo "Skipping..." + ;; + esac + BASE_EXEC_CMD="sudo ${BASE_EXEC_CMD}" +fi + +LOCAL_IMAGE_DATE=$(docker inspect --format='{{.Created}}' "$IMAGE_NAME" 2>/dev/null) +REMOTE_IMAGE_DATE=$(curl -sI "https://ghcr.io/v2/epitech/coding-style-checker/manifests/latest" | grep -i "last-modified" | cut -d' ' -f2-) + +if [ -z "$LOCAL_IMAGE_DATE" ] || [ "$(date -d "$REMOTE_IMAGE_DATE" +%s)" -gt "$(date -d "$LOCAL_IMAGE_DATE" +%s)" ]; then + echo "Downloading new image and cleaning old one..." + $BASE_EXEC_CMD pull "$IMAGE_NAME" && $BASE_EXEC_CMD image prune -f + echo "Download OK" + tput setaf 2 + echo "**/*/*/*/*/*/*/*/*/*/*/* CODING STYLE CHECKER EPITECH */*/*/*/*/*/*/*/*/*/*/*/**" + tput sgr0 +else + tput setaf 1 +fi + +$BASE_EXEC_CMD run --rm -i -v "$DELIVERY_DIR:/mnt/delivery" -v "$REPORTS_DIR:/mnt/reports" "$IMAGE_NAME" "/mnt/delivery" "/mnt/reports" + +[[ -f "$EXPORT_FILE" ]] && echo "$(wc -l < "$EXPORT_FILE") coding style error(s) reported in "$EXPORT_FILE", $(tput sgr0; tput setaf 9; grep -c ": MAJOR:" "$EXPORT_FILE") major, $(tput sgr0; tput setaf 27; grep -c ": MINOR:" "$EXPORT_FILE") minor, $(tput sgr0; tput setaf 11; grep -c ": INFO:" "$EXPORT_FILE") info" +tput setaf 2 +if [[ -f "/tmp/noge/coding-style-reports.log" ]]; then + cat /tmp/noge/coding-style-reports.log fi From 4e8da0406322391731b3fe7a6104041af9d9a330 Mon Sep 17 00:00:00 2001 From: Noge <146479712+nogebeat@users.noreply.github.com> Date: Sun, 2 Mar 2025 05:15:57 +0000 Subject: [PATCH 02/10] =?UTF-8?q?=F0=9F=94=A5=20Refactor=20&=20Fix:=20Am?= =?UTF-8?q?=C3=A9lioration=20du=20script=20Bash=20+=20nouvel=20installateu?= =?UTF-8?q?r=20Haskell-=20=F0=9F=9B=A0=20Correction=20de=20bugs=20dans=20l?= =?UTF-8?q?e=20script=20Bash=20:=20=20-=20Fix=20de=20la=20fonction=20my=5F?= =?UTF-8?q?readlink=20(gestion=20des=20erreurs=20de=20cd)=20=20-=20Correct?= =?UTF-8?q?ion=20des=20conditions=20if=20avec=20-eq=20au=20lieu=20de=20=3D?= =?UTF-8?q?=3D=20=20-=20S=C3=A9curisation=20de=20la=20mise=20=C3=A0=20jour?= =?UTF-8?q?=20de=20lambdananas=20(find,=20cp=20au=20lieu=20de=20cat)=20=20?= =?UTF-8?q?-=20Am=C3=A9lioration=20de=20la=20gestion=20des=20couleurs=20av?= =?UTF-8?q?ec=20tput=20=20-=20V=C3=A9rification=20plus=20robuste=20des=20d?= =?UTF-8?q?ates=20pour=20la=20mise=20=C3=A0=20jour=20Docker-=20=EF=BF=BD?= =?UTF-8?q?=EF=BF=BD=20Impl=C3=A9mentation=20d'une=20nouvelle=20version=20?= =?UTF-8?q?de=20l'installateur=20Haskell=20:=20=20-=20Meilleure=20gestion?= =?UTF-8?q?=20des=20d=C3=A9pendances=20et=20installation=20plus=20propre-?= =?UTF-8?q?=20=F0=9F=93=96=20Mise=20=C3=A0=20jour=20de=20l'aide=20(cat=5Fr?= =?UTF-8?q?eadme)=20pour=20une=20documentation=20plus=20claire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- coding-style.sh | 86 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 60 insertions(+), 26 deletions(-) diff --git a/coding-style.sh b/coding-style.sh index f9da472..51358c8 100755 --- a/coding-style.sh +++ b/coding-style.sh @@ -1,30 +1,58 @@ #!/bin/bash +## +## EPITECH PROJECT, 2025 +## Epitech +## File description: +## coding-style-checker +## + + function my_readlink() { - cd "$1" + cd "$1" 2>/dev/null || { echo "Error: Cannot cd into $1"; exit 1; } pwd cd - > /dev/null } function cat_readme() { echo "" - echo "Usage: $(basename "$0") DELIVERY_DIR REPORTS_DIR [HASKELL_FILE]" - echo -e "\tDELIVERY_DIR\tShould be the directory where your project files are" - echo -e "\tREPORTS_DIR\tShould be the directory where we output the reports" - echo -e "\tHASKELL_FILE\t(Optional) If a Haskell file is provided, it will be checked with lambdananas" - echo -e "\t\t\tTake note that existing reports will be overridden" + echo "Usage: $(basename "$0") [OPTIONS] DELIVERY_DIR REPORTS_DIR" + echo "" + echo "Arguments:" + echo -e "\tDELIVERY_DIR\tPath to the directory containing your project files." + echo -e "\tREPORTS_DIR\tPath to the directory where reports will be saved." + echo "" + echo "Options:" + echo -e "\t-hs, --haskell DELIVERY_DIR \t(Optional) Run lambdananas on the specified Haskell directory." + echo -e "\t--help\t\t\tShow this help message and exit." + echo "" + echo "Notes:" + echo -e "\t- Running with the Haskell option (-hs)" + echo -e "\t- Existing reports in the output directory will be overwritten." echo "" + echo "© 2025 Epitech. Tous droits réservés." } -IMAGE_HASKELL="ghcr.io/nogebeat/lambdananas:latest" -LOCAL_BINARY="/usr/local/bin/lambdananas" +LOCAL_BINARY="/usr/local/bin/" -if ! command -v lambdananas &> /dev/null; then - echo "lambdananas not found. Installing via Docker..." +function update_lambdananas() { + echo "Updating lambdananas..." + LAMBDA_PATH=$(sudo find /var/lib/docker/overlay2/ -name "lambdananas" 2>/dev/null | head -n 1) + + if [[ -z "$LAMBDA_PATH" ]]; then + echo "Error: lambdananas binary not found in Docker filesystem." + return 1 + fi - docker run --rm --entrypoint cat "$IMAGE_HASKELL" /usr/local/bin/lambdananas > lambdananas + sudo cp "$LAMBDA_PATH" ./lambdananas chmod +x lambdananas sudo mv lambdananas "$LOCAL_BINARY" +} + +if ! command -v lambdananas &> /dev/null; then + echo "lambdananas not found. Installing via Docker..." + + update_lambdananas if ! command -v lambdananas &> /dev/null; then echo "Installation failed." @@ -32,14 +60,14 @@ if ! command -v lambdananas &> /dev/null; then fi fi - -if [ "$#" -eq 1 ] && [[ "$1" == *.hs ]]; then +if [ "$#" -eq 2 ] && [[ "$1" == "-hs" || "$1" == "--haskell" ]]; then echo "Detected Haskell file. Running lambdananas..." - lambdananas "$1" + excluded_dirs="Setup.hs:setup.hs:.git:.stack-work:test:tests:bonus" + lambdananas -o vera --exclude "$excluded_dirs" "$2" exit 0 fi -if [ "$#" == 1 ] && [ "$1" == "--help" ]; then +if [ "$#" -eq 1 ] && [ "$1" == "--help" ]; then cat_readme exit 0 fi @@ -59,7 +87,7 @@ EXPORT_FILE="/tmp/noge/coding-style-reports.log" BASE_EXEC_CMD="docker" rm -f "$EXPORT_FILE" -chown -R $USER:$USER "$REPORTS_DIR" +chown -R "$USER:$USER" "$REPORTS_DIR" chmod -R 777 "$REPORTS_DIR" if [ "$HAS_SOCKET_ACCESS" -ne 0 ]; then @@ -81,21 +109,27 @@ fi LOCAL_IMAGE_DATE=$(docker inspect --format='{{.Created}}' "$IMAGE_NAME" 2>/dev/null) REMOTE_IMAGE_DATE=$(curl -sI "https://ghcr.io/v2/epitech/coding-style-checker/manifests/latest" | grep -i "last-modified" | cut -d' ' -f2-) -if [ -z "$LOCAL_IMAGE_DATE" ] || [ "$(date -d "$REMOTE_IMAGE_DATE" +%s)" -gt "$(date -d "$LOCAL_IMAGE_DATE" +%s)" ]; then - echo "Downloading new image and cleaning old one..." - $BASE_EXEC_CMD pull "$IMAGE_NAME" && $BASE_EXEC_CMD image prune -f - echo "Download OK" - tput setaf 2 - echo "**/*/*/*/*/*/*/*/*/*/*/* CODING STYLE CHECKER EPITECH */*/*/*/*/*/*/*/*/*/*/*/**" - tput sgr0 -else - tput setaf 1 +if [[ -n "$REMOTE_IMAGE_DATE" ]] && [[ -n "$LOCAL_IMAGE_DATE" ]]; then + LOCAL_TIMESTAMP=$(date -d "$LOCAL_IMAGE_DATE" +%s 2>/dev/null || echo 0) + REMOTE_TIMESTAMP=$(date -d "$REMOTE_IMAGE_DATE" +%s 2>/dev/null || echo 0) + + if [ "$REMOTE_TIMESTAMP" -gt "$LOCAL_TIMESTAMP" ]; then + echo "Downloading new image and cleaning old one..." + $BASE_EXEC_CMD pull "$IMAGE_NAME" && $BASE_EXEC_CMD image prune -f + update_lambdananas + echo "Download OK" + fi fi +tput setaf 2 +echo "**/*/*/*/*/*/*/*/*/*/*/* CODING STYLE CHECKER EPITECH */*/*/*/*/*/*/*/*/*/*/*/**" +tput sgr0 + $BASE_EXEC_CMD run --rm -i -v "$DELIVERY_DIR:/mnt/delivery" -v "$REPORTS_DIR:/mnt/reports" "$IMAGE_NAME" "/mnt/delivery" "/mnt/reports" [[ -f "$EXPORT_FILE" ]] && echo "$(wc -l < "$EXPORT_FILE") coding style error(s) reported in "$EXPORT_FILE", $(tput sgr0; tput setaf 9; grep -c ": MAJOR:" "$EXPORT_FILE") major, $(tput sgr0; tput setaf 27; grep -c ": MINOR:" "$EXPORT_FILE") minor, $(tput sgr0; tput setaf 11; grep -c ": INFO:" "$EXPORT_FILE") info" -tput setaf 2 +tput sgr0; echo "" + if [[ -f "/tmp/noge/coding-style-reports.log" ]]; then cat /tmp/noge/coding-style-reports.log fi From 8944d75130eb0778835e03f4a38cabd15660fe5f Mon Sep 17 00:00:00 2001 From: Noge <146479712+nogebeat@users.noreply.github.com> Date: Sun, 2 Mar 2025 05:17:30 +0000 Subject: [PATCH 03/10] readaptation de my_readlink --- coding-style.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coding-style.sh b/coding-style.sh index 51358c8..61667a0 100755 --- a/coding-style.sh +++ b/coding-style.sh @@ -9,7 +9,7 @@ function my_readlink() { - cd "$1" 2>/dev/null || { echo "Error: Cannot cd into $1"; exit 1; } + cd "$1" pwd cd - > /dev/null } From c59998f9aaee3aff4005a908849e1124ba253302 Mon Sep 17 00:00:00 2001 From: Noge <146479712+nogebeat@users.noreply.github.com> Date: Sun, 2 Mar 2025 05:42:29 +0000 Subject: [PATCH 04/10] readaptation de my_readlink --- coding-style.sh | 54 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/coding-style.sh b/coding-style.sh index 61667a0..5d97438 100755 --- a/coding-style.sh +++ b/coding-style.sh @@ -37,42 +37,64 @@ LOCAL_BINARY="/usr/local/bin/" function update_lambdananas() { echo "Updating lambdananas..." - LAMBDA_PATH=$(sudo find /var/lib/docker/overlay2/ -name "lambdananas" 2>/dev/null | head -n 1) - - if [[ -z "$LAMBDA_PATH" ]]; then - echo "Error: lambdananas binary not found in Docker filesystem." - return 1 + + if ! command -v docker &> /dev/null; then + echo "Error: Docker is not installed. Please install it and retry." + echo "Use this link to search how to install docker on your pc : https://docs.docker.com/engine/install/ " + fi + + if ! systemctl is-active --quiet docker; then + echo " Error: Docker service is not running. Start it with: sudo systemctl start docker" + read -p "Do you want to proceed? (yes/no) " yn + case $yn in + yes | Y | y | Yes | YES) + sudo systemctl start docker + ;; + *) + echo "Skipping..." + ;; + esac + fi + + IMAGE_NAME="ghcr.io/epitech/coding-style-checker:latest" + if ! docker image inspect "$IMAGE_NAME" &>/dev/null; then + echo "🔄 Downloading Docker image for lambdananas..." + docker pull "$IMAGE_NAME" || { echo "❌ Failed to pull Docker image."; exit 1; } fi + LAMBDA_PATH=$(sudo find /var/lib/docker/overlay2/ -name "lambdananas" 2>/dev/null | head -n 1) + sudo cp "$LAMBDA_PATH" ./lambdananas + + if [[ ! -f "./lambdananas" ]]; then + echo "Error: Failed to extract lambdananas from Docker." + exit 1 + fi + chmod +x lambdananas sudo mv lambdananas "$LOCAL_BINARY" + + echo "Lambdananas successfully updated!" } if ! command -v lambdananas &> /dev/null; then - echo "lambdananas not found. Installing via Docker..." - + echo "⚠️ lambdananas not found. Installing via Docker..." update_lambdananas - - if ! command -v lambdananas &> /dev/null; then - echo "Installation failed." - exit 1 - fi fi -if [ "$#" -eq 2 ] && [[ "$1" == "-hs" || "$1" == "--haskell" ]]; then - echo "Detected Haskell file. Running lambdananas..." +if [[ "$#" -eq 2 && ( "$1" == "-hs" || "$1" == "--haskell" ) ]]; then + echo "📌 Detected Haskell file. Running lambdananas..." excluded_dirs="Setup.hs:setup.hs:.git:.stack-work:test:tests:bonus" lambdananas -o vera --exclude "$excluded_dirs" "$2" exit 0 fi -if [ "$#" -eq 1 ] && [ "$1" == "--help" ]; then +if [[ "$#" -eq 1 && "$1" == "--help" ]]; then cat_readme exit 0 fi -if [ "$#" -ne 2 ]; then +if [[ "$#" -ne 2 ]]; then cat_readme exit 1 fi From 3814066a9c0e9224ac2dbea513ac7a34b3902ea9 Mon Sep 17 00:00:00 2001 From: Noge <146479712+nogebeat@users.noreply.github.com> Date: Sun, 2 Mar 2025 05:45:16 +0000 Subject: [PATCH 05/10] feat: improve lambdananas installation and error handling- Refactored to extract the binary cleanly from Docker instead of searching in --- coding-style.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/coding-style.sh b/coding-style.sh index 5d97438..698dcf6 100755 --- a/coding-style.sh +++ b/coding-style.sh @@ -63,14 +63,11 @@ function update_lambdananas() { fi LAMBDA_PATH=$(sudo find /var/lib/docker/overlay2/ -name "lambdananas" 2>/dev/null | head -n 1) - sudo cp "$LAMBDA_PATH" ./lambdananas - if [[ ! -f "./lambdananas" ]]; then echo "Error: Failed to extract lambdananas from Docker." exit 1 fi - chmod +x lambdananas sudo mv lambdananas "$LOCAL_BINARY" From c2f24bfb60ead311a4f8363bfd54cf7eba94c7b2 Mon Sep 17 00:00:00 2001 From: Noge <146479712+nogebeat@users.noreply.github.com> Date: Mon, 3 Mar 2025 18:47:59 +0000 Subject: [PATCH 06/10] =?UTF-8?q?feat:=20refonte=20et=20am=C3=A9lioration?= =?UTF-8?q?=20du=20script=20de=20v=C3=A9rification=20du=20coding=20style-?= =?UTF-8?q?=20R=C3=A9organisation=20du=20script=20pour=20une=20meilleure?= =?UTF-8?q?=20lisibilit=C3=A9=20et=20maintenabilit=C3=A9=20=20-=20Ajout=20?= =?UTF-8?q?d'une=20fonction=20=20pour=20g=C3=A9rer=20la=20mise=20=C3=A0=20?= =?UTF-8?q?jour=20des=20images=20Docker=20s=C3=A9par=C3=A9ment=20=20-=20Am?= =?UTF-8?q?=C3=A9lioration=20de=20l'analyse=20des=20arguments=20et=20du=20?= =?UTF-8?q?formatage=20du=20message=20d'aide=20=20-=20Ajout=20de=20la=20pr?= =?UTF-8?q?ise=20en=20charge=20de=20la=20v=C3=A9rification=20du=20coding?= =?UTF-8?q?=20style=20Haskell=20(=20ou=20)=20=20-=20Meilleure=20gestion=20?= =?UTF-8?q?des=20erreurs=20et=20des=20permissions=20pour=20les=20r=C3=A9pe?= =?UTF-8?q?rtoires=20de=20rapports=20=20-=20Optimisation=20de=20la=20v?= =?UTF-8?q?=C3=A9rification=20et=20mise=20=C3=A0=20jour=20de=20l=E2=80=99i?= =?UTF-8?q?mage=20Docker=20=20-=20Am=C3=A9lioration=20du=20retour=20utilis?= =?UTF-8?q?ateur=20avec=20des=20messages=20plus=20clairs=20et=20un=20affic?= =?UTF-8?q?hage=20color=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- coding-style-reports.log | 0 coding-style.sh | 169 +++++++++++++++++---------------------- 2 files changed, 72 insertions(+), 97 deletions(-) create mode 100644 coding-style-reports.log diff --git a/coding-style-reports.log b/coding-style-reports.log new file mode 100644 index 0000000..e69de29 diff --git a/coding-style.sh b/coding-style.sh index 698dcf6..63eee57 100755 --- a/coding-style.sh +++ b/coding-style.sh @@ -7,6 +7,7 @@ ## coding-style-checker ## +BASE_EXEC_CMD="docker" function my_readlink() { cd "$1" @@ -33,122 +34,96 @@ function cat_readme() { echo "© 2025 Epitech. Tous droits réservés." } -LOCAL_BINARY="/usr/local/bin/" - -function update_lambdananas() { - echo "Updating lambdananas..." - - if ! command -v docker &> /dev/null; then - echo "Error: Docker is not installed. Please install it and retry." - echo "Use this link to search how to install docker on your pc : https://docs.docker.com/engine/install/ " - fi - - if ! systemctl is-active --quiet docker; then - echo " Error: Docker service is not running. Start it with: sudo systemctl start docker" - read -p "Do you want to proceed? (yes/no) " yn - case $yn in - yes | Y | y | Yes | YES) - sudo systemctl start docker - ;; - *) - echo "Skipping..." - ;; - esac - fi - - IMAGE_NAME="ghcr.io/epitech/coding-style-checker:latest" - if ! docker image inspect "$IMAGE_NAME" &>/dev/null; then - echo "🔄 Downloading Docker image for lambdananas..." - docker pull "$IMAGE_NAME" || { echo "❌ Failed to pull Docker image."; exit 1; } - fi - - LAMBDA_PATH=$(sudo find /var/lib/docker/overlay2/ -name "lambdananas" 2>/dev/null | head -n 1) - sudo cp "$LAMBDA_PATH" ./lambdananas - if [[ ! -f "./lambdananas" ]]; then - echo "Error: Failed to extract lambdananas from Docker." - exit 1 - fi - chmod +x lambdananas - sudo mv lambdananas "$LOCAL_BINARY" - - echo "Lambdananas successfully updated!" -} - -if ! command -v lambdananas &> /dev/null; then - echo "⚠️ lambdananas not found. Installing via Docker..." - update_lambdananas -fi - -if [[ "$#" -eq 2 && ( "$1" == "-hs" || "$1" == "--haskell" ) ]]; then - echo "📌 Detected Haskell file. Running lambdananas..." - excluded_dirs="Setup.hs:setup.hs:.git:.stack-work:test:tests:bonus" - lambdananas -o vera --exclude "$excluded_dirs" "$2" - exit 0 -fi if [[ "$#" -eq 1 && "$1" == "--help" ]]; then cat_readme exit 0 fi -if [[ "$#" -ne 2 ]]; then +if [[ "$#" -gt 2 ]]; then cat_readme exit 1 fi -mkdir -p /tmp/noge/ -DELIVERY_DIR=$(my_readlink "$1") -REPORTS_DIR=/tmp/noge/ -DOCKER_SOCKET_PATH=/var/run/docker.sock -HAS_SOCKET_ACCESS=$(test -r "$DOCKER_SOCKET_PATH"; echo "$?") -IMAGE_NAME="ghcr.io/epitech/coding-style-checker:latest" -EXPORT_FILE="/tmp/noge/coding-style-reports.log" -BASE_EXEC_CMD="docker" - -rm -f "$EXPORT_FILE" -chown -R "$USER:$USER" "$REPORTS_DIR" -chmod -R 777 "$REPORTS_DIR" - -if [ "$HAS_SOCKET_ACCESS" -ne 0 ]; then - echo "WARNING: Socket access is denied" - echo "To fix this, add the current user to the docker group: sudo usermod -a -G docker $USER" - read -p "Do you want to proceed? (yes/no) " yn - case $yn in - yes | Y | y | Yes | YES) - sudo usermod -a -G docker "$USER" - echo "You must reboot your computer for the changes to take effect." - ;; - *) - echo "Skipping..." - ;; - esac - BASE_EXEC_CMD="sudo ${BASE_EXEC_CMD}" -fi +function pull_docker() { + mkdir -p /tmp/noge/ + DELIVERY_DIR=$(my_readlink "$1") + REPORTS_DIR="/tmp/noge/" + DOCKER_SOCKET_PATH="/var/run/docker.sock" + HAS_SOCKET_ACCESS=$(test -r "$DOCKER_SOCKET_PATH"; echo "$?") + IMAGE_NAME="ghcr.io/epitech/coding-style-checker:latest" + EXPORT_FILE="/tmp/noge/coding-style-reports.log" + + rm -f "$EXPORT_FILE" + chown -R "$USER:$USER" "$REPORTS_DIR" + chmod -R 777 "$REPORTS_DIR" + + if [[ "$HAS_SOCKET_ACCESS" -ne 0 ]]; then + echo "WARNING: Socket access is denied" + echo "To fix this, add the current user to the docker group: sudo usermod -a -G docker $USER" + read -rp "Do you want to proceed? (yes/no) " yn + case $yn in + yes | Y | y | Yes | YES) + sudo usermod -a -G docker "$USER" + echo "You must reboot your computer for the changes to take effect." + ;; + *) + echo "Skipping..." + ;; + esac + BASE_EXEC_CMD="sudo ${BASE_EXEC_CMD}" + fi -LOCAL_IMAGE_DATE=$(docker inspect --format='{{.Created}}' "$IMAGE_NAME" 2>/dev/null) -REMOTE_IMAGE_DATE=$(curl -sI "https://ghcr.io/v2/epitech/coding-style-checker/manifests/latest" | grep -i "last-modified" | cut -d' ' -f2-) + LOCAL_IMAGE_DATE=$(docker inspect --format='{{.Created}}' "$IMAGE_NAME" 2>/dev/null) + REMOTE_IMAGE_DATE=$(curl -sI "https://ghcr.io/v2/epitech/coding-style-checker/manifests/latest" | grep -i "last-modified" | cut -d' ' -f2-) -if [[ -n "$REMOTE_IMAGE_DATE" ]] && [[ -n "$LOCAL_IMAGE_DATE" ]]; then - LOCAL_TIMESTAMP=$(date -d "$LOCAL_IMAGE_DATE" +%s 2>/dev/null || echo 0) - REMOTE_TIMESTAMP=$(date -d "$REMOTE_IMAGE_DATE" +%s 2>/dev/null || echo 0) + if [[ -n "$REMOTE_IMAGE_DATE" && -n "$LOCAL_IMAGE_DATE" ]]; then + LOCAL_TIMESTAMP=$(date -d "$LOCAL_IMAGE_DATE" +%s 2>/dev/null || echo 0) + REMOTE_TIMESTAMP=$(date -d "$REMOTE_IMAGE_DATE" +%s 2>/dev/null || echo 0) - if [ "$REMOTE_TIMESTAMP" -gt "$LOCAL_TIMESTAMP" ]; then - echo "Downloading new image and cleaning old one..." - $BASE_EXEC_CMD pull "$IMAGE_NAME" && $BASE_EXEC_CMD image prune -f - update_lambdananas - echo "Download OK" + if [[ "$REMOTE_TIMESTAMP" -gt "$LOCAL_TIMESTAMP" ]]; then + echo "Downloading new image and cleaning old one..." + $BASE_EXEC_CMD pull "$IMAGE_NAME" && $BASE_EXEC_CMD image prune -f + echo "Download OK" + fi fi -fi +} tput setaf 2 echo "**/*/*/*/*/*/*/*/*/*/*/* CODING STYLE CHECKER EPITECH */*/*/*/*/*/*/*/*/*/*/*/**" tput sgr0 -$BASE_EXEC_CMD run --rm -i -v "$DELIVERY_DIR:/mnt/delivery" -v "$REPORTS_DIR:/mnt/reports" "$IMAGE_NAME" "/mnt/delivery" "/mnt/reports" +if [[ "$#" -eq 2 && ( "$1" == "-hs" || "$1" == "--haskell" ) ]]; then + echo "" + echo "📌 Running Haskell Coding Style ..." + echo "" + + pull_docker "$2" + + HASKELL_DIR=$(my_readlink "$2") + + excluded_dirs="Setup.hs:setup.hs:.git:.stack-work:test:tests:bonus" + + LAMBDA_PATH=$($BASE_EXEC_CMD run --rm --entrypoint /bin/bash ghcr.io/epitech/coding-style-checker:latest -c "which lambdananas") -[[ -f "$EXPORT_FILE" ]] && echo "$(wc -l < "$EXPORT_FILE") coding style error(s) reported in "$EXPORT_FILE", $(tput sgr0; tput setaf 9; grep -c ": MAJOR:" "$EXPORT_FILE") major, $(tput sgr0; tput setaf 27; grep -c ": MINOR:" "$EXPORT_FILE") minor, $(tput sgr0; tput setaf 11; grep -c ": INFO:" "$EXPORT_FILE") info" -tput sgr0; echo "" + # $BASE_EXEC_CMD run --rm --entrypoint /bin/bash ghcr.io/epitech/coding-style-checker:latest -c "which lambdananas" + $BASE_EXEC_CMD run --rm --entrypoint $LAMBDA_PATH -v "$HASKELL_DIR:/mnt/haskell" "$IMAGE_NAME" "/mnt/haskell" + exit 0 +fi -if [[ -f "/tmp/noge/coding-style-reports.log" ]]; then - cat /tmp/noge/coding-style-reports.log +if [[ "$#" -eq 2 || "$#" -eq 1 ]]; then + echo "" + echo "📌 Running C Coding Style ..." + echo "" + + pull_docker "$1" + + $BASE_EXEC_CMD run --rm -i -v "$DELIVERY_DIR:/mnt/delivery" -v "$REPORTS_DIR:/mnt/reports" "$IMAGE_NAME" "/mnt/delivery" "/mnt/reports" + + [[ -f "$EXPORT_FILE" ]] && echo "$(wc -l < "$EXPORT_FILE") coding style error(s) reported in "$EXPORT_FILE", $(tput sgr0; tput setaf 9; grep -c ": MAJOR:" "$EXPORT_FILE") major, $(tput sgr0; tput setaf 27; grep -c ": MINOR:" "$EXPORT_FILE") minor, $(tput sgr0; tput setaf 11; grep -c ": INFO:" "$EXPORT_FILE") info" + tput sgr0; echo "" + + if [[ -f "/tmp/noge/coding-style-reports.log" ]]; then + cat /tmp/noge/coding-style-reports.log + fi fi From 71fb7389698efd94132afae0671301f1f7bc6a2b Mon Sep 17 00:00:00 2001 From: Noge <146479712+nogebeat@users.noreply.github.com> Date: Mon, 3 Mar 2025 18:48:56 +0000 Subject: [PATCH 07/10] remove object file --- coding-style-reports.log | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 coding-style-reports.log diff --git a/coding-style-reports.log b/coding-style-reports.log deleted file mode 100644 index e69de29..0000000 From 98c820b0cb25e314a2235e882f45e16b482dc4eb Mon Sep 17 00:00:00 2001 From: Noge <146479712+nogebeat@users.noreply.github.com> Date: Mon, 3 Mar 2025 19:07:46 +0000 Subject: [PATCH 08/10] add wokflows --- .github/workflows/bash.yml | 139 +++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 .github/workflows/bash.yml diff --git a/.github/workflows/bash.yml b/.github/workflows/bash.yml new file mode 100644 index 0000000..ed35073 --- /dev/null +++ b/.github/workflows/bash.yml @@ -0,0 +1,139 @@ +name: Code Style Check in Bash + +on: + push: + branches: [ main, master ] + pull_request: + branches: [ main, master ] + workflow_dispatch: + +jobs: + test-bash-script: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Validate Bash script + run: | + chmod +x ./coding-style.sh + shellcheck ./coding-style.sh || echo "ShellCheck found issues, but continuing workflow" + + test-c-repo: + runs-on: ubuntu-latest + needs: test-bash-script + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Docker + run: | + if ! command -v docker &> /dev/null; then + sudo apt-get update + sudo apt-get install -y docker.io + sudo systemctl start docker + sudo systemctl enable docker + fi + + - name: Clone C repository + run: | + git clone https://github.com/examplehub/C.git c-project + + - name: Run coding style checker on C code + id: run-c-check + run: | + chmod +x ./coding-style.sh + mkdir -p reports + output=$(./coding-style.sh c-project reports 2>&1) + echo "$output" + + if echo "$output" | grep -q "📌 Running C Coding Style ..."; then + echo "C Style check started correctly" + else + echo "Error: C Style check didn't start correctly" + exit 1 + fi + + if [[ -f "/tmp/noge/coding-style-reports.log" ]]; then + errors=$(grep -c ":" /tmp/noge/coding-style-reports.log || echo "0") + echo "Found $errors coding style errors in C code" + echo "errors=$errors" >> $GITHUB_OUTPUT + else + echo "No coding style errors found or report not generated" + echo "errors=0" >> $GITHUB_OUTPUT + fi + + - name: Upload C style check results + uses: actions/upload-artifact@v4 + with: + name: c-style-check-report + path: | + reports/ + /tmp/noge/coding-style-reports.log + if-no-files-found: warn + retention-days: 5 + + test-haskell-repo: + runs-on: ubuntu-latest + needs: test-bash-script + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Docker + run: | + if ! command -v docker &> /dev/null; then + sudo apt-get update + sudo apt-get install -y docker.io + sudo systemctl start docker + sudo systemctl enable docker + fi + + - name: Clone Haskell repository + run: | + git clone https://github.com/marklnichols/haskell-examples.git haskell-project + + - name: Run coding style checker on Haskell code + id: run-haskell-check + run: | + chmod +x ./coding-style.sh + output=$(./coding-style.sh -hs haskell-project 2>&1) + echo "$output" + + if echo "$output" | grep -q "📌 Running Haskell Coding Style ..."; then + echo "Haskell Style check started correctly" + else + echo "Error: Haskell Style check didn't start correctly" + exit 1 + fi + + if echo "$output" | grep -q "error"; then + echo "Found coding style errors in Haskell code" + echo "has_errors=true" >> $GITHUB_OUTPUT + else + echo "No coding style errors found in Haskell code" + echo "has_errors=false" >> $GITHUB_OUTPUT + fi + + - name: Upload Haskell style check results + uses: actions/upload-artifact@v4 + with: + name: haskell-style-check-report + path: /tmp/noge/ + if-no-files-found: warn + retention-days: 5 + + notify: + runs-on: ubuntu-latest + needs: [test-c-repo, test-haskell-repo] + if: always() + steps: + - name: Check workflow status + run: | + if [[ "${{ needs.test-c-repo.result }}" == "success" && "${{ needs.test-haskell-repo.result }}" == "success" ]]; then + echo "All checks passed! Style check completed successfully." + echo "Note: Even if coding style errors were found, the workflow is considered successful if the checks ran properly." + else + echo "Some checks failed to execute properly. Check the logs for details." + exit 1 + fi \ No newline at end of file From 531e140e10d941a98987303528fcb3b4790a0891 Mon Sep 17 00:00:00 2001 From: Noge <146479712+nogebeat@users.noreply.github.com> Date: Tue, 4 Mar 2025 14:22:18 +0000 Subject: [PATCH 09/10] add condition for readme --- coding-style.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/coding-style.sh b/coding-style.sh index 63eee57..5933c12 100755 --- a/coding-style.sh +++ b/coding-style.sh @@ -40,7 +40,7 @@ if [[ "$#" -eq 1 && "$1" == "--help" ]]; then exit 0 fi -if [[ "$#" -gt 2 ]]; then +if [[ "$#" -gt 2 || "$#" -eq 0 ]]; then cat_readme exit 1 fi @@ -126,4 +126,5 @@ if [[ "$#" -eq 2 || "$#" -eq 1 ]]; then if [[ -f "/tmp/noge/coding-style-reports.log" ]]; then cat /tmp/noge/coding-style-reports.log fi + exit 0 fi From f06f533ad7703be4dcfd9742e500666100fa5824 Mon Sep 17 00:00:00 2001 From: Noge <146479712+nogebeat@users.noreply.github.com> Date: Fri, 14 Mar 2025 15:04:06 +0000 Subject: [PATCH 10/10] Correction coding c and relocation variable global --- coding-style.sh | 72 +++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/coding-style.sh b/coding-style.sh index 5933c12..4e38387 100755 --- a/coding-style.sh +++ b/coding-style.sh @@ -1,20 +1,20 @@ #!/bin/bash - + ## ## EPITECH PROJECT, 2025 ## Epitech ## File description: ## coding-style-checker ## - + BASE_EXEC_CMD="docker" - + function my_readlink() { cd "$1" pwd cd - > /dev/null } - + function cat_readme() { echo "" echo "Usage: $(basename "$0") [OPTIONS] DELIVERY_DIR REPORTS_DIR" @@ -33,31 +33,32 @@ function cat_readme() { echo "" echo "© 2025 Epitech. Tous droits réservés." } - - + + if [[ "$#" -eq 1 && "$1" == "--help" ]]; then cat_readme exit 0 fi - -if [[ "$#" -gt 2 || "$#" -eq 0 ]]; then + +if [[ "$#" -gt 2 ]]; then cat_readme exit 1 fi - + +REPORTS_DIR=$(my_readlink .) +EXPORT_FILE="$REPORTS_DIR"/coding-style-reports.log + function pull_docker() { - mkdir -p /tmp/noge/ DELIVERY_DIR=$(my_readlink "$1") - REPORTS_DIR="/tmp/noge/" DOCKER_SOCKET_PATH="/var/run/docker.sock" HAS_SOCKET_ACCESS=$(test -r "$DOCKER_SOCKET_PATH"; echo "$?") IMAGE_NAME="ghcr.io/epitech/coding-style-checker:latest" - EXPORT_FILE="/tmp/noge/coding-style-reports.log" - + #EXPORT_FILE="/tmp/noge/coding-style-reports.log" + rm -f "$EXPORT_FILE" - chown -R "$USER:$USER" "$REPORTS_DIR" - chmod -R 777 "$REPORTS_DIR" - + #chown -R "$USER:$USER" "$REPORTS_DIR" + #chmod -R 777 "$REPORTS_DIR" + if [[ "$HAS_SOCKET_ACCESS" -ne 0 ]]; then echo "WARNING: Socket access is denied" echo "To fix this, add the current user to the docker group: sudo usermod -a -G docker $USER" @@ -73,14 +74,14 @@ function pull_docker() { esac BASE_EXEC_CMD="sudo ${BASE_EXEC_CMD}" fi - + LOCAL_IMAGE_DATE=$(docker inspect --format='{{.Created}}' "$IMAGE_NAME" 2>/dev/null) REMOTE_IMAGE_DATE=$(curl -sI "https://ghcr.io/v2/epitech/coding-style-checker/manifests/latest" | grep -i "last-modified" | cut -d' ' -f2-) - + if [[ -n "$REMOTE_IMAGE_DATE" && -n "$LOCAL_IMAGE_DATE" ]]; then LOCAL_TIMESTAMP=$(date -d "$LOCAL_IMAGE_DATE" +%s 2>/dev/null || echo 0) REMOTE_TIMESTAMP=$(date -d "$REMOTE_IMAGE_DATE" +%s 2>/dev/null || echo 0) - + if [[ "$REMOTE_TIMESTAMP" -gt "$LOCAL_TIMESTAMP" ]]; then echo "Downloading new image and cleaning old one..." $BASE_EXEC_CMD pull "$IMAGE_NAME" && $BASE_EXEC_CMD image prune -f @@ -88,43 +89,44 @@ function pull_docker() { fi fi } - + tput setaf 2 echo "**/*/*/*/*/*/*/*/*/*/*/* CODING STYLE CHECKER EPITECH */*/*/*/*/*/*/*/*/*/*/*/**" tput sgr0 - + if [[ "$#" -eq 2 && ( "$1" == "-hs" || "$1" == "--haskell" ) ]]; then echo "" echo "📌 Running Haskell Coding Style ..." echo "" - + pull_docker "$2" - + HASKELL_DIR=$(my_readlink "$2") - + excluded_dirs="Setup.hs:setup.hs:.git:.stack-work:test:tests:bonus" - - LAMBDA_PATH=$($BASE_EXEC_CMD run --rm --entrypoint /bin/bash ghcr.io/epitech/coding-style-checker:latest -c "which lambdananas") - + + LAMBDA_PATH=$($BASE_EXEC_CMD run --rm --entrypoint /bin/bash ghcr.io/epitech/coding-style-checker:latest -c "which lambdananas") + # $BASE_EXEC_CMD run --rm --entrypoint /bin/bash ghcr.io/epitech/coding-style-checker:latest -c "which lambdananas" $BASE_EXEC_CMD run --rm --entrypoint $LAMBDA_PATH -v "$HASKELL_DIR:/mnt/haskell" "$IMAGE_NAME" "/mnt/haskell" exit 0 fi - + if [[ "$#" -eq 2 || "$#" -eq 1 ]]; then echo "" echo "📌 Running C Coding Style ..." echo "" - + pull_docker "$1" - + $BASE_EXEC_CMD run --rm -i -v "$DELIVERY_DIR:/mnt/delivery" -v "$REPORTS_DIR:/mnt/reports" "$IMAGE_NAME" "/mnt/delivery" "/mnt/reports" - + + #$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" [[ -f "$EXPORT_FILE" ]] && echo "$(wc -l < "$EXPORT_FILE") coding style error(s) reported in "$EXPORT_FILE", $(tput sgr0; tput setaf 9; grep -c ": MAJOR:" "$EXPORT_FILE") major, $(tput sgr0; tput setaf 27; grep -c ": MINOR:" "$EXPORT_FILE") minor, $(tput sgr0; tput setaf 11; grep -c ": INFO:" "$EXPORT_FILE") info" tput sgr0; echo "" - - if [[ -f "/tmp/noge/coding-style-reports.log" ]]; then - cat /tmp/noge/coding-style-reports.log + + if [[ -f "./coding-style-reports.log" ]]; then + cat ./coding-style-reports.log + rm -f ./coding-style-reports.log fi - exit 0 fi