-
Notifications
You must be signed in to change notification settings - Fork 0
134 lines (113 loc) · 4 KB
/
code_lint_and_test.yml
File metadata and controls
134 lines (113 loc) · 4 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
---
# This action performs a code linting and testing of files in the repository
# Name of the action
name: Lint and Test Code
# Events which trigger the action
on:
push:
pull_request:
workflow_dispatch:
jobs:
linting:
name: Lint repository files
runs-on: ubuntu-latest
steps:
# Checkout repository code
# checkout@v2 action documentation
# https://github.com/marketplace/actions/checkout
- name: Checkout repository
uses: actions/checkout@v2
# Install testing packages
- name: Install test packages
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements/requirements.txt
# Static code analysis with bandit
- name: Static code analysis with bandit
run: |
bandit -rc .bandit.yml .
# Lint Python files with flake8
- name: Lint Python files with flake8
run: |
flake8 . --count --show-source --statistics
# Lint YAML files with yamllint
- name: Lint YAML files yamllint
run: |
yamllint .
# Lint markdown files
# markdownlint-cli action documentation
# https://github.com/marketplace/actions/markdownlint-cli
- name: Lint Markdown files with markdownlint-cli
uses: nosborn/github-action-markdown-cli@v1.1.1
with:
files: .
config_file: .markdownlint.json
testing:
name: Test repository files
runs-on: ubuntu-latest
env:
PYTHONPATH: ./
steps:
# Checkout repository code
# checkout@v2 action documentation
# https://github.com/marketplace/actions/checkout
- name: Checkout repository
uses: actions/checkout@v2
# Install testing packages
- name: Install test packages
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements/requirements.txt
# Python application tests with pytest
- name: Python application tests with pytest
run: |
export PYTHONPATH=$PYTHONPATH:${{ env.PYTHONPATH }}
pytest tests/test_namedtuple_maker.py
# Python logging tests with pytest
- name: Python application tests with pytest
run: |
export PYTHONPATH=$PYTHONPATH:${{ env.PYTHONPATH }}
pytest -s tests/test_namedtuple_logger.py
package-install:
name: Test PyPI package installation
runs-on: ubuntu-latest
needs:
- linting
- testing
env:
DECORATOR: named_tuple_converter
MODULE: namedtuple_maker
PACKAGE: namedtuple-maker
TEST_SCRIPT: namedtuple_tester.py
steps:
# Install Python package with pip
- name: Install Python package with pip
run: |
pip install ${{ env.PACKAGE }}
# Test package module import
- name: Test package module import
run: |
python -c "from ${{ env.MODULE }} import ${{ env.MODULE }}"
# Build test script
- name: Build test script
run: |
echo "from ${{ env.MODULE }}.${{ env.MODULE }} import *" \
>> ${{ env.TEST_SCRIPT }}
echo >> ${{ env.TEST_SCRIPT }}
echo "@${{ env.DECORATOR }}" >> ${{ env.TEST_SCRIPT }}
echo "def ${{ env.DECORATOR }}_test(" >> ${{ env.TEST_SCRIPT }}
echo " iterable_input=TEST_DATA.values()," >> ${{ env.TEST_SCRIPT }}
echo " attribute_names=TEST_DATA.keys()" >> ${{ env.TEST_SCRIPT }}
echo "):" >> ${{ env.TEST_SCRIPT }}
echo " return iterable_input" >> ${{ env.TEST_SCRIPT }}
echo >> ${{ env.TEST_SCRIPT }}
echo "print(" >> ${{ env.TEST_SCRIPT }}
echo " ${{ env.DECORATOR }}_test(" >> ${{ env.TEST_SCRIPT }}
echo " attribute_names=TEST_DATA.keys()" >> ${{ env.TEST_SCRIPT }}
echo " )" >> ${{ env.TEST_SCRIPT }}
echo ")" >> ${{ env.TEST_SCRIPT }}
echo >> ${{ env.TEST_SCRIPT }}
# Run test script
- name: Run test script
run: |
python3 ${{ env.TEST_SCRIPT }}