Skip to content

Commit

Permalink
Added New job in workflow check README.md file
Browse files Browse the repository at this point in the history
  • Loading branch information
SlyPex committed Aug 4, 2024
1 parent 951c0ea commit cce3025
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 7 deletions.
40 changes: 40 additions & 0 deletions .github/scripts/readme_file_checker.sh
Original file line number Diff line number Diff line change
@@ -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
21 changes: 19 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ on:
workflow_dispatch:
######################
env:
DIRECTORY: challenges
- DIRECTORY: challenges
- README_FILE: README.md
######################
jobs:
test:
Expand Down Expand Up @@ -107,4 +108,20 @@ jobs:
up-flags: "--build"

- name: Test Challenge
run: docker ps -a
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
18 changes: 13 additions & 5 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -41,7 +42,7 @@ Job 2:
reports:
dotenv: deploy.env

Job 3:
Job 4:
extends: .standard_rules
stage: Test Deployment
image: docker:latest
Expand All @@ -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
- 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
40 changes: 40 additions & 0 deletions .gitlab/scripts/readme_file_checker.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit cce3025

Please sign in to comment.