Skip to content

Commit

Permalink
[+] Add all files
Browse files Browse the repository at this point in the history
  • Loading branch information
toro-nicolas committed Jun 5, 2024
0 parents commit 7a861e8
Show file tree
Hide file tree
Showing 918 changed files with 196,293 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: amazed

on: [push, pull_request]

env:
MIRROR_URL: [email protected]:EpitechPromo2028/B-CPE-200-NCE-2-1-amazed-nicolas.toro.git
EXECUTABLE: amazed

jobs:
check_coding_style:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
- name: Check coding style
run:
docker run --rm --security-opt "label:disable" -i -v "$(pwd)":"/mnt/delivery" -v "$(pwd)":"/mnt/reports" ghcr.io/epitech/coding-style-checker:latest "/mnt/delivery" "/mnt/reports" ;
cat coding-style-reports.log;
.github/workflows/display_coding_style

check_program:
runs-on: ubuntu-latest
container:
image: epitechcontent/epitest-docker
needs: check_coding_style
steps:
- name: Checkout
uses: actions/[email protected]
- name: Launch "make"
run: make
timeout-minutes: 2
- name: Check banned functions
run: .github/workflows/check_banned_functions amazed .github/workflows/authorized_functions.txt
- name: Launch "make clean"
run: make clean
- name: Check program compilation
run: .github/workflows/check_program_compilation ${{ env.EXECUTABLE }}
- name: Launch "make tests_run"
run: make tests_run
timeout-minutes: 2

push_to_mirror:
runs-on: ubuntu-latest
if: |
startsWith(github.ref, 'refs/heads/ga-ignore-') == false &&
github.repository != 'EpitechPromo2028/B-CPE-200-NCE-2-1-amazed-nicolas.toro'
needs: check_program
steps:
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0
- name: Mirroring Repository
uses: pixta-dev/[email protected]
with:
target_repo_url:
${{ env.MIRROR_URL }}
ssh_private_key:
${{ secrets.GIT_SSH_PRIVATE_KEY }}
5 changes: 5 additions & 0 deletions .github/workflows/authorized_functions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
read
write
malloc
free
getline
93 changes: 93 additions & 0 deletions .github/workflows/check_banned_functions
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/python3
# Created by Dawoox
# https://github.com/Dawoox/efc/tree/main

import shutil
import subprocess
import sys
import re
from typing import List

TEXT_RED = '\033[31m'
TEXT_GREEN = '\033[32m'
TEXT_CLEAR = '\033[0m'


def get_functions(bin_path: str) -> List[str]:
nm_process = subprocess.run(['nm', '-C', bin_path], stdout=subprocess.PIPE)
if nm_process.returncode != 0:
print('ERROR: nm failed')
exit(1)
lines = nm_process.stdout.decode().split('\n')
f_list = [line.split(' ')[-1] for line in lines if ' U ' in line]
f_list = [fx.split(' ')[-1] for fx in f_list if not fx.startswith('__')]
f_list = [fx.split('@')[0] for fx in f_list]
return f_list


def parse_file(file_path: str) -> List[str]:
try:
with open(file_path, 'r') as file:
lines = [line.strip() for line in file.readlines()]
return lines
except FileNotFoundError as e:
print(f"ERROR: Did not found {file_path}")
sys.exit(1)


def find_authorized_functions(functions_list: List[str], a_filepath: str) -> List[str]:
af_list = parse_file(a_filepath)
return [func for func in functions_list if not any(re.search(af, func) for af in af_list)]


def is_tool_present(tool_name: str) -> bool:
return shutil.which(tool_name) is not None


def print_usage() -> None:
print("""
Usage: python3 main.py /path/to/your/binary [/path/to/authorized_functions.txt]
If you don't specify a path to authorized_functions.txt, the program will
use the default one (./bonus/authorized_functions.txt)
""")


def run_analysis(bin_path: str, bf_path: str) -> None:
print(f'Analyzing {bin_path}...')
f_list = get_functions(bin_path)
print(f'Found {len(f_list)} functions')
print('Checking for banned functions...')
a_list = find_authorized_functions(f_list, bf_path)
if len(a_list) == 0:
print(f'{TEXT_GREEN}No banned functions found{TEXT_CLEAR}')
exit(0)
else:
print(f'{TEXT_RED}Found {len(a_list)} banned functions !{TEXT_CLEAR}')
print(f'{TEXT_RED}Banned functions:{TEXT_CLEAR}')
for bf_found in a_list:
print("-" + TEXT_RED + bf_found + TEXT_CLEAR)
print("::error title=Banned function found::" + bf_found)
exit(1)


def main():
if len(sys.argv) >= 2 and (sys.argv[1] == '-h' or sys.argv[1] == '--help'):
print_usage()
exit(0)
if not is_tool_present('nm'):
print('ERROR: Cannot find nm executable, please install nm')
exit(1)
if len(sys.argv) == 3:
binary_path = sys.argv[1]
a_path = sys.argv[2]
run_analysis(binary_path, a_path)
if len(sys.argv) == 2:
binary_path = sys.argv[1]
a_path = './bonus/authorized_functions.txt'
run_analysis(binary_path, a_path)
print_usage()
exit(1)


if __name__ == '__main__':
main()
17 changes: 17 additions & 0 deletions .github/workflows/check_program_compilation
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/python3
import os
from sys import argv

if __name__ == "__main__":
if len(argv) == 2:
file_content = argv[1].split(",")
for file in file_content:
if not os.path.exists(file):
print("::error file=" + file + "::File not found")
exit(1)
if not os.access(file, os.X_OK):
print("::error file=" + file + "::File is not executable")
exit(1)
exit(0)
else:
exit(0)
22 changes: 22 additions & 0 deletions .github/workflows/display_coding_style
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/python3

if __name__ == "__main__":
with open("coding-style-reports.log", "r") as f:
file_content = f.readlines()
find = False
if len(file_content) > 0:
for line in file_content:
content = line.split(":")
if len(content[2].split(" ")) > 2:
continue
print("::error file=" + content[0] + ",line=" + content[1] +
",title=" + content[2].split(" ")[1] + " coding style error::" + content[3])
find = True
if find:
exit(1)
else:
print("No errors found")
exit(0)
else:
print("No errors found")
exit(0)
85 changes: 85 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
##
## EPITECH PROJECT, 2023
## amazed
## File description:
## The main Makefile of our project
##

NAME = amazed

BUILDDIR = ./build
SRCDIR = ./src

SRCS += main.c
SRCS += amazed.c
SRCS += init_maze.c
SRCS += parse_file.c
SRCS += rooms.c
SRCS += doors.c
SRCS += path_finding.c
SRCS += robots.c

OBJS = $(addprefix $(BUILDDIR)/, $(notdir $(SRCS:.c=.o)))

CFLAGS = -Werror -Wextra -I./include/
DEBUGFLAGS = -g3
OPTIMIZEFLAGS = -O3

LDFLAGS = -L./lib/ -lmymemory -lmylist -lmy

all: create-build libs $(BUILDDIR) $(NAME)
@echo -e "\033[1;33m$(NAME) compiled.\033[0m"

libs:
@make --no-print-directory -C ./lib/my/
@make --no-print-directory -C ./lib/mylist/
@make --no-print-directory -C ./lib/mymemory/
@echo -e "\033[1;33mLibs made.\033[0m"

create-build:
@mkdir -p $(BUILDDIR)

$(BUILDDIR)/%.o: $(SRCDIR)/%.c
$(CC) $(CFLAGS) $(OPTIMIZEFLAGS) $(LDFLAGS) -c $< -o $@

debug: CFLAGS += $(DEBUGFLAGS)
debug: OPTIMIZEFLAGS =
debug: all

$(NAME): $(OBJS)
@$(CC) $(OBJS) $(CFLAGS) $(OPTIMIZEFLAGS) $(LDFLAGS) -o $(NAME)
@rm -rf ./lib/my/*.a
@rm -rf ./lib/mylist/*.a
@rm -rf ./lib/mymemory/*.a

clean:
@rm -rf $(BUILDDIR)
@echo -e "\033[1;31mAll .o deleted.\033[0m"

fclean: clean
@rm -rf ./lib/*.a
@rm -rf unit_tests*
@rm -rf tests/unit_tests*
@rm -rf vgcore*
@rm -rf *.log
@rm -rf $(NAME)
@echo -e "\033[1;31mProject cleaned.\033[0m"

re: fclean all

# Unit tests Makefile
unit_tests:
@make unit_tests --no-print-directory -C./tests/

tests_run:
@make tests_run --no-print-directory -C./tests/
@gcovr

# Documentation
doc: tests_run
@doxygen Doxyfile
@gcovr \
--branch --html-details docs/tests/test.html
@echo -e "\033[1;33mDocumentation generated.\033[0m"
@google-chrome docs/html/index.html
@google-chrome docs/tests/test.html
Loading

0 comments on commit 7a861e8

Please sign in to comment.