|
| 1 | +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions |
| 2 | +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions |
| 3 | + |
| 4 | +name: Pelita CI testing |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: [ master ] |
| 9 | + pull_request: |
| 10 | + branches: [ master ] |
| 11 | + |
| 12 | +jobs: |
| 13 | + detect-team: |
| 14 | + # The detect-team job specifically looks for a file named |
| 15 | + # group0.py, group1.py, ..., group4.py |
| 16 | + # which it will use to search for a team that can be imported. |
| 17 | + # Outside of an ASPP school (it is a requirement that the main file |
| 18 | + # in the repo bears that name), this may not be useful and this job |
| 19 | + # can be skipped. |
| 20 | + runs-on: ubuntu-latest |
| 21 | + outputs: |
| 22 | + team: ${{ steps.set-group-script.outputs.group }} |
| 23 | + status: ${{ steps.set-group-script.outputs.status }} |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v2 |
| 26 | + - name: Detect group script |
| 27 | + id: set-group-script |
| 28 | + # some stupid bash string array tricks there: ($( .. )) |
| 29 | + run: | |
| 30 | + group=($(for g in group{0,1,2,3,4}.py ; do [ -f $g ] && echo "$g" || : ; done )) |
| 31 | + if [ ${#group[@]} -eq 1 ] ; then |
| 32 | + echo "::set-output name=group::\"${group}\"" |
| 33 | + echo "::set-output name=status::\"Run pelita with player from file ${group}\"" |
| 34 | + else |
| 35 | + if [ ${#group[@]} -eq 0 ] ; then |
| 36 | + echo "::error::No groupN.py file found." |
| 37 | + echo "::set-output name=group::false" |
| 38 | + echo "::set-output name=status::\"WARNING: No file groupN.py found. Cannot test tournament.\"" |
| 39 | + else |
| 40 | + echo "::error::More than one groupN.py file found." |
| 41 | + echo "::set-output name=status::\"Error: More than one groupN.py file found. Cannot test tournament.\"" |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | + fi |
| 45 | + shell: bash |
| 46 | + |
| 47 | + run-pelita: |
| 48 | + # We don’t want CI to fail, when no groupN.py file has been defined, but we |
| 49 | + # still want to inform the user about this. Our appraoch is to set the name |
| 50 | + # of the run-pelita action from the detect-python. |
| 51 | + name: ${{ fromJson(needs.detect-team.outputs.status) }} |
| 52 | + # Ideally, we would skip the rest of the action here with an if: clause, |
| 53 | + # if: ${{ fromJson(needs.detect-team.outputs.team) }} |
| 54 | + # but this would mean that the expression in name: doesn’t get evaulated either. |
| 55 | + # Therefore we skip on every single step below. |
| 56 | + needs: detect-team |
| 57 | + runs-on: ubuntu-latest |
| 58 | + strategy: |
| 59 | + fail-fast: false |
| 60 | + matrix: |
| 61 | + python-version: [3.9] |
| 62 | + |
| 63 | + steps: |
| 64 | + - uses: actions/checkout@v2 |
| 65 | + if: ${{ fromJson(needs.detect-team.outputs.team) }} |
| 66 | + - name: Set up Python ${{ matrix.python-version }} |
| 67 | + if: ${{ fromJson(needs.detect-team.outputs.team) }} |
| 68 | + uses: actions/setup-python@v2 |
| 69 | + with: |
| 70 | + python-version: ${{ matrix.python-version }} |
| 71 | + - name: Install dependencies |
| 72 | + if: ${{ fromJson(needs.detect-team.outputs.team) }} |
| 73 | + run: | |
| 74 | + python -m pip install --upgrade pip |
| 75 | + python -m pip install flake8 pytest |
| 76 | + python -m pip install git+https://github.com/ASPP/pelita |
| 77 | + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi |
| 78 | + - name: Check that a the team can be imported |
| 79 | + if: ${{ fromJson(needs.detect-team.outputs.team) }} |
| 80 | + run: | |
| 81 | + pelita --check-team ${{needs.detect-team.outputs.team}} |
| 82 | +
|
| 83 | + pytest: |
| 84 | + runs-on: ubuntu-latest |
| 85 | + strategy: |
| 86 | + fail-fast: false |
| 87 | + matrix: |
| 88 | + python-version: [3.9] |
| 89 | + |
| 90 | + steps: |
| 91 | + - uses: actions/checkout@v2 |
| 92 | + - name: Set up Python ${{ matrix.python-version }} |
| 93 | + uses: actions/setup-python@v2 |
| 94 | + with: |
| 95 | + python-version: ${{ matrix.python-version }} |
| 96 | + - name: Install dependencies |
| 97 | + run: | |
| 98 | + python -m pip install --upgrade pip |
| 99 | + python -m pip install flake8 pytest |
| 100 | + python -m pip install git+https://github.com/ASPP/pelita |
| 101 | + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi |
| 102 | + - name: Lint with flake8 |
| 103 | + run: | |
| 104 | + # stop the build if there are Python syntax errors or undefined names |
| 105 | + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics |
| 106 | + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide |
| 107 | + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics |
| 108 | + - name: Test with pytest |
| 109 | + run: | |
| 110 | + python -m pytest |
| 111 | +
|
0 commit comments