Reducing GitHub usage time on builds and tests

Hey! I just upgraded my assignment template’s yml file with a little snippet that:

  1. Prevents the runner from executing when the student accepts their assignment (or the template is cloned or forked or anything similar, and
  2. Will only execute when the student pushes their solution file to the repo, or I edit the test script.

It can really improve usage time for those of you approaching limits! That workflow won’t fire when you update some markdown file or whatever.

Here’s the yml file. I hope it helps someone.

name: Build and Test

on:
  push:
    # Perform this workflow only when there is a push to the student solution file or the pytest testing script
    # Force the runner to skip this workflow when the repo is first created (cloned, forked, whatevs)
    # https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions
    paths: 
      - 'tests/test_exercise.py'      # testing script
      - 'src/exercise.py'             # student solution file

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
      # Tell the runner to use the newest release of Python 3 available by using 'Python 3.x' syntax below
      # https://docs.github.com/en/actions/guides/building-and-testing-python
    - name: Set up Python 3.x
      uses: actions/setup-python@v2
      with:
        python-version: '3.x'
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install pytest flake8
    - name: Lint with flake8
      run: |
        # stop the build if there are Python syntax errors or undefined names
        flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
        # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
        flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
    - name: Test with pytest
      run: |
        python -m pytest

Here’s the different testing scripts I’ll use for different programming assignments.

Which, like I said, only fire when the students push their python programs or I manipulate the testing script. So I can go about my business of uploading pretty pictures of unicorns :unicorn: and embedding them on my markdown files without worrying about affecting my GitHub usage limits

5 Likes

This is exactly what I was looking for! For those who are curious, here are some more rules you can use: Workflow syntax for GitHub Actions - GitHub Docs

1 Like

Hey you guys, I cleaned up that ugly file I wrote lol.

Cuz no one likes ugly. And no one likes code that talks too much lol. Much like your favorite ex-mother-in-law…

name: Build and Test

    on:
      push:
        paths: 
          - 'src/exercise.py' 
          
    jobs:
      build_and_test:
        runs-on: ubuntu-latest
        steps:
        - uses: actions/setup-python@v2
          with:
            python-version: '3.x'
        - uses: actions/checkout@v2
        - run: |
            python3 -m pip install --upgrade pip
            pip install pytest flake8
            flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
            flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 
            python3 -m pytest

When I have come close to running out of build time, it has been due to infinite loops in student code, or errors in std::cin. The timeout parameter in .github/classroom/autograding.json does not actually halt the execution, so I’ve found adding the timeout command to my run command has greatly reduced usage. Instead of

"run": "make run-main",

I use

"run": "timeout 20 make run-main",

Which does halt execution (in this case after 20 seconds).

How do you get the modified .yml file into the students’ repositories? I created a custom classroom.yml and put it in my template repository. But, when students use the classroom link to create a repo, my classroom.yml gets overwritten by the default.

Hi!

Are you using the “add tests” feature of assignment creation? I think if you do that, it’ll overwrite your yml file with the automatically generated one.

With a custom yml file (workflow), you’ll need to add your own tests to the repo. You’ll also want to avoid adding the tests through the assignment creation interface.

1 Like

Try this out… Just follow the directions.

Hi, Bianca @RuizTheRuler.

Thanks a lot for sharing your solution!

I am having a problem implementing it though.

I created my own repository and then a simple assignment (check if a number is a multiple of 10) to test the workflow but… when the repository is loaded into Repl.it, it is detected as a bash repl instead of a Python one. Do you have any idea what could I have done wrong? I am an absolute beginner to GitHub, Classroom and Repl.it.

The invitation link for the assignment is https://classroom.github.com/a/W1ISgnxJ

By the way, I just noticed that I left your flowchart in my repo. :grimacing:

By the way, I can commit and push to GitHub and the code will pass the test, but I can’t run it interactively in Repl.it, which makes the setup unusable for the students.

When creating the assignment, I enabled feedback pull requests, your instructions didn’t mention anything about that, but I don’t think that’s the problem. I created a new assignment without enabling them and got the exact same behavior. :confused:

© 2017 GitHub, Inc.
with by
GitHub Education