-
Notifications
You must be signed in to change notification settings - Fork 8
120 lines (106 loc) · 3.92 KB
/
package-coverage.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
# This workflow runs tests and reports code coverage.
# We need a workflow name to be able to schedule it from Github UI
name: TestCoverage
on:
# workflow_call is what makes it reusable!
# we take the package path as the input
workflow_call:
inputs:
target_path:
description: "The path of the package"
required: true
type: string
python_versions:
description: "Python versions to run. Must be a JSON array. In PRs, the first version will be used to post a coverage comment"
default: '["3.11", "3.9"]'
type: string
nightly:
description: "If this is being executed nightly"
default: false
type: boolean
# sadly, we have to duplicate the inputs for workflow_dispatch
workflow_dispatch:
inputs:
target_path:
description: "The path of the package"
required: true
type: string
python_versions:
description: 'Python versions to run, ["3.11", "3.9"]'
default: '["3.11", "3.9"]'
type: string
nightly:
description: "If this is being executed nightly"
default: false
type: boolean
concurrency:
group: ${{ github.workflow }}-coverage-${{ github.ref }}-${{ inputs.target_path }}
cancel-in-progress: true
jobs:
# The job ID has to match repo settings for PR required checks
TestCoverage:
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: ${{ github.workspace }}/${{ inputs.target_path }}
# Run jobs for a couple of Python versions and OSes.
strategy:
matrix:
os: ["ubuntu-latest"]
python: ${{ fromJSON(inputs.python_versions) }}
# Extend the matrix with a job that prints coverage.
# Because { os: "ubuntu-latest", python: "3.11" } is already in the matrix,
# print_coverage: true is added to that job.
include:
- os: "ubuntu-latest"
python: ${{ fromJSON(inputs.python_versions)[0] }}
print_coverage: true
timeout-minutes: 25
name: Coverage - Python ${{ matrix.python }} - ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
# Fetch depth 0 required to compare against `main`
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
architecture: x64
cache: ${{ inputs.nightly == false && 'pip' || '' }}
# Installation method (venv/system/etc) affects Ray behavior. We're
# installing deps to a venv to align with the most common use case.
# Hence, we'll need to ensure the venv is always activated. More info:
# https://stackoverflow.com/questions/74668349/how-to-activate-a-virtualenv-in-a-github-action
- name: Install deps
shell: bash
run: |
python3 -m venv ./venv
source ./venv/bin/activate
make github_actions
- name: Run pre-test setup
shell: bash
run: |
source ./venv/bin/activate
make pre-coverage
- name: Run tests and gather coverage stats
shell: bash
run: |
source ./venv/bin/activate
make coverage
- name: Upload coverage reports as artifacts
uses: actions/upload-artifact@v4
with:
path: |
.coverage
coverage.xml
name: coverage-reports-python${{ matrix.python }}
- name: Comment with code coverage
# Conditionally run this step to prevent multiple comments
# Occasionally, multiple jobs could post at the same time.
if: matrix.print_coverage
uses: zapata-engineering/command-pr-comment@47141d48f14d33b89f8d689ebda1604fbc0bf4e0
with:
command: make PYTHON=./venv/bin/python github-actions-coverage-report
template: "🚀 Code Coverage\n```%command%```"
update-text: "🚀 Code Coverage"
working-dir: ${{ inputs.target_path }}