Repository navigation
113 lines (111 loc) · 3.78 KB
/
Copy pathcomponent-test-python.yml
File metadata and controls
113 lines (111 loc) · 3.78 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
name: Test
on:
workflow_call:
inputs:
runner-size:
required: false
type: string
description: 'Runner size for the component-runner-size-converter'
use-arc-runners:
required: false
type: boolean
default: true
description: "Run on the self-hosted ARC arm64 runners (default in private repositories, never used in public ones). Set to false to run on the GitHub-hosted linux-arm64 runners."
service-name:
required: false
type: string
description: 'Proper name for your service i.e API Service, Backend Service'
service-emoji:
required: false
type: string
description: 'An emoji to identify your service by :)'
python-version:
required: false
type: string
default: "3.13"
description: 'Python version to use'
test-directory:
required: false
type: string
default: "tests"
description: 'Directory containing test files'
pytest-args:
required: false
type: string
default: ""
description: 'Additional pytest arguments'
docker-compose-path:
required: false
type: string
description: 'File path of the docker compose file'
secrets:
TEST_ENV_FILE:
required: false
description: 'Environment variables for tests in .env format'
permissions:
contents: read
actions: read
jobs:
setup:
name: Setup
runs-on: ${{ (inputs.use-arc-runners && github.event.repository.private) && 'arc-arm64-1cpu-2gb-nodocker' || 'linux-arm64' }}
outputs:
runner-name: ${{ steps.runner.outputs.runner-name }}
steps:
- name: Get runner name
id: runner
uses: monta-app/github-workflows/.github/actions/runner-size-converter@main
with:
runner-size: ${{ inputs.runner-size }}
use-arc-runners: ${{ (inputs.use-arc-runners && github.event.repository.private) }}
test:
name: Test
needs: setup
runs-on: ${{ needs.setup.outputs.runner-name }}
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
- name: Setup Docker Compose
if: ${{ inputs.docker-compose-path }}
uses: monta-app/github-workflows/.github/actions/docker-compose-setup@main
with:
docker-compose-path: ${{ inputs.docker-compose-path }}
- name: Create .env file from secret
run: |
echo "${{ secrets.TEST_ENV_FILE }}" > .env
echo "Created .env file with $(wc -l < .env) lines"
- name: Set up Python ${{ inputs.python-version }}
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
with:
python-version: ${{ inputs.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2
with:
enable-cache: true
cache-dependency-glob: |
**/pyproject.toml
**/uv.lock
- name: Install dependencies
run: |
uv sync --all-extras --dev
- name: Run tests with pytest
id: pytest
run: |
PYTHONPATH=. uv run pytest ${{ inputs.test-directory }} \
--junit-xml=pytest-report.xml \
--html=pytest-report.html \
--self-contained-html \
--tb=short \
-v \
${{ inputs.pytest-args }}
- name: Upload test results
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: test-results-python-${{ inputs.python-version }}
path: |
pytest-report.xml
pytest-report.html
retention-days: 7
overwrite: true