-
Notifications
You must be signed in to change notification settings - Fork 45
Update coding-style.sh and add usage lamdananas #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nogebeat
wants to merge
10
commits into
Epitech:main
Choose a base branch
from
nogebeat:patch-3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2737a16
Update coding-style.sh
nogebeat 4e8da04
🔥 Refactor & Fix: Amélioration du script Bash + nouvel installateur H…
nogebeat 8944d75
readaptation de my_readlink
nogebeat c59998f
readaptation de my_readlink
nogebeat 3814066
feat: improve lambdananas installation and error handling- Refactored…
nogebeat c2f24bf
feat: refonte et amélioration du script de vérification du coding sty…
nogebeat 71fb738
remove object file
nogebeat 98c820b
add wokflows
nogebeat 531e140
add condition for readme
nogebeat f06f533
Correction coding c and relocation variable global
nogebeat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope