-
Notifications
You must be signed in to change notification settings - Fork 31
236 lines (210 loc) · 8.77 KB
/
Copy pathcodecov_aggregator.yml
File metadata and controls
236 lines (210 loc) · 8.77 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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
name: CI codecov aggregator
on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened, closed]
branches: [main]
permissions:
# required to post on the PR
pull-requests: write
# required for the local IT (which pulls HCD from ECR)
id-token: write
contents: write
# required to publish GH pages
pages: write
concurrency:
group: preview-pages-${{ github.ref }}
cancel-in-progress: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
main_it:
uses: ./.github/workflows/main.yml
if: ${{ github.event.action != 'closed' }}
with:
coverage_prefix: main_it
sha: ${{ github.sha }}
secrets:
ASTRA_DB_APPLICATION_TOKEN: ${{ secrets.ASTRA_DB_APPLICATION_TOKEN }}
ASTRA_DB_API_ENDPOINT: ${{ secrets.ASTRA_DB_API_ENDPOINT }}
HEADER_EMBEDDING_API_KEY_VOYAGEAI: ${{ secrets.HEADER_EMBEDDING_API_KEY_VOYAGEAI }}
LEGACY_INSERTMANY_BEHAVIOUR_PRE2193: ${{ secrets.LEGACY_INSERTMANY_BEHAVIOUR_PRE2193 }}
FIND_PAGE_SIZE: ${{ secrets.FIND_PAGE_SIZE }}
local_it:
uses: ./.github/workflows/local.yml
if: ${{ github.event.action != 'closed' }}
with:
coverage_prefix: local_it
sha: ${{ github.sha }}
secrets:
AWS_ECR_REGION: ${{ secrets.AWS_ECR_REGION }}
AWS_ECR_ACCOUNT_ID: ${{ secrets.AWS_ECR_ACCOUNT_ID }}
AWS_ECR_ROLE_NAME: ${{ secrets.AWS_ECR_ROLE_NAME }}
AWS_ECR_REPOSITORY: ${{ secrets.AWS_ECR_REPOSITORY }}
AWS_ECR_REGISTRY: ${{ secrets.AWS_ECR_REGISTRY }}
HEADER_EMBEDDING_API_KEY_VOYAGEAI: ${{ secrets.HEADER_EMBEDDING_API_KEY_VOYAGEAI }}
# hardcoding the target DB
DOCKER_COMPOSE_LOCAL_DATA_API: "yes"
# turn on header-based reranker auth
HEADER_RERANKING_API_KEY_NVIDIA: ${{ secrets.HEADER_RERANKING_API_KEY_NVIDIA }}
ut:
uses: ./.github/workflows/unit.yml
if: ${{ github.event.action != 'closed' }}
with:
coverage_prefix: ut
sha: ${{ github.sha }}
coverage_python_version: "3.12"
secrets:
# basic secrets
ASTRA_DB_APPLICATION_TOKEN: ${{ secrets.ASTRA_DB_APPLICATION_TOKEN }}
ASTRA_DB_API_ENDPOINT: ${{ secrets.ASTRA_DB_API_ENDPOINT }}
aggregate:
runs-on: ubuntu-latest
needs: [main_it, local_it, ut]
steps:
- name: Checkout code
if: ${{ github.event.action != 'closed' }}
uses: actions/checkout@v2
with:
# needed to retrieve the parents of the merge commit (hence the base commit on main)
fetch-depth: 2
- name: Set up Python
if: ${{ github.event.action != 'closed' }}
uses: actions/setup-python@v2
with:
python-version: 3.11
- name: Install dependencies
if: ${{ github.event.action != 'closed' }}
run: |
python -m pip install --upgrade pip
pipx install uv
make venv
- name: Download all coverage artifacts from this run
if: ${{ github.event.action != 'closed' }}
uses: actions/download-artifact@v4
with:
path: ./all_coverage
- name: Combine coverage data
if: ${{ github.event.action != 'closed' }}
run: uv run coverage combine $(find all_coverage/ -name ".coverage" 2>/dev/null)
- name: produce coverage JSON report
if: ${{ github.event.action != 'closed' }}
run: uv run coverage json
- name: verify JSON report output
if: ${{ github.event.action != 'closed' }}
run: cut -c -200 coverage.json
- name: Upload coverage JSON report for mid-term storage
if: ${{ github.event_name == 'push' }}
uses: actions/upload-artifact@v4
id: upload_json
with:
name: coverage-json-push-${{ github.sha }}
path: coverage.json
retention-days: 30
- name: produce coverage HTML report
if: ${{ github.event.action != 'closed' }}
run: |
uv run coverage html
test -f htmlcov/index.html
echo "commit=${GITHUB_SHA}" > htmlcov/_preview_build.txt
# This uploads the coverage html report to make it available for offline inspection
- name: Upload coverage HTML report for reference
uses: actions/upload-artifact@v4
id: upload_html
with:
name: coverage-html-report-${{ inputs.sha }}
path: htmlcov
retention-days: 7
include-hidden-files: true
# Note: the following would be to publish a PR-preview of the code coverage
# HTML report. Not completely set up, something does not work with publishing
# to GH Pages. Postponed.
# - name: Sanity check coverage output (WIP)
# run: |
# echo "PWD=$PWD"
# ls -la
# ls -la htmlcov || true
# test -f htmlcov/index.html || (echo "ERROR: htmlcov/index.html not found." && exit 1)
# echo "Files in htmlcov:"
# find htmlcov -type f | head -100
# - name: Deploy PR preview to Pages (WIP)
# if: ${{ github.event.action != 'closed' }}
# uses: rossjrw/pr-preview-action@v1
# with:
# source-dir: htmlcov
# - name: Remove PR preview (WIP)
# if: ${{ github.event.action == 'closed' }}
# uses: rossjrw/pr-preview-action@v1
# with:
# action: remove
- name: Compute base parent SHA of the merge commit
id: base_sha
shell: bash
run: |
BASE_SHA=$(git rev-parse "${GITHUB_SHA}^1")
echo "Base parent is $BASE_SHA"
echo "sha=$BASE_SHA" >> "$GITHUB_OUTPUT"
# some more logic to download main's coverage json as it is from another run ID
- name: Resolve run-id for main's coverage json
if: ${{ github.event.action != 'closed' && github.event_name == 'pull_request'}}
id: resolve_main_run_id
uses: actions/github-script@v7
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const name = `coverage-json-push-${process.env.ART_SHA}`;
// find artifacts with that name (in practice, we expect 0 or 1)
const res = await github.rest.actions.listArtifactsForRepo({
owner, repo, name, per_page: 100
});
if (!res.data.artifacts?.length) {
core.warning(`No artifact found named ${name}. Coverage delta will not be available`);
core.setOutput('run_id', '__NOT_SET__');
return;
}
// pick newest
const art = res.data.artifacts.sort((a,b) =>
new Date(b.created_at) - new Date(a.created_at))[0];
core.info(`Artifact ${art.id} from run ${art.workflow_run.id}`);
core.setOutput('run_id', art.workflow_run.id);
env:
ART_SHA: ${{ steps.base_sha.outputs.sha }}
- name: download coverage JSON from target commit on main
if: ${{ github.event.action != 'closed' && github.event_name == 'pull_request' && steps.resolve_main_run_id.outputs.run_id != '__NOT_SET__' }}
uses: actions/download-artifact@v4
with:
name: coverage-json-push-${{ steps.base_sha.outputs.sha }}
run-id: ${{ steps.resolve_main_run_id.outputs.run_id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
path: coverage_main
- name: generate code coverage short report
if: ${{ github.event.action != 'closed' && github.event_name == 'pull_request'}}
id: generate_coverage_report
shell: bash
run: |
set -o pipefail
# was: OUTPUT=$(uv run coverage report)
OUTPUT=$(uv run python tests/coverage_utils/calc_delta.py coverage_main/coverage.json coverage.json -f table)
# Multi-line safe write to $GITHUB_OUTPUT
echo "text<<EOF" >> "$GITHUB_OUTPUT"
echo "$OUTPUT" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: Comment on PR
if: ${{ github.event.action != 'closed' && github.event_name == 'pull_request' }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prNumber = context.payload.pull_request.number;
var missing_delta_notice = '';
if ('${{ steps.resolve_main_run_id.outputs.run_id }}' === '__NOT_SET__'){
missing_delta_notice = '\n*WARNING*: Unable to compute coverage delta information.\n';
}
const body = `### Coverage report\nfor commit: \`${{ github.sha }}\`.\ndownload detailed report [here](${{ steps.upload_html.outputs['artifact-url'] }}).\n${missing_delta_notice}\`\`\`\n${{ steps.generate_coverage_report.outputs.text }}\n\`\`\``;
await github.rest.issues.createComment({
...context.repo,
issue_number: prNumber,
body
});