Skip to content

Commit 61f468a

Browse files
authored
ci: batch CI improvements — paths, validate-pr action, test skips, fetch-depth
ci: consolidate improvements — paths, validate-pr action, fetch-depth, continue-on-error
2 parents f658fc5 + 65b117c commit 61f468a

5 files changed

Lines changed: 118 additions & 82 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Validate PR
2+
description: Ensure only authorized users can modify workflow files in PRs
3+
inputs:
4+
base_sha:
5+
description: Base commit SHA of the pull request
6+
required: true
7+
head_sha:
8+
description: Head commit SHA of the pull request
9+
required: true
10+
author:
11+
description: Login of the PR author
12+
required: true
13+
pr_state:
14+
description: State of the pull request (open/closed)
15+
required: true
16+
runs:
17+
using: composite
18+
steps:
19+
- name: Check workflow file changes
20+
shell: bash
21+
run: |
22+
if git diff --name-only "${{ inputs.base_sha }}" "${{ inputs.head_sha }}" | grep -q "^.github/workflows/"; then
23+
echo "Workflow changes detected."
24+
AUTHOR="${{ inputs.author }}"
25+
if [[ "$AUTHOR" == "misrasaurabh1" || "$AUTHOR" == "KRRT7" ]]; then
26+
echo "Authorized user ($AUTHOR). Proceeding."
27+
elif [[ "${{ inputs.pr_state }}" == "open" ]]; then
28+
echo "PR is open. Protection rules in place. Proceeding."
29+
else
30+
echo "Unauthorized user ($AUTHOR). Exiting."
31+
exit 1
32+
fi
33+
else
34+
echo "No workflow file changes. Proceeding."
35+
fi

.github/workflows/ci.yaml

Lines changed: 63 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -61,26 +61,39 @@ jobs:
6161
fi
6262
}
6363
64-
# Unit tests: code + test infra + java + packages + build config
64+
# Unit tests: code + test infra + packages + build config
6565
check_paths unit_tests \
66-
'codeflash/' 'codeflash-benchmark/' 'codeflash-java-runtime/' \
66+
'codeflash/' 'codeflash-benchmark/' \
6767
'tests/' 'packages/' 'pyproject.toml' 'uv.lock'
6868
6969
# Type checking: code + build config + mypy config
7070
check_paths type_check \
7171
'codeflash/' 'pyproject.toml' 'uv.lock' 'mypy_allowlist.txt'
7272
73-
# E2E tests: code + tests + build config
73+
# E2E tests: Python pipeline + tests + build config (excludes java/ and javascript/)
7474
check_paths e2e \
75-
'codeflash/' 'tests/' 'pyproject.toml' 'uv.lock'
76-
77-
# JS E2E tests: JS packages changed
75+
'codeflash/*.py' \
76+
'codeflash/api/' 'codeflash/benchmarking/' 'codeflash/cli_cmds/' \
77+
'codeflash/code_utils/' 'codeflash/discovery/' 'codeflash/github/' \
78+
'codeflash/languages/python/' 'codeflash/languages/*.py' \
79+
'codeflash/lsp/' 'codeflash/models/' 'codeflash/optimization/' \
80+
'codeflash/picklepatch/' 'codeflash/result/' 'codeflash/setup/' \
81+
'codeflash/telemetry/' 'codeflash/tracing/' 'codeflash/verification/' \
82+
'tests/' 'pyproject.toml' 'uv.lock'
83+
84+
# JS E2E tests: JS language support + shared pipeline + packages
7885
check_paths e2e_js \
79-
'packages/'
86+
'codeflash/languages/javascript/' 'codeflash/languages/base.py' \
87+
'codeflash/languages/registry.py' 'codeflash/optimization/' \
88+
'codeflash/verification/' 'packages/' \
89+
'tests/scripts/end_to_end_test_js*'
8090
81-
# Java E2E tests: java runtime or java test fixtures changed
91+
# Java E2E tests: Java language support + shared pipeline + runtime
8292
check_paths e2e_java \
83-
'codeflash-java-runtime/' 'code_to_optimize/java/'
93+
'codeflash/languages/java/' 'codeflash/languages/base.py' \
94+
'codeflash/languages/registry.py' 'codeflash/optimization/' \
95+
'codeflash/verification/' 'codeflash-java-runtime/' \
96+
'code_to_optimize/java/' 'tests/scripts/end_to_end_test_java*'
8497
env:
8598
MERGE_BASE: ${{ steps.merge_base.outputs.sha }}
8699

@@ -108,29 +121,15 @@ jobs:
108121
python-version: "3.14"
109122
- os: windows-latest
110123
python-version: "3.13"
111-
continue-on-error: true
112124
runs-on: ${{ matrix.os }}
113125
env:
114126
PYTHONIOENCODING: utf-8
115127
steps:
116128
- uses: actions/checkout@v4
117129
with:
118-
fetch-depth: 0
130+
fetch-depth: 1
119131
token: ${{ secrets.GITHUB_TOKEN }}
120132

121-
- name: Set up JDK 11
122-
uses: actions/setup-java@v4
123-
with:
124-
java-version: '11'
125-
distribution: 'temurin'
126-
cache: maven
127-
128-
- name: Build codeflash-runtime JAR
129-
run: |
130-
cd codeflash-java-runtime
131-
mvn clean package -q -DskipTests
132-
mvn install -q -DskipTests
133-
134133
- name: Install uv
135134
uses: astral-sh/setup-uv@v8.0.0
136135
with:
@@ -156,7 +155,7 @@ jobs:
156155
steps:
157156
- uses: actions/checkout@v4
158157
with:
159-
fetch-depth: 0
158+
fetch-depth: 1
160159
token: ${{ secrets.GITHUB_TOKEN }}
161160

162161
- name: Install uv
@@ -180,14 +179,32 @@ jobs:
180179
&& (needs.determine-changes.outputs.e2e == 'true'
181180
|| needs.determine-changes.outputs.e2e_js == 'true')
182181
runs-on: ubuntu-latest
182+
permissions:
183+
contents: write
183184
steps:
184185
- uses: actions/checkout@v4
185186
with:
187+
ref: ${{ github.head_ref }}
186188
fetch-depth: 0
187189
- uses: astral-sh/setup-uv@v8.0.0
190+
191+
- name: Auto-fix formatting
192+
run: |
193+
uv run ruff check --fix . || true
194+
uv run ruff format .
195+
196+
- name: Commit and push fixes
197+
run: |
198+
git diff --quiet && exit 0
199+
git config user.name "github-actions[bot]"
200+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
201+
git add -u
202+
git commit -m "style: auto-format with ruff"
203+
git push
204+
188205
- uses: j178/prek-action@v1
189206
with:
190-
extra-args: '--from-ref origin/${{ github.base_ref }} --to-ref ${{ github.sha }}'
207+
extra-args: '--from-ref origin/${{ github.base_ref }} --to-ref HEAD'
191208

192209
# ---------------------------------------------------------------------------
193210
# E2E tests — only on pull_request and workflow_dispatch (not push to main)
@@ -231,7 +248,6 @@ jobs:
231248
- name: init-optimization
232249
script: end_to_end_test_init_optimization.py
233250
expected_improvement: 10
234-
name: ${{ matrix.name }}
235251
environment: ${{ (github.event_name == 'workflow_dispatch' || (contains(toJSON(github.event.pull_request.files.*.filename), '.github/workflows/') && github.event.pull_request.user.login != 'misrasaurabh1' && github.event.pull_request.user.login != 'KRRT7')) && 'external-trusted-contributors' || '' }}
236252
runs-on: ubuntu-latest
237253
env:
@@ -251,21 +267,12 @@ jobs:
251267

252268
- name: Validate PR
253269
if: github.event_name == 'pull_request'
254-
run: |
255-
if git diff --name-only "${{ github.event.pull_request.base.sha }}" "${{ github.event.pull_request.head.sha }}" | grep -q "^.github/workflows/"; then
256-
echo "Workflow changes detected."
257-
AUTHOR="${{ github.event.pull_request.user.login }}"
258-
if [[ "$AUTHOR" == "misrasaurabh1" || "$AUTHOR" == "KRRT7" ]]; then
259-
echo "Authorized user ($AUTHOR). Proceeding."
260-
elif [[ "${{ github.event.pull_request.state }}" == "open" ]]; then
261-
echo "PR is open. Protection rules in place. Proceeding."
262-
else
263-
echo "Unauthorized user ($AUTHOR). Exiting."
264-
exit 1
265-
fi
266-
else
267-
echo "No workflow file changes. Proceeding."
268-
fi
270+
uses: ./.github/actions/validate-pr
271+
with:
272+
base_sha: ${{ github.event.pull_request.base.sha }}
273+
head_sha: ${{ github.event.pull_request.head.sha }}
274+
author: ${{ github.event.pull_request.user.login }}
275+
pr_state: ${{ github.event.pull_request.state }}
269276

270277
- name: Install uv
271278
uses: astral-sh/setup-uv@v8.0.0
@@ -309,8 +316,7 @@ jobs:
309316
e2e-js:
310317
needs: determine-changes
311318
if: >-
312-
(needs.determine-changes.outputs.e2e == 'true'
313-
|| needs.determine-changes.outputs.e2e_js == 'true')
319+
needs.determine-changes.outputs.e2e_js == 'true'
314320
&& github.event_name != 'push'
315321
strategy:
316322
fail-fast: false
@@ -328,7 +334,6 @@ jobs:
328334
script: end_to_end_test_js_ts_class.py
329335
js_project_dir: code_to_optimize/js/code_to_optimize_ts
330336
expected_improvement: 30
331-
name: ${{ matrix.name }}
332337
environment: ${{ (github.event_name == 'workflow_dispatch' || (contains(toJSON(github.event.pull_request.files.*.filename), '.github/workflows/') && github.event.pull_request.user.login != 'misrasaurabh1' && github.event.pull_request.user.login != 'KRRT7')) && 'external-trusted-contributors' || '' }}
333338
runs-on: ubuntu-latest
334339
env:
@@ -350,21 +355,12 @@ jobs:
350355

351356
- name: Validate PR
352357
if: github.event_name == 'pull_request'
353-
run: |
354-
if git diff --name-only "${{ github.event.pull_request.base.sha }}" "${{ github.event.pull_request.head.sha }}" | grep -q "^.github/workflows/"; then
355-
echo "Workflow changes detected."
356-
AUTHOR="${{ github.event.pull_request.user.login }}"
357-
if [[ "$AUTHOR" == "misrasaurabh1" || "$AUTHOR" == "KRRT7" ]]; then
358-
echo "Authorized user ($AUTHOR). Proceeding."
359-
elif [[ "${{ github.event.pull_request.state }}" == "open" ]]; then
360-
echo "PR is open. Protection rules in place. Proceeding."
361-
else
362-
echo "Unauthorized user ($AUTHOR). Exiting."
363-
exit 1
364-
fi
365-
else
366-
echo "No workflow file changes. Proceeding."
367-
fi
358+
uses: ./.github/actions/validate-pr
359+
with:
360+
base_sha: ${{ github.event.pull_request.base.sha }}
361+
head_sha: ${{ github.event.pull_request.head.sha }}
362+
author: ${{ github.event.pull_request.user.login }}
363+
pr_state: ${{ github.event.pull_request.state }}
368364

369365
- name: Set up Node.js
370366
uses: actions/setup-node@v4
@@ -396,8 +392,7 @@ jobs:
396392
e2e-java:
397393
needs: determine-changes
398394
if: >-
399-
(needs.determine-changes.outputs.e2e == 'true'
400-
|| needs.determine-changes.outputs.e2e_java == 'true')
395+
needs.determine-changes.outputs.e2e_java == 'true'
401396
&& github.event_name != 'push'
402397
strategy:
403398
fail-fast: false
@@ -414,7 +409,6 @@ jobs:
414409
script: end_to_end_test_java_void_optimization.py
415410
expected_improvement: 70
416411
remove_git: true
417-
name: ${{ matrix.name }}
418412
environment: ${{ (github.event_name == 'workflow_dispatch' || (contains(toJSON(github.event.pull_request.files.*.filename), '.github/workflows/') && github.event.pull_request.user.login != 'misrasaurabh1' && github.event.pull_request.user.login != 'KRRT7')) && 'external-trusted-contributors' || '' }}
419413
runs-on: ubuntu-latest
420414
env:
@@ -436,21 +430,12 @@ jobs:
436430

437431
- name: Validate PR
438432
if: github.event_name == 'pull_request'
439-
run: |
440-
if git diff --name-only "${{ github.event.pull_request.base.sha }}" "${{ github.event.pull_request.head.sha }}" | grep -q "^.github/workflows/"; then
441-
echo "Workflow changes detected."
442-
AUTHOR="${{ github.event.pull_request.user.login }}"
443-
if [[ "$AUTHOR" == "misrasaurabh1" || "$AUTHOR" == "KRRT7" ]]; then
444-
echo "Authorized user ($AUTHOR). Proceeding."
445-
elif [[ "${{ github.event.pull_request.state }}" == "open" ]]; then
446-
echo "PR is open. Protection rules in place. Proceeding."
447-
else
448-
echo "Unauthorized user ($AUTHOR). Exiting."
449-
exit 1
450-
fi
451-
else
452-
echo "No workflow file changes. Proceeding."
453-
fi
433+
uses: ./.github/actions/validate-pr
434+
with:
435+
base_sha: ${{ github.event.pull_request.base.sha }}
436+
head_sha: ${{ github.event.pull_request.head.sha }}
437+
author: ${{ github.event.pull_request.user.login }}
438+
pr_state: ${{ github.event.pull_request.state }}
454439

455440
- name: Set up JDK 11
456441
uses: actions/setup-java@v4
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# These version placeholders will be replaced by uv-dynamic-versioning during build.
2-
__version__ = "0.20.1.post242.dev0+7c7eeb5b"
2+
__version__ = "0.20.5.post146.dev0+5ff38597"

tests/test_languages/test_java/test_comparator.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@
66

77
import pytest
88

9-
from codeflash.languages.java.comparator import compare_invocations_directly, compare_test_results, values_equal
9+
from codeflash.languages.java.comparator import (
10+
_find_comparator_jar,
11+
compare_invocations_directly,
12+
compare_test_results,
13+
values_equal,
14+
)
1015
from codeflash.models.models import TestDiffScope
1116

12-
# Skip tests that require Java runtime if Java is not available
17+
# Skip tests that require the codeflash-runtime JAR (built by Maven from codeflash-java-runtime/)
1318
requires_java = pytest.mark.skipif(
14-
shutil.which("java") is None, reason="Java not found - skipping Comparator integration tests"
19+
_find_comparator_jar() is None,
20+
reason="codeflash-runtime JAR not found - skipping Comparator integration tests",
1521
)
1622

1723
# Kryo-serialized bytes for common test values.

tests/test_languages/test_java/test_run_and_parse.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313

1414
import pytest
1515

16+
from codeflash.languages.java.comparator import _find_comparator_jar
17+
18+
requires_java_runtime = pytest.mark.skipif(
19+
_find_comparator_jar() is None,
20+
reason="codeflash-runtime JAR not found - skipping Java integration tests",
21+
)
22+
1623
from codeflash.discovery.functions_to_optimize import FunctionToOptimize
1724
from codeflash.languages.base import Language
1825
from codeflash.languages.current import set_current_language
@@ -227,6 +234,7 @@ def _create_test_results_db(path: Path, results: list[dict]) -> None:
227234
"""
228235

229236

237+
@requires_java_runtime
230238
class TestJavaRunAndParseBehavior:
231239
def test_behavior_single_test_method(self, java_project):
232240
"""Full pipeline: instrument → run → parse with precise field assertions."""
@@ -369,6 +377,7 @@ def test_behavior_multiple_test_methods(self, java_project):
369377
assert "testAddPositive" in test_names
370378
assert "testAddZero" in test_names
371379

380+
@requires_java_runtime
372381
def test_behavior_return_value_correctness(self, tmp_path):
373382
"""Verify the Comparator JAR correctly identifies equivalent vs. differing results.
374383
@@ -405,6 +414,7 @@ def test_behavior_return_value_correctness(self, tmp_path):
405414
assert equivalent is False
406415

407416

417+
@requires_java_runtime
408418
class TestJavaRunAndParsePerformance:
409419
"""Tests that the performance instrumentation produces correct timing data.
410420

0 commit comments

Comments
 (0)