-
Notifications
You must be signed in to change notification settings - Fork 1
181 lines (156 loc) · 6.08 KB
/
ci.yml
File metadata and controls
181 lines (156 loc) · 6.08 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
name: CI
on:
push:
branches: ['*']
pull_request:
branches: [main]
permissions:
contents: read
env:
PYTHON_VERSION: "3.12"
jobs:
lint:
name: Code Quality (Ruff)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install ruff
run: pip install ruff
- name: Collect changed Python files
id: changed
run: |
python - <<'PY'
import json
import os
import subprocess
def collect_files(command):
result = subprocess.run(command, capture_output=True, check=False, text=True)
if result.returncode == 0:
return [line.strip() for line in result.stdout.splitlines() if line.strip()]
return None
event = os.environ["GITHUB_EVENT_NAME"]
if event == "pull_request":
with open(os.environ["GITHUB_EVENT_PATH"], encoding="utf-8") as fh:
payload = json.load(fh)
base_sha = payload["pull_request"]["base"]["sha"]
head_sha = payload["pull_request"]["head"]["sha"]
files = collect_files(["git", "diff", "--name-only", f"{base_sha}...{head_sha}", "--", "*.py"])
if files is None:
files = collect_files(["git", "diff", "--name-only", f"{base_sha}..{head_sha}", "--", "*.py"])
if files is None:
files = []
else:
has_parent = subprocess.run(
["git", "rev-parse", "--verify", "HEAD^"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
).returncode == 0
if has_parent:
files = collect_files(["git", "diff", "--name-only", "HEAD^", "HEAD", "--", "*.py"]) or []
else:
files = collect_files(["git", "ls-files", "*.py"]) or []
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as fh:
fh.write(f"files={json.dumps(files)}\n")
fh.write(f"count={len(files)}\n")
PY
- name: Run ruff check
if: steps.changed.outputs.count != '0'
run: ruff check ${{ join(fromJson(steps.changed.outputs.files), ' ') }}
- name: Run ruff format check
if: steps.changed.outputs.count != '0'
run: ruff format --check ${{ join(fromJson(steps.changed.outputs.files), ' ') }}
- name: Skip ruff when no Python files changed
if: steps.changed.outputs.count == '0'
run: echo "No Python file changes detected."
security:
name: Security Scanning (Bandit)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install bandit
run: pip install "bandit[toml]"
- name: Collect changed Python files
id: changed
run: |
python - <<'PY'
import json
import os
import subprocess
def collect_files(command):
result = subprocess.run(command, capture_output=True, check=False, text=True)
if result.returncode == 0:
return [line.strip() for line in result.stdout.splitlines() if line.strip()]
return None
event = os.environ["GITHUB_EVENT_NAME"]
if event == "pull_request":
with open(os.environ["GITHUB_EVENT_PATH"], encoding="utf-8") as fh:
payload = json.load(fh)
base_sha = payload["pull_request"]["base"]["sha"]
head_sha = payload["pull_request"]["head"]["sha"]
files = collect_files(["git", "diff", "--name-only", f"{base_sha}...{head_sha}", "--", "*.py"])
if files is None:
files = collect_files(["git", "diff", "--name-only", f"{base_sha}..{head_sha}", "--", "*.py"])
if files is None:
files = []
else:
has_parent = subprocess.run(
["git", "rev-parse", "--verify", "HEAD^"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
).returncode == 0
if has_parent:
files = collect_files(["git", "diff", "--name-only", "HEAD^", "HEAD", "--", "*.py"]) or []
else:
files = collect_files(["git", "ls-files", "*.py"]) or []
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as fh:
fh.write(f"files={json.dumps(files)}\n")
fh.write(f"count={len(files)}\n")
PY
- name: Run bandit security scan
if: steps.changed.outputs.count != '0'
run: bandit -c pyproject.toml ${{ join(fromJson(steps.changed.outputs.files), ' ') }}
- name: Skip bandit when no Python files changed
if: steps.changed.outputs.count == '0'
run: echo "No Python file changes detected."
test:
name: Beta Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Miniconda
uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
python-version: ${{ env.PYTHON_VERSION }}
activate-environment: BLOOM
environment-file: bloom_env.yaml
auto-activate-base: false
- name: Install bloom in editable mode
shell: bash -el {0}
run: |
pip install -e .
- name: Initialize local Bloom database
shell: bash -el {0}
run: |
bloom db init
- name: Run beta-critical tests
shell: bash -el {0}
run: |
pytest --no-cov \
tests/test_config_runtime.py \
tests/test_api_atlas_bridge.py \
tests/test_atlas_lookup_resilience.py \
tests/test_queue_flow.py \
tests/test_run_resolver.py