UCL-MPHY0021-21-22 / RSE-Classwork

7 stars 73 forks source link

Adding a Continuous Integration system #19

Open alessandrofelder opened 3 years ago

alessandrofelder commented 3 years ago

Use CI to run the tests for you.

It's always possible that we forget to run the tests before pushing to GitHub. Luckily, continuous integration (CI) platforms can help us catch failing tests even when we do forget to run them. In this exercise, you will use GitHub Actions to do exactly this.

Set up Github Actions to run our tests for every commit we push to our repository.

on: [push]

jobs: build:

runs-on: ubuntu-latest
strategy:
  matrix:
    python-version: [3.6, 3.9]

steps:
  - uses: actions/checkout@v2
  - name: Set up Python ${{ matrix.python-version }}
    uses: actions/setup-python@v2
    with:
      python-version: ${{ matrix.python-version }}
  - name: Install dependencies
    run: |
      python -m pip install --upgrade pip
      pip install pytest
  - name: Test with pytest
    run: |
      pytest

- Discuss with your group what you think each of the lines in `.github/workflows/python-tests.yml` does
- Add `.github/workflows/python-tests.yml` to the repository, commit it and push it to github. Link to this issue on that commit by including `Answers https://github.com/UCL-MPHY0021-21-22/RSE-Classwork/issues/19` in the commit message.
- Check whether the tests pass on your remote (_Hint_: check the Actions tab on your GitHub fork)

If you're done with this issue, try to add test coverage by working on this related issue: https://github.com/UCL-MPHY0021-21-22/RSE-Classwork/issues/20

## [Sample solution](https://github.com/alessandrofelder/times-tests/blob/check-ci-works/.github/workflows/pytest.yaml) and [sample solution in action](https://github.com/alessandrofelder/times-tests/actions/runs/1418054616).