Skip to content

Commit 21e25fc

Browse files
authored
Merge branch 'master' into TutorTask531_Create_data_downloader_for_EIA
2 parents 2f34e44 + f4cae24 commit 21e25fc

4 files changed

Lines changed: 1528 additions & 72 deletions

File tree

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
name: Test coverage
2+
on:
3+
pull_request:
4+
# Run manually.
5+
workflow_dispatch: {}
6+
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch
7+
# every day at 00:00 UTC.
8+
schedule:
9+
- cron: '0 0 * * *'
10+
11+
env:
12+
CSFY_CI: true
13+
14+
# Set up permissions for OIDC authentication.
15+
permissions:
16+
# This is required for requesting the OIDC JWT.
17+
id-token: write
18+
# This is required for actions/checkout.
19+
contents: read
20+
# This is required for pulling the Docker image from GHCR.
21+
packages: read
22+
jobs:
23+
run_test_coverage:
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
# Configure AWS authentication for this workflow.
28+
# This step assumes an AWS IAM role to grant GH Action temporary
29+
# credentials necessary to access AWS resources.
30+
- name: Configure AWS credentials
31+
uses: aws-actions/configure-aws-credentials@v1
32+
with:
33+
role-to-assume: ${{ vars.GH_ACTION_AWS_ROLE_ARN }}
34+
role-session-name: ${{ vars.GH_ACTION_AWS_SESSION_NAME }}
35+
aws-region: ${{ vars.CSFY_AWS_DEFAULT_REGION }}
36+
37+
# This is needed to pull the Docker image.
38+
- name: Login to GHCR
39+
run: docker login ghcr.io -u gpsaggese -p ${{ secrets.GH_ACTION_ACCESS_TOKEN }}
40+
41+
# Make everything accessible by any user to avoid permission errors.
42+
- name: Cleanup
43+
run: sudo chmod 777 -R .
44+
45+
# Check out the code from GitHub so that we can run the action inside
46+
# the Docker container.
47+
- name: Checkout code
48+
uses: actions/checkout@v3
49+
with:
50+
submodules: true
51+
# TODO(Samarth): Do we need to propagate this to other `repos/workflow`
52+
# make it a default behavior? For certain tests to pass, we need entire
53+
# commit history of the repo including sub-modules.
54+
fetch-depth: 0
55+
token: ${{ secrets.GH_ACTION_ACCESS_TOKEN }}
56+
57+
# To see the modules in `helpers_root`, PYTHONPATH needs to include
58+
# `helpers_root` in the same way we do in `setenv.sh`.
59+
- name: Update PYTHONPATH
60+
run: echo "PYTHONPATH=.:helpers_root" >> $GITHUB_ENV
61+
62+
# Install packages that are required to run the job via GH.
63+
- name: Install dependencies
64+
run: |
65+
python -m pip install --upgrade pip
66+
pip install -r .github/gh_requirements.txt
67+
68+
# Pull the latest Docker image from the GHCR registry instead of ECR for
69+
# cost saving purposes to run the regressions on.
70+
- name: Pull image from GHCR
71+
run: docker pull ghcr.io/${{ github.repository }}:dev
72+
73+
# This step is used to trigger the fast test coverage generation using the invoke task.
74+
- name: Run Fast test and generate report
75+
id: run_fast
76+
continue-on-error: true
77+
env:
78+
GH_ACTION_ACCESS_TOKEN: ${{ secrets.GH_ACTION_ACCESS_TOKEN }}
79+
CSFY_AWS_ACCESS_KEY_ID: ${{ env.AWS_ACCESS_KEY_ID }}
80+
CSFY_AWS_SECRET_ACCESS_KEY: ${{ env.AWS_SECRET_ACCESS_KEY }}
81+
CSFY_AWS_SESSION_TOKEN: ${{ env.AWS_SESSION_TOKEN }}
82+
CSFY_AWS_DEFAULT_REGION: ${{ env.AWS_DEFAULT_REGION }}
83+
CSFY_ECR_BASE_PATH: ghcr.io/${{ github.repository_owner }}
84+
CSFY_AWS_S3_BUCKET: ${{ vars.CSFY_AWS_S3_BUCKET }}
85+
run: invoke run_coverage --suite fast
86+
87+
- name: Upload Fast Test Coverage to Codecov
88+
id: upload_fast
89+
# Only upload if the previous fast test run step succeeded (i.r report generated).
90+
# failed step don’t generate a coverage report, so there's nothing to upload.
91+
if: steps.run_fast.outcome == 'success'
92+
continue-on-error: true
93+
uses: codecov/codecov-action@v5
94+
with:
95+
token: ${{ secrets.CODECOV_TOKEN }}
96+
files: ./coverage.xml
97+
# Specify the Codecov flag name associated with this test suite.
98+
# Required to separate coverage reports by type (e.g., fast, slow, superslow) inside the Codecov UI.
99+
flags: fast
100+
name: fast-test-coverage
101+
102+
- name: Run Slow test and generate report
103+
id: run_slow
104+
continue-on-error: true
105+
env:
106+
GH_ACTION_ACCESS_TOKEN: ${{ secrets.GH_ACTION_ACCESS_TOKEN }}
107+
CSFY_AWS_ACCESS_KEY_ID: ${{ env.AWS_ACCESS_KEY_ID }}
108+
CSFY_AWS_SECRET_ACCESS_KEY: ${{ env.AWS_SECRET_ACCESS_KEY }}
109+
CSFY_AWS_SESSION_TOKEN: ${{ env.AWS_SESSION_TOKEN }}
110+
CSFY_AWS_DEFAULT_REGION: ${{ env.AWS_DEFAULT_REGION }}
111+
CSFY_ECR_BASE_PATH: ghcr.io/${{ github.repository_owner }}
112+
CSFY_AWS_S3_BUCKET: ${{ vars.CSFY_AWS_S3_BUCKET }}
113+
run: invoke run_coverage --suite slow
114+
115+
- name: Upload Slow Test Coverage to Codecov
116+
id: upload_slow
117+
# Only upload if the previous slow test run step succeeded (i.e, if report generated).
118+
if: steps.run_slow.outcome == 'success'
119+
continue-on-error: true
120+
uses: codecov/codecov-action@v5
121+
with:
122+
token: ${{ secrets.CODECOV_TOKEN }}
123+
files: ./coverage.xml
124+
flags: slow
125+
name: slow-test-coverage
126+
127+
- name: Run Superslow test and generate report
128+
id: run_superslow
129+
env:
130+
GH_ACTION_ACCESS_TOKEN: ${{ secrets.GH_ACTION_ACCESS_TOKEN }}
131+
CSFY_AWS_ACCESS_KEY_ID: ${{ env.AWS_ACCESS_KEY_ID }}
132+
CSFY_AWS_SECRET_ACCESS_KEY: ${{ env.AWS_SECRET_ACCESS_KEY }}
133+
CSFY_AWS_SESSION_TOKEN: ${{ env.AWS_SESSION_TOKEN }}
134+
CSFY_AWS_DEFAULT_REGION: ${{ env.AWS_DEFAULT_REGION }}
135+
CSFY_ECR_BASE_PATH: ghcr.io/${{ github.repository_owner }}
136+
CSFY_AWS_S3_BUCKET: ${{ vars.CSFY_AWS_S3_BUCKET }}
137+
run: |
138+
# Determine the day of the week (1 = Monday, 7 = Sunday).
139+
day_of_week=$(date +%u)
140+
# Only run superslow tests on Mondays or if the workflow is manually triggered.
141+
if [ "$day_of_week" = "1" ] || [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
142+
echo "Running superslow tests..."
143+
invoke run_coverage --suite superslow
144+
else
145+
echo "Skipping superslow tests — today is not Monday and this is not a manual trigger"
146+
exit 0
147+
fi
148+
149+
- name: Upload Superslow Test Coverage to Codecov
150+
#TODO(Shaunak): Consider removing it when we turn this workflow into a reusable one.
151+
if: steps.run_superslow.outcome == 'success'
152+
uses: codecov/codecov-action@v5
153+
with:
154+
token: ${{ secrets.CODECOV_TOKEN }}
155+
files: ./coverage.xml
156+
flags: superslow
157+
name: superslow-test-coverage
158+
159+
# Fail the job in CI if any of the fast/ slow run/ upload steps above failed.
160+
- name: Fail if fast/slow test or upload failed
161+
run: |
162+
failed=""
163+
if [ "${{ steps.run_fast.outcome }}" != "success" ]; then
164+
echo "Fast test run failed"
165+
failed="true"
166+
fi
167+
if [ "${{ steps.upload_fast.outcome }}" != "success" ]; then
168+
echo "Fast test coverage upload failed"
169+
failed="true"
170+
fi
171+
if [ "${{ steps.run_slow.outcome }}" != "success" ]; then
172+
echo "Slow test run failed"
173+
failed="true"
174+
fi
175+
if [ "${{ steps.upload_slow.outcome }}" != "success" ]; then
176+
echo "Slow test coverage upload failed"
177+
failed="true"
178+
fi
179+
if [ "$failed" = "true" ]; then
180+
echo "At least one fast/slow test or upload step failed."
181+
exit 1
182+
fi

helpers_root

0 commit comments

Comments
 (0)