Skip to content

Commit cfdb131

Browse files
authored
Merge pull request #2104 from codeflash-ai/ci/use-shared-workflows
Use shared workflows for change detection, prek, and gate job
2 parents 5c0c90d + c613fda commit cfdb131

1 file changed

Lines changed: 27 additions & 119 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 27 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -83,87 +83,26 @@ jobs:
8383
# ---------------------------------------------------------------------------
8484
# Change detection — decides which downstream jobs actually run.
8585
# On push/workflow_dispatch every flag is true so all jobs execute.
86-
# On pull_request we diff against the merge base (same approach as astral-sh/ruff).
86+
# On pull_request we diff against the merge base.
8787
# ---------------------------------------------------------------------------
8888
determine-changes:
89-
runs-on: ubuntu-latest
90-
permissions:
91-
contents: read
92-
outputs:
93-
unit_tests: ${{ github.event_name != 'pull_request' || steps.check.outputs.unit_tests == 'true' }}
94-
type_check: ${{ github.event_name != 'pull_request' || steps.check.outputs.type_check == 'true' }}
95-
e2e: ${{ github.event_name != 'pull_request' || steps.check.outputs.e2e == 'true' }}
96-
e2e_js: ${{ github.event_name != 'pull_request' || steps.check.outputs.e2e_js == 'true' }}
97-
e2e_java: ${{ github.event_name != 'pull_request' || steps.check.outputs.e2e_java == 'true' }}
98-
steps:
99-
- uses: actions/checkout@v6
100-
if: github.event_name == 'pull_request'
101-
with:
102-
fetch-depth: 0
103-
104-
- name: Determine merge base
105-
if: github.event_name == 'pull_request'
106-
id: merge_base
107-
run: |
108-
sha=$(git merge-base HEAD "origin/${{ github.event.pull_request.base.ref }}")
109-
echo "sha=${sha}" >> "$GITHUB_OUTPUT"
110-
111-
- name: Check changed paths
112-
if: github.event_name == 'pull_request'
113-
id: check
114-
run: |
115-
check_paths() {
116-
local name="$1"; shift
117-
if ! git diff --quiet "$MERGE_BASE...HEAD" -- "$@" 2>/dev/null; then
118-
echo "${name}=true" >> "$GITHUB_OUTPUT"
119-
else
120-
echo "${name}=false" >> "$GITHUB_OUTPUT"
121-
fi
122-
}
123-
124-
# Unit tests: code + test infra + packages + build config
125-
check_paths unit_tests \
126-
'codeflash/' 'codeflash-benchmark/' \
127-
'tests/' 'packages/' 'pyproject.toml' 'uv.lock'
128-
129-
# Type checking: code + build config + mypy config
130-
check_paths type_check \
131-
'codeflash/' 'pyproject.toml' 'uv.lock' 'mypy_allowlist.txt'
132-
133-
# E2E tests: Python pipeline + tests + build config (excludes java/ and javascript/)
134-
check_paths e2e \
135-
'codeflash/*.py' \
136-
'codeflash/api/' 'codeflash/benchmarking/' 'codeflash/cli_cmds/' \
137-
'codeflash/code_utils/' 'codeflash/discovery/' 'codeflash/github/' \
138-
'codeflash/languages/python/' 'codeflash/languages/*.py' \
139-
'codeflash/lsp/' 'codeflash/models/' 'codeflash/optimization/' \
140-
'codeflash/picklepatch/' 'codeflash/result/' 'codeflash/setup/' \
141-
'codeflash/telemetry/' 'codeflash/tracing/' 'codeflash/verification/' \
142-
'tests/' 'pyproject.toml' 'uv.lock'
143-
144-
# JS E2E tests: JS language support + shared pipeline + packages + test fixtures
145-
check_paths e2e_js \
146-
'codeflash/languages/javascript/' 'codeflash/languages/base.py' \
147-
'codeflash/languages/registry.py' 'codeflash/optimization/' \
148-
'codeflash/verification/' 'packages/' \
149-
'code_to_optimize/js/' 'tests/scripts/end_to_end_test_js*'
150-
151-
# Java E2E tests: Java language support + shared pipeline + runtime
152-
check_paths e2e_java \
153-
'codeflash/languages/java/' 'codeflash/languages/base.py' \
154-
'codeflash/languages/registry.py' 'codeflash/optimization/' \
155-
'codeflash/verification/' 'codeflash-java-runtime/' \
156-
'code_to_optimize/java/' 'tests/scripts/end_to_end_test_java*' \
157-
'tests/test_languages/fixtures/java_tracer_e2e/'
158-
env:
159-
MERGE_BASE: ${{ steps.merge_base.outputs.sha }}
89+
uses: codeflash-ai/github-workflows/.github/workflows/determine-changes.yml@main
90+
with:
91+
path-filters: |
92+
{
93+
"unit_tests": ["codeflash/", "codeflash-benchmark/", "tests/", "packages/", "pyproject.toml", "uv.lock"],
94+
"type_check": ["codeflash/", "pyproject.toml", "uv.lock", "mypy_allowlist.txt"],
95+
"e2e": ["codeflash/*.py", "codeflash/api/", "codeflash/benchmarking/", "codeflash/cli_cmds/", "codeflash/code_utils/", "codeflash/discovery/", "codeflash/github/", "codeflash/languages/python/", "codeflash/languages/*.py", "codeflash/lsp/", "codeflash/models/", "codeflash/optimization/", "codeflash/picklepatch/", "codeflash/result/", "codeflash/setup/", "codeflash/telemetry/", "codeflash/tracing/", "codeflash/verification/", "tests/", "pyproject.toml", "uv.lock"],
96+
"e2e_js": ["codeflash/languages/javascript/", "codeflash/languages/base.py", "codeflash/languages/registry.py", "codeflash/optimization/", "codeflash/verification/", "packages/", "code_to_optimize/js/", "tests/scripts/end_to_end_test_js*"],
97+
"e2e_java": ["codeflash/languages/java/", "codeflash/languages/base.py", "codeflash/languages/registry.py", "codeflash/optimization/", "codeflash/verification/", "codeflash-java-runtime/", "code_to_optimize/java/", "tests/scripts/end_to_end_test_java*", "tests/test_languages/fixtures/java_tracer_e2e/"]
98+
}
16099
161100
# ---------------------------------------------------------------------------
162101
# Unit tests — 6 Linux + 1 Windows matrix
163102
# ---------------------------------------------------------------------------
164103
unit-tests:
165104
needs: determine-changes
166-
if: needs.determine-changes.outputs.unit_tests == 'true'
105+
if: fromJSON(needs.determine-changes.outputs.flags).unit_tests == 'true'
167106
strategy:
168107
fail-fast: false
169108
matrix:
@@ -214,7 +153,7 @@ jobs:
214153
# ---------------------------------------------------------------------------
215154
coverage:
216155
needs: determine-changes
217-
if: needs.determine-changes.outputs.unit_tests == 'true'
156+
if: fromJSON(needs.determine-changes.outputs.flags).unit_tests == 'true'
218157
runs-on: ubuntu-latest
219158
env:
220159
PYTHONIOENCODING: utf-8
@@ -252,7 +191,7 @@ jobs:
252191
# ---------------------------------------------------------------------------
253192
type-check:
254193
needs: determine-changes
255-
if: needs.determine-changes.outputs.type_check == 'true'
194+
if: fromJSON(needs.determine-changes.outputs.flags).type_check == 'true'
256195
runs-on: ubuntu-latest
257196
steps:
258197
- uses: actions/checkout@v6
@@ -278,39 +217,15 @@ jobs:
278217
needs: determine-changes
279218
if: >-
280219
github.event_name == 'pull_request'
281-
&& (needs.determine-changes.outputs.e2e == 'true'
282-
|| needs.determine-changes.outputs.e2e_js == 'true')
283-
runs-on: ubuntu-latest
220+
&& (fromJSON(needs.determine-changes.outputs.flags).e2e == 'true'
221+
|| fromJSON(needs.determine-changes.outputs.flags).e2e_js == 'true')
222+
uses: codeflash-ai/github-workflows/.github/workflows/prek-lint.yml@main
284223
permissions:
285224
contents: write
286-
steps:
287-
- uses: actions/checkout@v6
288-
with:
289-
ref: ${{ github.head_ref }}
290-
fetch-depth: 0
291-
- uses: astral-sh/setup-uv@v8.1.0
292-
with:
293-
enable-cache: true
294-
295-
- name: Auto-fix formatting
296-
run: |
297-
uv run ruff check --fix . || true
298-
uv run ruff format .
299-
# uv-dynamic-versioning rewrites version.py on every `uv run` — discard those changes
300-
git checkout HEAD -- codeflash/version.py codeflash-benchmark/codeflash_benchmark/version.py 2>/dev/null || true
301-
302-
- name: Commit and push fixes
303-
run: |
304-
git diff --quiet && exit 0
305-
git config user.name "github-actions[bot]"
306-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
307-
git add -u
308-
git commit -m "style: auto-format with ruff"
309-
git push
310-
311-
- uses: j178/prek-action@v2
312-
with:
313-
extra-args: '--from-ref origin/${{ github.base_ref }} --to-ref HEAD'
225+
with:
226+
auto-fix: true
227+
checkout-ref: ${{ github.head_ref }}
228+
restore-paths: "codeflash/version.py codeflash-benchmark/codeflash_benchmark/version.py"
314229

315230
# ---------------------------------------------------------------------------
316231
# E2E tests — only on pull_request and workflow_dispatch (not push to main)
@@ -320,7 +235,7 @@ jobs:
320235
e2e-python:
321236
needs: determine-changes
322237
if: >-
323-
needs.determine-changes.outputs.e2e == 'true'
238+
fromJSON(needs.determine-changes.outputs.flags).e2e == 'true'
324239
&& github.event_name != 'push'
325240
&& github.actor != 'dependabot[bot]'
326241
strategy:
@@ -424,7 +339,7 @@ jobs:
424339
e2e-js:
425340
needs: determine-changes
426341
if: >-
427-
needs.determine-changes.outputs.e2e_js == 'true'
342+
fromJSON(needs.determine-changes.outputs.flags).e2e_js == 'true'
428343
&& github.event_name != 'push'
429344
&& github.actor != 'dependabot[bot]'
430345
strategy:
@@ -508,7 +423,7 @@ jobs:
508423
e2e-java:
509424
needs: determine-changes
510425
if: >-
511-
needs.determine-changes.outputs.e2e_java == 'true'
426+
fromJSON(needs.determine-changes.outputs.flags).e2e_java == 'true'
512427
&& github.event_name != 'push'
513428
&& github.actor != 'dependabot[bot]'
514429
strategy:
@@ -617,13 +532,6 @@ jobs:
617532
- e2e-java
618533
runs-on: ubuntu-latest
619534
steps:
620-
- name: Verify all required jobs passed
621-
run: |
622-
failing=$(echo "$NEEDS_JSON" | jq -r 'to_entries[] | select(.value.result != "success" and .value.result != "skipped") | "\(.key): \(.value.result)"')
623-
if [ -n "$failing" ]; then
624-
echo "Required jobs failed or were cancelled:"
625-
echo "$failing"
626-
exit 1
627-
fi
628-
env:
629-
NEEDS_JSON: ${{ toJSON(needs) }}
535+
- uses: codeflash-ai/github-workflows/.github/actions/required-checks-gate@main
536+
with:
537+
needs-json: ${{ toJSON(needs) }}

0 commit comments

Comments
 (0)