generated from pythoninthegrasses/python_template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (85 loc) · 3.48 KB
/
python_test.yml
File metadata and controls
90 lines (85 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
# https://github.com/actions/setup-python/blob/main/docs/advanced-usage.md#caching-packages
# https://www.peterbe.com/plog/install-python-poetry-github-actions-faster
name: python_test
on:
workflow_dispatch:
# push:
# branches:
# - main
# pull_request:
jobs:
ci:
strategy:
matrix:
python-version: ["3.10", "3.11"]
os: ["ubuntu-latest"]
arch: ['x64']
runs-on: ${{ matrix.os }}
steps:
- name: checkout repo content
uses: actions/checkout@v3
# TODO: debug 'cache not found for input keys dotlocal-Linux-8e1cebf...'
# - name: load cached $HOME/.local
# uses: actions/cache@v2.1.6
# id: cash-money
# with:
# path: ~/.local
# key: dotlocal-${{ runner.os }}-${{ hashFiles('.github/workflows/python_test.yml') }}
# - run: echo '${{ steps.cash-money.outputs.cache-hit }}' # true if cache-hit occured on the primary key
# TODO: use `git config --global --add safe.directory` to find working dir (may need to set under checkout step)
- name: set cwd and change to directory
run: |
CWD=$(basename $(git rev-parse --show-toplevel))
BASE_DIR=$(cat BASE_DIR)
echo "BASE_DIR=$BASE_DIR" >> $GITHUB_ENV
cd ${{ env.BASE_DIR }} || unset BASE_DIR; \
BASE_DIR="$(pwd)/work/${CWD}/${CWD}" && echo "BASE_DIR=$BASE_DIR" >> $GITHUB_ENV; \
cd ${{ env.BASE_DIR }}
# - run: ls -la ${{ env.BASE_DIR }}
- name: Read .tool-versions # dynamic versions
uses: marocchino/tool-versions-action@v1
id: versions
with:
path: ${{ env.BASE_DIR }}/.tool-versions
- name: shuffle files
run: |
cat ${{ env.BASE_DIR }}/.tool-versions | awk '/python/ {print $NF}' >> ${{ env.BASE_DIR }}/.python-version
# [[ -e "$(pwd)/pyproject.toml" ]] && mv "$(pwd)/pyproject.toml" "$(pwd)/pyproject.toml.bak"
# cp "${{ env.BASE_DIR }}/pyproject.toml" $(pwd)/
- name: setup python
uses: actions/setup-python@v4
with:
python-version-file: ${{ env.BASE_DIR }}/.python-version
cache: 'pip'
- name: setup poetry
uses: snok/install-poetry@v1
id: cp310
with:
version: ${{ steps.versions.outputs.poetry }}
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: ${{ env.BASE_DIR }}
installer-parallel: true
- name: load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v2.1.6
with:
path: ${{ env.BASE_DIR }}/.venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}-${{ hashFiles('.github/workflows/python_test.yml') }}
- name: install virtualenv
run: |
cd ${{ env.BASE_DIR }}
poetry install
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
poetry run flake8 ${{ env.BASE_DIR }} --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
poetry run flake8 ${{ env.BASE_DIR }} --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
# TODO: write tests
- name: Test with pytest
run: |
# exit code 5 == 'collected 0 items'
poetry run pytest ${{ env.BASE_DIR }}