-
Notifications
You must be signed in to change notification settings - Fork 3
/
action.yaml
102 lines (101 loc) · 3.15 KB
/
action.yaml
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
91
92
93
94
95
96
97
98
99
100
101
102
name: Python Test
description: GitHub Action that tests a python based repository
inputs:
checkout-repo:
required: false
description: Perform checkout as first step of action
default: "true"
github-token:
required: true
description: GitHub token that can checkout the repository. e.g. 'secrets.GITHUB_TOKEN'
default: ""
test-flags:
required: false
description: Flags and args for test command
default: ""
setup-script:
required: false
description: Script to run before tests
default: ""
upload-coverage:
required: false
description: Upload coverage report to codecov
default: "false"
coveralls-repo-token:
required: false
description: Coveralls repo token
default: ""
runs:
using: composite
steps:
- name: Authorize
uses: open-turo/action-git-auth@v2
if: inputs.github-token != ''
with:
github-personal-access-token: ${{ inputs.github-token }}
- name: Checkout
uses: actions/checkout@v4
if: inputs.checkout-repo == 'true'
with:
fetch-depth: 0
- name: Setup python
uses: actions/setup-python@v5
# First we attempt to run a pip-based workflow if there is no poetry.lock
- name: Install pip dependencies
if: hashFiles('poetry.lock') == ''
shell: bash
#if there is a requirements-dev.txt or requirements-test.txt, we install that
run: |
if [[ -f requirements-dev.txt ]]; then
pip install -r requirements-dev.txt
elif [[ -f requirements-test.txt ]]; then
pip install -r requirements-test.txt
else
pip install -r requirements.txt
fi
- name: Run setup script
if: hashFiles('poetry.lock') == '' && inputs.setup-script != ''
shell: bash
run: |
${{ inputs.setup-script }}
- name: Run tests
if: hashFiles('poetry.lock') == ''
shell: bash
run: |
if command -v pytest &>/dev/null; then
pytest ${{ inputs.test-flags }}
elif [[ -f setup.py ]]; then
python setup.py test -- ${{ inputs.test-flags }}
else
echo "::error::pytest not found in the dependencies, cannot run tests"
exit 1
fi
# If we do have a poetry.lock, we use a poetry based workflow
- name: install poetry
if: hashFiles('poetry.lock') != ''
shell: bash
run: pip install poetry
- name: Install poetry dependencies
if: hashFiles('poetry.lock') != ''
shell: bash
run: poetry install
- name: Run setup script
if: hashFiles('poetry.lock') != '' && inputs.setup-script != ''
shell: bash
run: |
${{ inputs.setup-script }}
- name: Run poetry tests
if: hashFiles('poetry.lock') != ''
shell: bash
run: |
if poetry show pytest &>/dev/null; then
poetry run pytest ${{ inputs.test-flags }}
else
echo "::error::pytest not found in poetry.lock, cannot run tests"
exit 1
fi
- name: Upload coverage
if: inputs.upload-coverage != 'false'
uses: coverallsapp/github-action@v2
env:
COVERALLS_REPO_TOKEN: ${{ inputs.coveralls-repo-token }}