diff --git a/.github/workflows/auto-grading.yml b/.github/workflows/auto-grading.yml index 2b960f4..2d0c6ef 100644 --- a/.github/workflows/auto-grading.yml +++ b/.github/workflows/auto-grading.yml @@ -15,27 +15,66 @@ jobs: - name: Install jq run: sudo apt-get install -y jq + - name: List Files in Repository + run: ls -R + + - name: Debug - Display solution.txt Content + run: | + if [ -f "solution.txt" ]; then + echo "📄 Content of solution.txt:" + cat solution.txt + else + echo "❌ solution.txt file not found!" + exit 1 + fi + - name: Validate Solution - env: - EXPECTED_ANSWERS: ${{ secrets.EXPECTED_ANSWERS }} run: | + # Ensure solution.txt exists if [ ! -f "solution.txt" ]; then - echo "❌ Missing solution file!" && exit 1 + echo "❌ Missing solution.txt in the root directory!" + exit 1 fi - # Read expected answers from secret - expected_answers=$(echo $EXPECTED_ANSWERS | jq -r '.[]') + # Define expected answers directly in the script + expected_answers=( + "A commit is a snapshot of changes in the repository." + "A branch is a separate line of development in the repository." + "A pull request is a request to merge changes from one branch to another." + "You initialize a new Git repository with 'git init'." + "You clone a repository from GitHub with 'git clone '." + "You stage changes for a commit with 'git add '." + "You push changes to a remote repository with 'git push'." + ) # Read answers from solution.txt IFS=$'\n' read -d '' -r -a answers < solution.txt + # Ensure the number of answers matches + expected_count=${#expected_answers[@]} + actual_count=${#answers[@]} + + if [ "$expected_count" -ne "$actual_count" ]; then + echo "❌ Mismatch in the number of answers!" + echo "Expected: $expected_count" + echo "Found: $actual_count" + exit 1 + fi + # Validate answers index=0 - for expected_answer in $expected_answers; do - if [[ "${answers[$index]}" != *"$expected_answer"* ]]; then - echo "❌ Incorrect answer for question $((index+1))!" && exit 1 + for expected_answer in "${expected_answers[@]}"; do + # Normalize strings (remove extra spaces, convert to lowercase for comparison) + normalized_expected=$(echo "$expected_answer" | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]') + normalized_actual=$(echo "${answers[$index]}" | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]') + + if [[ "$normalized_actual" != *"$normalized_expected"* ]]; then + echo "❌ Incorrect answer for question $((index+1))!" + echo "Expected: $expected_answer" + echo "Found: ${answers[$index]}" + exit 1 fi index=$((index+1)) done - echo "✅ All answers are correct!" \ No newline at end of file + echo "✅ All answers are correct!" diff --git a/solution.txt b/solution.txt index 58f39e7..49b2ed0 100644 --- a/solution.txt +++ b/solution.txt @@ -1,7 +1,7 @@ -A commit is a snapshot of changes in the repository. -A branch is a separate line of development in the repository. -A pull request is a request to merge changes from one branch to another. -You initialize a new Git repository with 'git init'. -You clone a repository from GitHub with 'git clone '. -You stage changes for a commit with 'git add '. -You push changes to a remote repository with 'git push'. +1.A commit is like a snapshot of the current status or condition of a repsository at a specific point in time. +2.A branch is like a separate path within your project that allows you to work on changes without affecting the main codebase. +3.A pull request is used to propose changes form one branch to another, typically from a feature branch to a main branch. +4.You can initialise a new repository by running the command "git init". +5.You can clone the repository by using the command "git clone (to stage individual changes)". +7.You can push changes to a remote repository by using "git push origin " or "git push". \ No newline at end of file