-
Notifications
You must be signed in to change notification settings - Fork 1
153 lines (153 loc) · 5.81 KB
/
_reusable-test-code.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
---
name: Test code
on:
workflow_call:
inputs:
repo-name:
description: The full name of the repository to use to gate Codecov uploads,
in the format `owner/repo`.
required: true
type: string
python-versions-array:
description: A valid JSON array of Python versions to test against. A valid
option is also the string 'pyproject.toml', indicating to use the defined
Python version from the pyproject.toml file.
required: true
type: string
operating-systems-array:
description: A valid JSON array of operating system names to run tests on.
required: false
default: '["ubuntu", "windows", "macos"]'
type: string
upload-to-codecov:
description: A boolean indicating if coverage results should be uploaded to
Codecov.
required: false
default: false
type: boolean
secrets:
codecov-token:
description: The token to use to upload coverage results to Codecov. Only
required when the `upload-codecov` input variable is set to `true`.
required: false
concurrency:
group: ${{ github.workflow }}-${{ github.ref }} (Reusable)
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
# Basic testing & linting
test-general:
runs-on: ${{ matrix.os-name }}-latest
strategy:
fail-fast: false
matrix:
os-name: ${{ fromJSON(inputs.operating-systems-array) }}
python-version: ${{ fromJSON(inputs.python-versions-array) }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
with:
node-version: lts/*
check-latest: true
- name: Set up Python (version)
if: ${{ matrix.python-version != 'pyproject.toml' }}
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
with:
python-version: ${{ matrix.python-version }}
check-latest: true
- name: Set up Python (pyproject.toml)
if: ${{ matrix.python-version == 'pyproject.toml' }}
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
with:
python-version-file: ${{ matrix.python-version }}
check-latest: true
- name: Install dependencies
run: python -m pip install tox tox-gh-actions
- name: Set up pre-commit cache
uses: actions/cache@0c907a75c2c80ebcb7f088228285e798b750cf8f # v4.2.1
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml')
}}
- name: Run tox
run: tox -v
- uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
if: ${{ !cancelled() }}
with:
name: artifact_${{ matrix.os-name }}_${{ matrix.python-version }}_tests_and_linting
include-hidden-files: true
path: |
.results_*/**
.coverage*
# Quick testing with coverage (no linting)
test-fast:
runs-on: ${{ matrix.os-name }}-latest
env:
REPO_NAME: ${{ inputs.repo-name }}
pytest_report_title: Test Results (${{ matrix.os-name }})
strategy:
fail-fast: false
matrix:
os-name: ${{ fromJSON(inputs.operating-systems-array) }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
with:
node-version: lts/*
check-latest: true
- name: Set up Python
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
with:
python-version-file: pyproject.toml
- name: Install tox
run: python -m pip install tox
- name: Run tox
id: run-tox
run: tox -ve tests
- uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
if: ${{ !cancelled() }}
with:
name: artifact_${{ matrix.os-name }}_tests
include-hidden-files: true
path: |
.results_*/**
.coverage*
- name: Upload coverage to Codecov
uses: codecov/codecov-action@13ce06bfc6bbe3ecf90edbbf1bc32fe5978ca1d3 # v5.3.1
if: ${{ always() && inputs.upload-to-codecov && github.repository == env.REPO_NAME && contains(fromJSON('["success", "failure"]'), steps.run-tox.outcome) }}
with:
token: ${{ secrets.codecov-token }}
files: ./.coverage_tests.xml
name: codecov-${{ matrix.os-name }}
fail_ci_if_error: true
verbose: true
# Update the workflow summary with test results
create-job-summary:
name: Test Results
if: ${{ !cancelled() }}
needs: test-fast
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
path: artifacts
- name: Generate Summary
uses: phoenix-actions/test-reporting@f957cd93fc2d848d556fa0d03c57bc79127b6b5e # v15
with:
name: Test Results
only-summary: false
output-to: step-summary
path: artifacts/**/.results_tests/results.xml
reporter: java-junit
fail-on-error: false
max-annotations: 0
# Check that all jobs passed
check-tests-passed:
if: ${{ !cancelled() }}
needs: [test-general, test-fast, create-job-summary]
runs-on: ubuntu-latest
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe # v1.2.2
with:
jobs: ${{ toJSON(needs) }}