-
Notifications
You must be signed in to change notification settings - Fork 69
Autograding action not able to read GitHub Secrets (Actions) #69
Comments
the example repo can be found here: https://github.com/unhueteb-org/Tecnun2023-Azure-VisionAI |
When autograding runs grading tests, it runs them in a child process with very few environment variables brought in. You could try running the pytest tests as seperate steps. If the test passes, drop a file. Then in autograding test if the file exists. Something like: ...
# delete and recreate result dir
- name: Reset results dir
run: |
rm -rf .github/results
mkdir -p .github/results
# Test 1.1
- run: pytest 1-rest-client.py && touch .github/results/test1-1-pass
# Test 1.2
- run: pytest 1-sdk-client.py && touch .github/results/test1-2-pass
...
- uses: education/autograding@v1 Then in {
"tests": [
{
"name": "Activity 1 - Accept assignment",
"setup": "",
"run": "[ -e .github/results/test1-1-pass ] && exit 0 || exit 1",
"input": "",
"output": "",
"comparison": "included",
"timeout": 10,
"points": 1
},
{
"name": "Activity 1 - Accept assignment",
"setup": "",
"run": "[ -e .github/results/test1-2-pass ] && exit 0 || exit 1",
"input": "",
"output": "",
"comparison": "included",
"timeout": 10,
"points": 1
},
]
} etc |
Thanks for the reply @markpatterson27 , I will try it! :) |
Hi! classroom.yml jobs:
build:
name: Autograding
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: |
echo GITHUB_ACTOR="$GITHUB_ACTOR" >> owner-environment
echo GITHUB_REPOSITORY_OWNER="$GITHUB_REPOSITORY_OWNER" >> owner-environment
- uses: education/autograding@v1 autograding.json {
"tests": [
{
"name": "Verificacion Links a otras paginas",
"setup": "",
"run": "source owner-environment && cat owner-environment",
"input": "",
"output": "",
"comparison": "included",
"timeout": 10,
"points": 100
}
]
} The important part is |
it is possible another method to read variables? |
Does using the file-detection based approach vs. an environment variable-setting script approach pose any major differences in terms of "security concerns" (xref: #19 (comment) and #19 (comment))? My intuition is that either way, the robust method for preventing "circumvention" is for the teacher to run the tests in a private instance (e.g., locally) and use those grades directly or check for mismatches between GitHub Classroom grades via the CLI. @booleanchile I tried saving a "Using secrets in a workflow" gh docs are very relevant.
I kept getting
{
"tests": [
{
"name": "GitHub secrets test (env vars)",
"setup": "sudo -H pip3 install -r requirements.txt",
"run": ". ./setenv.sh && pytest github_secrets_test.py::test_env_vars_exist",
"input": "",
"output": "",
"comparison": "exact",
"timeout": 5,
"points": 2
},
{
"name": "Orchestrator client test",
"setup": "sudo -H pip3 install -r requirements.txt",
"run": ". ./setenv.sh && pytest orchestrator_client_test.py",
"input": "",
"output": "",
"comparison": "exact",
"timeout": 5,
"points": 3
},
{
"name": "Microcontroller client test",
"setup": "sudo -H pip3 install -r requirements.txt",
"run": ". ./setenv.sh && pytest microcontroller_client_test.py",
"input": "",
"output": "",
"comparison": "exact",
"timeout": 5,
"points": 3
},
{
"name": "GitHub secrets test (basic comms)",
"setup": "sudo -H pip3 install -r requirements.txt",
"run": ". ./setenv.sh && pytest github_secrets_test.py::test_basic_hivemq_communication",
"input": "",
"output": "",
"comparison": "exact",
"timeout": 5,
"points": 2
}
]
}
name: GitHub Classroom Workflow
on:
- push
- workflow_dispatch
permissions:
checks: write
actions: read
contents: read
jobs:
build:
name: Autograding
runs-on: ubuntu-latest
if: github.actor != 'github-classroom[bot]'
steps:
- uses: actions/checkout@v4
- name: Create file for setting env vars
# https://github.com/education/autograding/issues/69#issuecomment-1497674655
# https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#using-secrets-in-a-workflow
env:
HIVEMQ_HOST: ${{ secrets.HIVEMQ_HOST }}
HIVEMQ_USERNAME: ${{ secrets.HIVEMQ_USERNAME }}
HIVEMQ_PASSWORD: ${{ secrets.HIVEMQ_PASSWORD }}
COURSE_ID: ${{ secrets.COURSE_ID }}
run: |
echo "#!/bin/sh" > setenv.sh
echo "export HIVEMQ_HOST=\"$HIVEMQ_HOST\"" >> setenv.sh
echo "export HIVEMQ_PASSWORD=\"$HIVEMQ_PASSWORD\"" >> setenv.sh
echo "export HIVEMQ_USERNAME=\"$HIVEMQ_USERNAME\"" >> setenv.sh
echo "export COURSE_ID=\"$COURSE_ID\"" >> setenv.sh
chmod +x setenv.sh
- uses: education/autograding@v1 Note: I'm not sure if |
Hello,
I was testing running some pytest to test some Python files and it fails when getting the GitHub Secrets from environment variables.
autograding workflow
autograding.json
post-create.sh installs all neccesary python libraries.
This is the error I get, it does not read the env variable.
Running another custom workflow (one below) executing my pytest file works. What am I missing?
The text was updated successfully, but these errors were encountered: