-
Notifications
You must be signed in to change notification settings - Fork 0
111 lines (106 loc) · 3.43 KB
/
reusable-python-testing-linting-with-db.yml
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
name: reusable-testing-linting-pipeline-with-db
on:
workflow_call:
inputs:
DJANGO_SETTINGS_MODULE:
required: true
type: string
directories_to_test:
description: "Directories to test"
type: string
required: false
default: "tests/"
directories_for_coverage:
description: "Directories to test"
type: string
required: false
default: "app/"
env:
JEST_JUNIT_OUTPUT_FILE: "/home/runner/work/${{ github.event.repository.name }}/${{ github.event.repository.name }}/unit-test-results.xml"
DJANGO_SETTINGS_MODULE: ${{ inputs.DJANGO_SETTINGS_MODULE }}
DATABASE_HOST: ${{ vars.DATABASE_HOST }}
DATABASE_NAME: ${{ vars.DATABASE_NAME }}
DATABASE_PASSWORD: ${{ vars.DATABASE_PASSWORD }}
DATABASE_USER: ${{ vars.DATABASE_USER }}
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
pull-requests: write
jobs:
Unit-Tests:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
db: [postgres]
postgresql-version: [14]
python-version: [3.11]
include:
- db: postgres
db_port: 5432
permissions:
contents: read
issues: read
checks: write
pull-requests: write
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Start PostgreSQL
run: |
sudo systemctl start postgresql.service
sudo -u postgres createuser -s runner
- name: Git clone the repository
uses: actions/checkout@v3
- name: Install Dependencies
run: pip install -r requirements.txt
- name: Run Tests
run: pytest ${{ inputs.directories_to_test }} --cov=${{ inputs.directories_for_coverage }} --cov-report=xml --junitxml=unit-test-results.xml
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
check_name: Unit-Tests-Report
junit_files: ${{ env.JEST_JUNIT_OUTPUT_FILE }}
- name: Code Coverage Report
uses: irongut/[email protected]
with:
filename: coverage.xml
badge: true
fail_below_min: true
format: markdown
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: '60 80'
- name: Finder
uses: jwalton/gh-find-current-pr@v1
id: finder
- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'push'
with:
number: ${{ steps.finder.outputs.pr }}
message: |
Test ${{ github.sha }} ended successfully.
This message is from a push.
recreate: false
path: code-coverage-results.md
Linting:
name: Linting with ruff
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Lint with Ruff
run: |
pip install ruff
ruff check --output-format=github .
continue-on-error: false