Skip to content

chore: bugbot

chore: bugbot #7901

Workflow file for this run

name: Code Quality checks
on:
pull_request:
branches: [main]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
# Detect which projects have changed
detect-changes:
uses: ./.github/workflows/_check-workspaces-changes.yaml
format:
needs: detect-changes
# Prevents running on the release-please branch
if: |
needs.detect-changes.outputs.package_react == 'true' &&
github.head_ref != 'release-please--branches--master' &&
!contains(github.event.pull_request.labels.*.name, 'autorelease')
name: Format
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-node-pnpm
- name: Check formatting
run: pnpm --filter @factorialco/f0-react run format:check
lint:
needs: detect-changes
# Prevents running on the release-please branch
if: |
needs.detect-changes.outputs.package_react == 'true' &&
github.head_ref != 'release-please--branches--master' &&
!contains(github.event.pull_request.labels.*.name, 'autorelease')
name: "[⚛️ REACT] Linting"
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
- uses: ./.github/actions/setup-node-pnpm
with:
node-version: "22.x"
cache: pnpm
- name: Install dependencies
run: pnpm install
- name: Build core package
run: pnpm --filter @factorialco/f0-core build
- name: Check linting with oxlint
run: pnpm --filter @factorialco/f0-react run lint
eslint-react-native:
needs: detect-changes
# Prevents running on the release-please branch
if: |
needs.detect-changes.outputs.package_react_native == 'true'
name: "[📱 REACT NATIVE] Eslint"
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
- uses: ./.github/actions/setup-node-pnpm
with:
node-version: "22.x"
cache: pnpm
- name: Install dependencies
run: pnpm install
- name: Build core package
run: pnpm --filter @factorialco/f0-core build
- name: Check linting with eslint
run: pnpm --filter @factorialco/f0-react-native run lint
- name: Check typescript
run: pnpm --filter @factorialco/f0-react-native exec tsc --noEmit
cycle-dependencies:
needs: detect-changes
# Prevents running on the release-please branch
if: |
needs.detect-changes.outputs.package_react == 'true' &&
github.head_ref != 'release-please--branches--master' &&
!contains(github.event.pull_request.labels.*.name, 'autorelease')
name: "[⚛️ REACT] Cycle Dependencies Check"
runs-on: ubuntu-22.04
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
- uses: ./.github/actions/setup-node-pnpm
with:
node-version: "22.x"
cache: pnpm
- name: Install dependencies
run: pnpm install
- name: Build core package
run: pnpm --filter @factorialco/f0-core build
- name: Get latest commit from main
id: main-commit
run: |
git fetch origin main:main || true
MAIN_COMMIT=$(git rev-parse origin/main 2>/dev/null || git rev-parse main)
echo "commit=$MAIN_COMMIT" >> $GITHUB_OUTPUT
echo "Main branch commit: $MAIN_COMMIT"
- name: Detect cycle dependencies and compare
id: compare
continue-on-error: true
run: |
cd packages/react
# Run the script and capture output
# The script may exit with 1 if new cycles are found, so we use continue-on-error
pnpm exec tsx .scripts/check-cycle-dependencies.ts --ci --json --compare-commit ${{ steps.main-commit.outputs.commit }} > /tmp/cycle-output.txt 2>&1 || true
# Extract JSON (find the last complete JSON object in the output)
# The script outputs multi-line JSON, so we need to extract from the last { to the end
# Find the line number where the last JSON object starts
LAST_JSON_LINE=$(grep -n '^{' /tmp/cycle-output.txt | tail -n 1 | cut -d: -f1)
if [ -z "$LAST_JSON_LINE" ]; then
echo "ERROR: No JSON output found in script output"
echo "Script output:"
cat /tmp/cycle-output.txt
exit 1
fi
# Extract from that line to the end of the file
sed -n "${LAST_JSON_LINE},\$p" /tmp/cycle-output.txt > /tmp/cycle-data-raw.json
# Use jq to parse and extract valid JSON
if ! jq . /tmp/cycle-data-raw.json > /tmp/cycle-data.json 2>/tmp/jq-error.txt; then
echo "ERROR: Failed to parse JSON output from cycle dependency check"
echo "Raw JSON extraction:"
cat /tmp/cycle-data-raw.json
echo ""
echo "jq error:"
cat /tmp/jq-error.txt
echo ""
echo "Full script output:"
cat /tmp/cycle-output.txt
exit 1
fi
# Verify JSON has the expected structure
if ! jq -e '.current.cycles >= 0' /tmp/cycle-data.json > /dev/null 2>&1; then
echo "ERROR: JSON output missing expected structure (current.cycles field)"
echo "Extracted JSON:"
cat /tmp/cycle-data.json
exit 1
fi
# Validate JSON and parse using jq
if jq empty /tmp/cycle-data.json 2>/dev/null; then
HAS_NEW_CYCLES=$(jq -r '.hasNewCycles // false' /tmp/cycle-data.json)
CYCLES_DECREASED=$(jq -r '.cyclesDecreased // false' /tmp/cycle-data.json)
CYCLES_REMOVED=$(jq -r '.cyclesRemoved // 0' /tmp/cycle-data.json)
BASELINE_COUNT=$(jq -r '.baseline.cycles // 0' /tmp/cycle-data.json)
CURRENT_COUNT=$(jq -r '.current.cycles // 0' /tmp/cycle-data.json)
echo "new_cycles_found=$HAS_NEW_CYCLES" >> $GITHUB_OUTPUT
echo "cycles_decreased=$CYCLES_DECREASED" >> $GITHUB_OUTPUT
echo "cycles_removed=$CYCLES_REMOVED" >> $GITHUB_OUTPUT
echo "baseline_count=$BASELINE_COUNT" >> $GITHUB_OUTPUT
echo "current_count=$CURRENT_COUNT" >> $GITHUB_OUTPUT
if [ "$HAS_NEW_CYCLES" = "true" ]; then
# Extract new cycles list to file and output
jq -r '.newCycles.cyclesList[]? | " \(.cycle)"' /tmp/cycle-data.json > /tmp/new-cycles.txt
echo "new_cycles<<CYCLES_EOF" >> $GITHUB_OUTPUT
cat /tmp/new-cycles.txt >> $GITHUB_OUTPUT
echo "CYCLES_EOF" >> $GITHUB_OUTPUT
fi
else
echo "ERROR: Failed to validate JSON structure"
echo "Extracted JSON:"
cat /tmp/cycle-data.json
exit 1
fi
- name: Generate comment body
id: comment
run: |
cd packages/react
NEW_CYCLES_FOUND="${{ steps.compare.outputs.new_cycles_found }}"
CYCLES_DECREASED="${{ steps.compare.outputs.cycles_decreased }}"
CYCLES_REMOVED="${{ steps.compare.outputs.cycles_removed }}"
BASELINE_COUNT="${{ steps.compare.outputs.baseline_count }}"
CURRENT_COUNT="${{ steps.compare.outputs.current_count }}"
if [ "$NEW_CYCLES_FOUND" = "true" ]; then
{
echo "## ⚠️ New Circular Dependencies Detected"
echo ""
echo "The following new circular dependencies have been detected:"
echo ""
echo '```'
jq -r '.newCycles.cyclesList[]? | " \(.cycle)"' /tmp/cycle-data.json 2>/dev/null || echo " (unable to load cycles)"
echo '```'
echo ""
echo "Please review and resolve these circular dependencies."
} > /tmp/comment-body.txt
elif [ "$CYCLES_DECREASED" = "true" ]; then
{
echo "## 🎉 Circular Dependencies Reduced"
echo ""
echo "Great job! You have reduced circular dependencies by **${CYCLES_REMOVED}** (from ${BASELINE_COUNT} to ${CURRENT_COUNT})."
echo ""
echo "Keep up the good work!"
} > /tmp/comment-body.txt
else
{
echo "## ✅ No New Circular Dependencies"
echo ""
echo "No new circular dependencies detected. Current count: **${CURRENT_COUNT}**"
} > /tmp/comment-body.txt
fi
# Set output for the comment action
echo "body<<COMMENT_BODY_EOF" >> $GITHUB_OUTPUT
cat /tmp/comment-body.txt >> $GITHUB_OUTPUT
echo "COMMENT_BODY_EOF" >> $GITHUB_OUTPUT
- name: Comment on PR with cycle dependency status
uses: ./.github/actions/add-or-update-pr-comment
with:
comment-type: cycle_dependency
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-body: ${{ steps.comment.outputs.body }}