Add codeflash optimization workflow for cf-api and cf-webapp (#2411)

Co-authored-by: Kevin Turcios <106575910+KRRT7@users.noreply.github.com>
This commit is contained in:
Sarthak Agarwal 2026-02-16 19:48:15 +05:30 committed by GitHub
parent 38eda0c2d6
commit e22e5d1f8b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 169 additions and 0 deletions

160
.github/workflows/codeflash-js.yaml vendored Normal file
View file

@ -0,0 +1,160 @@
name: Codeflash JS/TS Optimization
on:
pull_request:
paths:
- "js/cf-api/**"
- "js/cf-webapp/**"
workflow_dispatch:
inputs:
project:
description: 'Project to optimize (cf-api, cf-webapp, or both)'
required: false
default: 'both'
type: choice
options:
- both
- cf-api
- cf-webapp
permissions:
contents: read
pull-requests: read
checks: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# Check which projects have changes
check-changes:
runs-on: ubuntu-latest
outputs:
cf-api: ${{ steps.filter.outputs.cf-api }}
cf-webapp: ${{ steps.filter.outputs.cf-webapp }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
cf-api:
- 'js/cf-api/**'
cf-webapp:
- 'js/cf-webapp/**'
# Skip job when no JS changes detected (only for pull_request events)
no-js-changes:
name: No JS/TS changes detected
needs: check-changes
if: |
github.event_name == 'pull_request'
&& needs.check-changes.outputs.cf-api != 'true'
&& needs.check-changes.outputs.cf-webapp != 'true'
runs-on: ubuntu-latest
steps:
- name: Skip optimization
run: echo "Skipping codeflash optimization - no changes in js/cf-api/ or js/cf-webapp/"
# Optimize cf-api (Jest)
optimize-cf-api:
needs: [check-changes]
if: |
(
needs.check-changes.outputs.cf-api == 'true'
|| github.event_name == 'workflow_dispatch' && (github.event.inputs.project == 'cf-api' || github.event.inputs.project == 'both')
)
&& github.actor != 'codeflash-ai[bot]'
name: Optimize cf-api
runs-on: ubuntu-latest
env:
CODEFLASH_API_KEY: ${{ secrets.CODEFLASH_API_KEY }}
CODEFLASH_PR_NUMBER: ${{ github.event.number }}
COLUMNS: 110
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: js/cf-api/package-lock.json
- name: Install cf-api dependencies
working-directory: js/cf-api
run: npm ci
- name: Install jest-junit for test reporting
working-directory: js/cf-api
run: npm install --save-dev jest-junit
- name: Set up Python and install Codeflash
uses: astral-sh/setup-uv@v7
with:
python-version: "3.12"
- name: Install Codeflash CLI
run: |
uv tool install git+https://github.com/codeflash-ai/codeflash@main
- name: Run Codeflash optimization
working-directory: js/cf-api
run: |
export PATH="$HOME/.local/bin:$PATH"
codeflash --all --verbose --yes
# Optimize cf-webapp (Vitest)
optimize-cf-webapp:
needs: [check-changes]
if: |
(
needs.check-changes.outputs.cf-webapp == 'true'
|| github.event_name == 'workflow_dispatch' && (github.event.inputs.project == 'cf-webapp' || github.event.inputs.project == 'both')
)
&& github.actor != 'codeflash-ai[bot]'
name: Optimize cf-webapp
runs-on: ubuntu-latest
env:
CODEFLASH_API_KEY: ${{ secrets.CODEFLASH_API_KEY }}
CODEFLASH_PR_NUMBER: ${{ github.event.number }}
COLUMNS: 110
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: js/cf-webapp/package-lock.json
- name: Install cf-webapp dependencies
working-directory: js/cf-webapp
run: npm ci
- name: Set up Python and install Codeflash
uses: astral-sh/setup-uv@v7
with:
python-version: "3.12"
- name: Install Codeflash CLI
run: |
uv tool install git+https://github.com/codeflash-ai/codeflash@main
- name: Run Codeflash optimization
working-directory: js/cf-webapp
run: |
export PATH="$HOME/.local/bin:$PATH"
codeflash --all --verbose --yes

View file

@ -92,5 +92,14 @@
"**/*.{json,md}": [
"prettier --write"
]
},
"codeflash": {
"testsRoot": "test",
"formatterCmds": [
"npx prettier --write $file"
],
"ignorePaths": [
"node_modules"
]
}
}