From cce30252a74335c21ce44ce06b0d231a74a53bf5 Mon Sep 17 00:00:00 2001 From: Slimane MEHARZI <59923212+SlyPex@users.noreply.github.com> Date: Sun, 4 Aug 2024 21:39:28 +0100 Subject: [PATCH] Added New job in workflow check README.md file --- .github/scripts/readme_file_checker.sh | 40 ++++++++++++++++++++++++++ .github/workflows/ci.yml | 21 ++++++++++++-- .gitlab-ci.yml | 18 ++++++++---- .gitlab/scripts/readme_file_checker.sh | 40 ++++++++++++++++++++++++++ 4 files changed, 112 insertions(+), 7 deletions(-) create mode 100755 .github/scripts/readme_file_checker.sh create mode 100755 .gitlab/scripts/readme_file_checker.sh diff --git a/.github/scripts/readme_file_checker.sh b/.github/scripts/readme_file_checker.sh new file mode 100755 index 0000000..0654089 --- /dev/null +++ b/.github/scripts/readme_file_checker.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +set -euo pipefail + +if [[ "$#" -gt 2 ]] +then + echo -e "[!] - ERROR : Extra Argument Specified\nUsage : $0 [path_to_challs_directory] [path_to_readme_file]" >&2 + exit 1 +elif [[ "$#" -lt 2 ]] +then + echo -e "[!] - ERROR : Missing Argument\nUsage : $0 [path_to_challs_directory] [path_to_readme_file]" >&2 + exit 1 +else + LINES_IN_TABLE=$(grep -Pc "^\|" "$2") + COUNTER=0 + + mapfile -t CHALLS_UNDER_DIR < <(echo $(ls "$1" | sort)) + mapfile -t CHALLS_IN_TABLE < <(echo $(grep -P "^\|" "$2" | tail -n $(($LINES_IN_TABLE - 2)) | cut -d '|' -f 2 | sort )) + + + for dir_chall in "${CHALLS_UNDER_DIR[@]}" + do + for tab_chall in "${CHALLS_IN_TABLE[@]}" + do + if [[ "$dir_chall" = "$tab_chall" ]] + then + COUNTER=$(( $COUNTER + 1 )) + fi + done + done + + if [[ $COUNTER -eq $(($(ls -l "$1" | wc -l ) - 1)) ]] + then + echo "[*] - SUCCESS : Challs in README.md and Directory are the same" + exit 0 + else + echo "[!] - ERROR : Checking Failed" >&2 + exit 1 + fi +fi \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1c78548..7b3ee76 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,8 @@ on: workflow_dispatch: ###################### env: - DIRECTORY: challenges + - DIRECTORY: challenges + - README_FILE: README.md ###################### jobs: test: @@ -107,4 +108,20 @@ jobs: up-flags: "--build" - name: Test Challenge - run: docker ps -a \ No newline at end of file + run: docker ps -a + +###################### + check_readme_file_table: + name: 'Check Table with Number of Challs' + runs-on: ubuntu-latest + defaults: + run: + shell: bash + steps: + - name: 'Checkout' + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + + - name: 'Comparaison Number of Challs between Table and within Directory' + run: .github/scripts/readme_file_checker.sh $DIRECTORY $README_FILE \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 541d084..20fcf04 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,12 +7,13 @@ workflow: when: never stages: - - Test Challenge Structure + - Test Challenge Files - Check Deployability - Test Deployment variables: DIRECTORY: challenges + README_FILE: README.md .standard_rules: rules: @@ -23,12 +24,12 @@ variables: Job 1: extends: .standard_rules - stage: Test Challenge Structure + stage: Test Challenge Files image: python:3.11.4-alpine3.18 script: - python .gitlab/scripts/chall_structure_validator.py $DIRECTORY/$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME -Job 2: +Job 3: extends: .standard_rules stage: Check Deployability needs: @@ -41,7 +42,7 @@ Job 2: reports: dotenv: deploy.env -Job 3: +Job 4: extends: .standard_rules stage: Test Deployment image: docker:latest @@ -51,4 +52,11 @@ Job 3: - job: Job 2 artifacts: true script: - - sh .gitlab/scripts/test_deploy.sh $DIRECTORY/$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME \ No newline at end of file + - sh .gitlab/scripts/test_deploy.sh $DIRECTORY/$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME + +Job 2: + extends: .standard_rules + stage: Test Challenge Files + image: alpine:3.18 + script: + - sh .gitlab/scripts/readme_file_checker.sh $DIRECTORY $README_FILE \ No newline at end of file diff --git a/.gitlab/scripts/readme_file_checker.sh b/.gitlab/scripts/readme_file_checker.sh new file mode 100755 index 0000000..0654089 --- /dev/null +++ b/.gitlab/scripts/readme_file_checker.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +set -euo pipefail + +if [[ "$#" -gt 2 ]] +then + echo -e "[!] - ERROR : Extra Argument Specified\nUsage : $0 [path_to_challs_directory] [path_to_readme_file]" >&2 + exit 1 +elif [[ "$#" -lt 2 ]] +then + echo -e "[!] - ERROR : Missing Argument\nUsage : $0 [path_to_challs_directory] [path_to_readme_file]" >&2 + exit 1 +else + LINES_IN_TABLE=$(grep -Pc "^\|" "$2") + COUNTER=0 + + mapfile -t CHALLS_UNDER_DIR < <(echo $(ls "$1" | sort)) + mapfile -t CHALLS_IN_TABLE < <(echo $(grep -P "^\|" "$2" | tail -n $(($LINES_IN_TABLE - 2)) | cut -d '|' -f 2 | sort )) + + + for dir_chall in "${CHALLS_UNDER_DIR[@]}" + do + for tab_chall in "${CHALLS_IN_TABLE[@]}" + do + if [[ "$dir_chall" = "$tab_chall" ]] + then + COUNTER=$(( $COUNTER + 1 )) + fi + done + done + + if [[ $COUNTER -eq $(($(ls -l "$1" | wc -l ) - 1)) ]] + then + echo "[*] - SUCCESS : Challs in README.md and Directory are the same" + exit 0 + else + echo "[!] - ERROR : Checking Failed" >&2 + exit 1 + fi +fi \ No newline at end of file