Skip to content

Add custom working directory value to run tests #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
|-----------------|-----------------------------------------------------------------------------------------------------------------|----------|
| `timeout` | Duration (in minutes) before the test is terminated. Defaults to 10 minutes with a maximum limit of 6 hours. | Yes |
| `max-score` | Points to be awarded if the test passes. | No |
| `setup-command` | Command to execute prior to the test, typically for environment setup or dependency installation. | No |
| `setup-command` | Command to execute prior to the test, typically for environment setup or dependency installation. | No |
| `working-directory` | Relative location where pytest should start looking for tests. | No |

### Outputs

Expand Down Expand Up @@ -47,6 +48,7 @@ jobs:
timeout: '15'
max-score: '100'
setup-command: 'pip install -r requirements.txt'
working-directory: 'some_subdir'
- name: Autograding Reporter
uses: ...
```
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ inputs:
setup-command:
description: "Command to execute prior to the test, typically for environment setup or dependency installation."
required: false
working-directory:
description: "Working directory to start the test."
required: false
outputs:
result:
description: "Runner output"
Expand All @@ -23,3 +26,4 @@ runs:
- "--timeout=${{ inputs.timeout }}"
- "--max-score=${{ inputs.max-score }}"
- "--setup-command=${{ inputs.setup-command }}"
- "--working-directory=${{ inputs.working-directory }}"
7 changes: 5 additions & 2 deletions bin/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
root="/opt/test-runner"
export PYTHONPATH="$root:$PYTHONPATH"

mkdir autograding_output
mkdir -p autograding_output

while [ $# -gt 0 ]; do
case "$1" in
Expand All @@ -17,6 +17,9 @@ while [ $# -gt 0 ]; do
--setup-command=*)
SETUP_COMMAND="${1#*=}"
;;
--working-directory=*)
WORKING_DIR="${1#*=}"
;;
*)
printf "***************************\n"
printf "* Warning: Unknown argument.*\n"
Expand All @@ -34,7 +37,7 @@ if [ -n "$SETUP_COMMAND" ]; then
eval "$SETUP_COMMAND"
fi

timeout "$TIMEOUT" python3 /opt/test-runner/bin/run.py ./ ./autograding_output/ "$MAX_SCORE"
timeout "$TIMEOUT" python3 /opt/test-runner/bin/run.py ./$WORKING_DIR ./autograding_output/ "$MAX_SCORE"
exit_status=$?
if [ $exit_status -eq 124 ]; then
echo "The command took longer than $TIMEOUT seconds to execute. Please increase the timeout to avoid this error."
Expand Down