Skip to content

Commit

Permalink
Merge branch 'main' into feat/2fa
Browse files Browse the repository at this point in the history
  • Loading branch information
rubentalstra authored Feb 12, 2025
2 parents 910eb19 + 2a506df commit 2040635
Show file tree
Hide file tree
Showing 100 changed files with 3,395 additions and 1,185 deletions.
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/NEW-LANGUAGE-REQUEST.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: New Language Request
description: Request to add a new language for LibreChat translations.
title: "New Language Request: "
labels: ["enhancement", "i18n"]
labels: ["enhancement", "🌍 i18n"]
body:
- type: markdown
attributes:
Expand Down Expand Up @@ -30,4 +30,4 @@ body:
description: By submitting this issue, you agree to follow our [Code of Conduct](https://github.com/danny-avila/LibreChat/blob/main/.github/CODE_OF_CONDUCT.md).
options:
- label: I agree to follow this project's Code of Conduct
required: true
required: true
70 changes: 0 additions & 70 deletions .github/TRANSLATION.md

This file was deleted.

71 changes: 24 additions & 47 deletions .github/workflows/eslint-ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
name: ESLint Code Quality Checks

on:
pull_request:
branches:
- main
- dev
- release/*
paths:
- 'api/**'
- 'client/**'

jobs:
eslint_checks:
Expand All @@ -29,67 +33,40 @@ jobs:
- name: Install dependencies
run: npm ci

# Use a paths filter (v3) to detect changes in JavaScript/TypeScript files,
# but only consider files that are added or modified (ignoring deleted files).
- name: Filter changed files for ESLint
id: file_filter
uses: dorny/paths-filter@v3
with:
filters: |
eslint:
- added|modified: '**/*.js'
- added|modified: '**/*.jsx'
- added|modified: '**/*.ts'
- added|modified: '**/*.tsx'
# Run ESLint only if relevant files have been added or modified.
# Run ESLint on changed files within the api/ and client/ directories.
- name: Run ESLint on changed files
if: steps.file_filter.outputs.eslint == 'true'
env:
SARIF_ESLINT_IGNORE_SUPPRESSED: "true"
run: |
# Extract the base commit SHA from the pull_request event payload.
BASE_SHA=$(jq --raw-output .pull_request.base.sha "$GITHUB_EVENT_PATH")
echo "Base commit SHA: $BASE_SHA"
# List files changed between the base commit and current HEAD,
# but only include files that are not deleted (ACMRTUXB: A, C, M, R, T, U, X, B).
CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRTUXB "$BASE_SHA" HEAD | grep -E '\.(js|jsx|ts|tsx)$')
echo "Files to lint:"
# Get changed files (only JS/TS files in api/ or client/)
CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRTUXB "$BASE_SHA" HEAD | grep -E '^(api|client)/.*\.(js|jsx|ts|tsx)$' || true)
# Debug output
echo "Changed files:"
echo "$CHANGED_FILES"
# Run ESLint on the changed files.
# Ensure there are files to lint before running ESLint
if [[ -z "$CHANGED_FILES" ]]; then
echo "No matching files changed. Skipping ESLint."
echo "UPLOAD_SARIF=false" >> $GITHUB_ENV
exit 0
fi
# Set variable to allow SARIF upload
echo "UPLOAD_SARIF=true" >> $GITHUB_ENV
# Run ESLint
npx eslint --no-error-on-unmatched-pattern \
--config eslint.config.mjs \
--format @microsoft/eslint-formatter-sarif \
--output-file eslint-results.sarif $CHANGED_FILES || true
# If no JavaScript/TypeScript files were added or modified,
# create a valid (non-empty) SARIF file containing one run.
- name: Create empty SARIF results file
if: steps.file_filter.outputs.eslint != 'true'
run: |
cat << 'EOF' > eslint-results.sarif
{
"version": "2.1.0",
"$schema": "https://json.schemastore.org/sarif-2.1.0.json",
"runs": [
{
"tool": {
"driver": {
"name": "ESLint",
"informationUri": "https://eslint.org",
"version": "0.0.0",
"rules": []
}
},
"results": []
}
]
}
EOF
- name: Upload analysis results to GitHub
if: env.UPLOAD_SARIF == 'true'
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: eslint-results.sarif
Expand Down
84 changes: 84 additions & 0 deletions .github/workflows/i18n-unused-keys.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Detect Unused i18next Strings

on:
pull_request:
paths:
- "client/src/**"

jobs:
detect-unused-i18n-keys:
runs-on: ubuntu-latest
permissions:
pull-requests: write # Required for posting PR comments
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Find unused i18next keys
id: find-unused
run: |
echo "🔍 Scanning for unused i18next keys..."
# Define paths
I18N_FILE="client/src/locales/en/translation.json"
SOURCE_DIR="client/src"
# Check if translation file exists
if [[ ! -f "$I18N_FILE" ]]; then
echo "::error title=Missing i18n File::Translation file not found: $I18N_FILE"
exit 1
fi
# Extract all keys from the JSON file
KEYS=$(jq -r 'keys[]' "$I18N_FILE")
# Track unused keys
UNUSED_KEYS=()
# Check if each key is used in the source code
for KEY in $KEYS; do
if ! grep -r --include=\*.{js,jsx,ts,tsx} -q "$KEY" "$SOURCE_DIR"; then
UNUSED_KEYS+=("$KEY")
fi
done
# Output results
if [[ ${#UNUSED_KEYS[@]} -gt 0 ]]; then
echo "🛑 Found ${#UNUSED_KEYS[@]} unused i18n keys:"
echo "unused_keys=$(echo "${UNUSED_KEYS[@]}" | jq -R -s -c 'split(" ")')" >> $GITHUB_ENV
for KEY in "${UNUSED_KEYS[@]}"; do
echo "::warning title=Unused i18n Key::'$KEY' is defined but not used in the codebase."
done
else
echo "✅ No unused i18n keys detected!"
echo "unused_keys=[]" >> $GITHUB_ENV
fi
- name: Post verified comment on PR
if: env.unused_keys != '[]'
run: |
PR_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
# Format the unused keys list correctly, filtering out empty entries
FILTERED_KEYS=$(echo "$unused_keys" | jq -r '.[]' | grep -v '^\s*$' | sed 's/^/- `/;s/$/`/' )
COMMENT_BODY=$(cat <<EOF
### 🚨 Unused i18next Keys Detected
The following translation keys are defined in \`translation.json\` but are **not used** in the codebase:
$FILTERED_KEYS
⚠️ **Please remove these unused keys to keep the translation files clean.**
EOF
)
gh api "repos/${{ github.repository }}/issues/${PR_NUMBER}/comments" \
-f body="$COMMENT_BODY" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Fail workflow if unused keys found
if: env.unused_keys != '[]'
run: exit 1 # This makes the PR fail if unused keys exist
Original file line number Diff line number Diff line change
@@ -1,23 +1,46 @@
name: Create Translation PR on Version Published
name: Sync Locize Translations & Create Translation PR

on:
# do not run during PR request only on push and repository_dispatch
# pull_request:
# branches:
# - main
push:
branches: [main]
repository_dispatch:
types: [locize/versionPublished]

jobs:
createPullRequest:
sync-translations:
name: Sync Translation Keys with Locize
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set Up Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install locize CLI
run: npm install -g locize-cli

# Sync translations (Push missing keys & remove deleted ones)
- name: Sync Locize with Repository
if: ${{ github.event_name == 'push' }}
run: |
cd client/src/locales
locize sync --api-key ${{ secrets.LOCIZE_API_KEY }} --project-id ${{ secrets.LOCIZE_PROJECT_ID }} --language en
# When triggered by repository_dispatch, skip sync step.
- name: Skip sync step on non-push events
if: ${{ github.event_name != 'push' }}
run: echo "Skipping sync as the event is not a push."

create-pull-request:
name: Create Translation PR on Version Published
runs-on: ubuntu-latest
needs: sync-translations
permissions:
contents: write
pull-requests: write

steps:
# 1. Check out the repository.
- name: Checkout Repository
Expand Down Expand Up @@ -46,5 +69,4 @@ jobs:
- 🎯 **Objective**: Update `translation.json` with the latest translations from locize.
- 🔍 **Details**: This PR is automatically generated upon receiving a versionPublished event with version "latest". It reflects the newest translations provided by locize.
- ✅ **Status**: Ready for review.
labels: |
🌍 i18n
labels: "🌍 i18n"
26 changes: 0 additions & 26 deletions .github/workflows/locize-push-missing-keys.yml

This file was deleted.

Loading

0 comments on commit 2040635

Please sign in to comment.