-
Notifications
You must be signed in to change notification settings - Fork 438
99 lines (91 loc) · 3.3 KB
/
tests.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
name: Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
types:
- opened
- ready_for_review
- reopened
- synchronize
workflow_call:
merge_group:
jobs:
test_package:
name: Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Poetry
run: pip install poetry
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: "3.11"
architecture: x64
cache: 'poetry'
- name: Install dependencies through poetry
run: |
poetry install
- name: Get coverage artifact ID
id: coverage-artifact
uses: actions/github-script@v7
if: github.event_name == 'pull_request'
with:
script: |
const workflows = await github.rest.actions.listRepoWorkflows({
owner: context.repo.owner,
repo: context.repo.repo,
});
const workflowId = workflows.data.workflows.find(workflow => workflow.name === "${{ github.workflow }}")?.id;
if (!workflowId) return "";
const workflowRuns = await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: workflowId,
branch: "${{ github.base_ref }}",
event: "push",
status: "success",
});
return workflowRuns.data.workflow_runs[0]?.id ?? "";
result-encoding: string
retries: 3
- name: Download main coverage artifact
uses: actions/download-artifact@v4
if: github.event_name == 'pull_request' && steps.coverage-artifact.outputs.result != ''
continue-on-error: true # There is a chance that the artifact doesn't exist, or has expired
with:
name: coverage
path: "${{ github.workspace }}/coverage-main"
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ steps.coverage-artifact.outputs.result }}
- name: Get coverage from main
id: coverage-value
run: |
MIN_COVERAGE=0
if [[ -f "./coverage-main/coverage.xml" ]]; then
MIN_COVERAGE=$(grep -m 1 "<coverage" "./coverage-main/coverage.xml" | sed -E 's/.*line-rate="([^"]*)".*/\1/') # Extract the line rate from the XML
MIN_COVERAGE=$(awk "BEGIN {print int($MIN_COVERAGE * 100)}") # Turn into percentage, rounding down to avoid rounding issues
fi
echo "MIN_COVERAGE=$MIN_COVERAGE" >> "$GITHUB_OUTPUT"
- name: Run Python Tests
run: make python-test optional_args="--junitxml=coverage-junit.xml --cov=. --cov-report xml:coverage.xml --cov-fail-under ${{ steps.coverage-value.outputs.MIN_COVERAGE }}"
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: coverage
path: |
coverage-junit.xml
coverage.xml
if-no-files-found: error
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"
cache-dependency-path: "code/frontend/package-lock.json"
- name: Run frontend unit tests
run: make unittest-frontend
- name: Lint
run: make lint