Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 48 additions & 9 deletions .github/workflows/auto-grading.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <repository_url>'."
"You stage changes for a commit with 'git add <file>'."
"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!"
echo "✅ All answers are correct!"
14 changes: 7 additions & 7 deletions solution.txt
Original file line number Diff line number Diff line change
@@ -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 <repository_url>'.
You stage changes for a commit with 'git add <file>'.
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 <url of git repository".
6.You can stage changes for a commit by either uing "git add . (to stage all changes)" or "git add <file name> (to stage individual changes)".
7.You can push changes to a remote repository by using "git push origin <branch-name>" or "git push".