Repository navigation
152 lines (129 loc) · 4.87 KB
/
Copy pathpr_validation.yml
File metadata and controls
152 lines (129 loc) · 4.87 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
name: Pull Request Data Validation
on:
pull_request:
branches: [develop]
permissions:
contents: read
jobs:
static_checks:
name: Static Checks (Lint & dbt Parse)
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: |
requirements.txt
requirements-dev.txt
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- name: Lint YAML Files
run: yamllint --strict .
- name: Lint & Format Check Python Scripts
run: |
ruff check .
ruff format --check .
- name: Lint SQL Models
run: |
sqlfluff lint models/
if [ -d tests ]; then
sqlfluff lint tests/
fi
- name: Parse dbt Project Offline
run: |
cat << 'EOF' > profiles.yml
oppia_analytics:
target: dev
outputs:
dev:
type: bigquery
method: oauth
project: oppia-analytics-test
dataset: dev_github_actions
threads: 4
timeout_seconds: 300
location: US
EOF
dbt deps --profiles-dir .
dbt parse --profiles-dir .
- name: Run Python Unit Tests (100% Coverage)
run: |
coverage run -m unittest discover -s scripts -v
coverage report
- name: Check dbt Test, Doc & DAG Coverage
run: python3 scripts/check_dbt_coverage.py
bigquery_build:
name: BigQuery Build & Test
needs: static_checks
# Dependabot PRs cannot mint GitHub OIDC tokens, so skip BigQuery build for Dependabot
# (Static Checks still verifies installs, linting, and dbt parse). Fork PRs still enter
# this job and fail cleanly at the first step so unvalidated fork PRs cannot be merged.
if: github.actor != 'dependabot[bot]' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
concurrency:
# Serialize PR runs against the shared dev_github_actions dataset without canceling queued PRs
group: pr-bigquery-test
cancel-in-progress: false
steps:
- name: Check PR Source Branch
if: github.event.pull_request.head.repo.full_name != github.repository
run: |
cat << 'EOF' >> "$GITHUB_STEP_SUMMARY"
### BigQuery Build Blocked (Fork PR)
GitHub withholds cloud credentials from pull requests opened from forks, so **BigQuery Build & Test** cannot run here.
Please push your feature branch directly to `oppia/analytics-data-platform` and reopen the pull request from that branch (see `CONTRIBUTING.md`).
EOF
echo "::error::Pull requests from forks cannot run BigQuery CI. Push your branch directly to oppia/analytics-data-platform and reopen the PR from there (see CONTRIBUTING.md)."
exit 1
- name: Checkout Code
uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: requirements.txt
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
# Authenticate via GCP Workload Identity Federation (no static JSON keys).
# Sets GOOGLE_APPLICATION_CREDENTIALS, which dbt's 'method: oauth' picks up via ADC.
- name: Authenticate to Google Cloud (WIF)
uses: google-github-actions/auth@v3
with:
project_id: oppia-analytics-test
workload_identity_provider: ${{ secrets.GCP_TEST_WIF_PROVIDER }}
service_account: ${{ secrets.GCP_TEST_SERVICE_ACCOUNT }}
- name: Create dynamic profiles.yml for dbt
run: |
cat << 'EOF' > profiles.yml
oppia_analytics:
target: dev
outputs:
dev:
type: bigquery
method: oauth
project: oppia-analytics-test
dataset: dev_github_actions
threads: 4
timeout_seconds: 300
location: US
EOF
- name: Verify dbt Connection
run: dbt debug --profiles-dir .
- name: Install dbt Packages (if any)
run: dbt deps --profiles-dir .
- name: Build and Test Models
# Full-refresh on the shared CI dataset ensures schema/partition changes build cleanly,
# and dbt build runs unit tests, builds each model, then runs data tests immediately.
run: dbt build --full-refresh --profiles-dir .