Files
langchain4j--langchain4j/.github/workflows/main.yaml
T
wehub-resource-sync a2578d7ff1
Documentation: build and deploy / deploy (push) Waiting to run
langchain4j-github-bot.yml lint / langchain4j-github-bot.yml validation (push) Waiting to run
Java CI / compile_and_unit_test (17) (push) Waiting to run
Java CI / compile_and_unit_test (21) (push) Waiting to run
Java CI / integration_test (21) (push) Blocked by required conditions
Java CI / compliance (push) Waiting to run
Java CI / spotless (push) Waiting to run
snapshot_release / snapshot_release (push) Waiting to run
Split Package Detection / check-split-packages (push) Waiting to run
Java CI / compile_and_unit_test (25) (push) Waiting to run
chore: import upstream snapshot with attribution
2026-07-13 13:38:45 +08:00

380 lines
15 KiB
YAML

name: Java CI
on:
push:
branches:
- main
- 'release/**'
paths-ignore:
- '.gitignore'
- '*.md'
- 'LICENSE'
- '.github/*.md'
- '.github/*.yml'
- '.github/*.conf'
- '.github/ISSUE_TEMPLATE/*.md'
pull_request:
branches:
- main
- 'release/**'
paths-ignore:
- '.gitignore'
- '*.md'
- 'LICENSE'
- '.github/*.md'
- '.github/*.yml'
- '.github/*.conf'
- '.github/ISSUE_TEMPLATE/*.md'
workflow_dispatch:
permissions:
contents: read
jobs:
compile_and_unit_test:
runs-on: ubuntu-latest
strategy:
matrix:
java_version:
- 17
- 21
- 25
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
with:
fetch-depth: 0
- name: Set up JDK ${{ matrix.java_version }}
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
with:
java-version: ${{ matrix.java_version }}
distribution: 'temurin'
cache: 'maven'
- name: Compile and unit test with JDK ${{ matrix.java_version }}
run: |
set -o pipefail
mvn -B -U -DembeddingsSkipDownload -T8C test javadoc:aggregate 2>&1 | tee maven-output.log
- name: Publish test summary
if: always()
env:
SUMMARY_TITLE: 'Test Results (JDK ${{ matrix.java_version }})'
run: |
python3 << 'PYEOF'
import xml.etree.ElementTree as ET
import glob, os, re
files = glob.glob('**/target/*-reports/TEST-*.xml', recursive=True)
if not files:
raise SystemExit(0) # e.g. compilation failed before any test ran
total = failures = errors = skipped = 0
failed_tests = []
for path in files:
try:
root = ET.parse(path).getroot()
total += int(root.get('tests', 0))
failures += int(root.get('failures', 0))
errors += int(root.get('errors', 0))
skipped += int(root.get('skipped', 0))
for tc in root.findall('.//testcase'):
fail = tc.find('failure')
if fail is None:
fail = tc.find('error')
if fail is not None:
cls = tc.get('classname', '')
name = tc.get('name', '')
trace = fail.text or ''
m = re.search(r'\bat ' + re.escape(cls) + r'[.$][^\n(]*\(([^)]+\.java:\d+)\)', trace)
loc = f'`{m.group(1)}`' if m else ''
msg = (fail.get('message', '') or '').replace('\n', '<br>').replace('|', '\\|')
if len(msg) > 500:
msg = f"{msg[:500]}<details><summary>show more</summary>{msg[500:]}</details>"
failed_tests.append(f"| `{cls}` | `{name}` | {loc} | {msg} |")
except Exception:
pass
passed = total - failures - errors - skipped
title = os.environ.get('SUMMARY_TITLE', 'Test Results')
summary = os.environ.get('GITHUB_STEP_SUMMARY', '/dev/null')
with open(summary, 'a') as f:
f.write(f'## {title}\n\n')
if failures == 0 and errors == 0:
f.write(f':white_check_mark: **{passed} passed**, {skipped} skipped out of {total} tests\n')
else:
f.write(f':x: **{failures} failed, {errors} errors**, {passed} passed, {skipped} skipped out of {total} tests\n')
if failed_tests:
f.write('\n### Failures\n\n')
f.write('| Class | Test | Location | Error Message |\n')
f.write('|-------|------|----------|---------------|\n')
for line in failed_tests[:50]:
f.write(line + '\n')
if len(failed_tests) > 50:
f.write(f'\n*... and {len(failed_tests) - 50} more*\n')
PYEOF
- name: Surface build errors
if: failure()
run: |
{
echo '## Build Errors (JDK ${{ matrix.java_version }})'
echo ''
echo '```'
# Only Maven's own errors (compilation, javadoc, plugins). Exclude forked
# test-JVM output that Surefire re-emits with an [ERROR] prefix on channel
# corruption (e.g. mock-server stub dumps) — that is test noise, not a build error.
grep '^\[ERROR\]' maven-output.log \
| grep -vE '^\[ERROR\]( +"|[[:space:]]*(Stub|DEBUG:)|[[:space:]]*$)' \
| head -50
echo '```'
} >> $GITHUB_STEP_SUMMARY
integration_test:
needs: compile_and_unit_test
runs-on: ubuntu-latest
continue-on-error: true
env:
GCP_CREDENTIALS_JSON: ${{ secrets.GCP_CREDENTIALS_JSON }}
strategy:
fail-fast: false
matrix:
java_version:
- 21
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
with:
fetch-depth: 0
- name: Create branch from commit by event name
env:
EVENT_NAME: ${{ github.event_name }}
BEFORE_SHA: ${{ github.event.before }}
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: |
if [[ "$EVENT_NAME" == 'push' ]]; then
git branch __branch_before "$BEFORE_SHA"
elif [[ "$EVENT_NAME" == 'pull_request' ]]; then
git branch __branch_before "$PR_BASE_SHA"
fi
- name: Set up JDK ${{ matrix.java_version }}
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
with:
java-version: ${{ matrix.java_version }}
distribution: 'temurin'
cache: 'maven'
- name: Authenticate to Google Cloud
# Required for Google modules (e.g., langchain4j-vertex-ai)
# Skipped for PRs from forks where secrets are not available
if: ${{ env.GCP_CREDENTIALS_JSON != '' }}
uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
credentials_json: ${{ secrets.GCP_CREDENTIALS_JSON }}
- name: Setup JBang
# Required for MCP module
uses: jbangdev/setup-jbang@2b1b465a7b75f4222b81426f23a01e013aa7b95c # v0.1.1
continue-on-error: true
- name: Integration test with JDK ${{ matrix.java_version }}
run: |
set -o pipefail
## Compile and install ALL modules to ensure that modules selected by GIB in the next step
## reference the latest code (e.g., langchain4j-core and langchain4j)
mvn -B -U -T8C -DskipTests -DskipITs -DembeddingsSkipCache install 2>&1 | tee maven-output.log
mvn -B -U verify \
-Dgib.disable=false -Dgib.referenceBranch=__branch_before \
-Djunit.jupiter.extensions.autodetection.enabled=true \
-DskipAzureAiSearchITs -DskipJlamaITs -DskipLocalAiITs -DskipMilvusITs -DskipOllamaITs -DskipOracleITs -DskipVespaITs \
-DembeddingsSkipCache \
-Dtinylog.writer.level=info 2>&1 | tee maven-output.log
env:
LC4J_GLOBAL_TEST_RETRY_ENABLED: true
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
ANTHROPIC_CACHING_BASE_URL: ${{ secrets.ANTHROPIC_CACHING_BASE_URL }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AZURE_OPENAI_AUDIO_DEPLOYMENT_NAME: ${{ secrets.AZURE_OPENAI_AUDIO_DEPLOYMENT_NAME }}
AZURE_OPENAI_AUDIO_ENDPOINT: ${{ secrets.AZURE_OPENAI_AUDIO_ENDPOINT }}
AZURE_OPENAI_AUDIO_KEY: ${{ secrets.AZURE_OPENAI_AUDIO_KEY }}
AZURE_OPENAI_DEPLOYMENT_NAME: ${{ secrets.AZURE_OPENAI_DEPLOYMENT_NAME }}
AZURE_OPENAI_ENDPOINT: ${{ secrets.AZURE_OPENAI_ENDPOINT }}
AZURE_OPENAI_KEY: ${{ secrets.AZURE_OPENAI_KEY }}
AZURE_SEARCH_ENDPOINT: ${{ secrets.AZURE_SEARCH_ENDPOINT }}
AZURE_SEARCH_KEY: ${{ secrets.AZURE_SEARCH_KEY }}
COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }}
DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }}
ELASTICSEARCH_CLOUD_API_KEY: ${{ secrets.ELASTICSEARCH_CLOUD_API_KEY }}
ELASTICSEARCH_CLOUD_URL: ${{ secrets.ELASTICSEARCH_CLOUD_URL }}
GCP_CREDENTIALS_JSON: ${{ secrets.GCP_CREDENTIALS_JSON }}
GCP_LOCATION: ${{ secrets.GCP_LOCATION }}
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
GCP_PROJECT_NUM: ${{ secrets.GCP_PROJECT_NUM }}
GCP_VERTEXAI_ENDPOINT: ${{ secrets.GCP_VERTEXAI_ENDPOINT }}
GOOGLE_AI_GEMINI_API_KEY: ${{ secrets.GOOGLE_AI_GEMINI_API_KEY }}
HF_API_KEY: ${{ secrets.HF_API_KEY }}
JINA_API_KEY: ${{ secrets.JINA_API_KEY }}
MICROSOFT_FOUNDRY_API_KEY: ${{ secrets.MICROSOFT_FOUNDRY_API_KEY }}
MICROSOFT_FOUNDRY_ENDPOINT: ${{ secrets.MICROSOFT_FOUNDRY_ENDPOINT }}
MILVUS_API_KEY: ${{ secrets.MILVUS_API_KEY }}
MILVUS_URI: ${{ secrets.MILVUS_URI }}
MISTRAL_AI_API_KEY: ${{ secrets.MISTRAL_AI_API_KEY }}
NOMIC_API_KEY: ${{ secrets.NOMIC_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_BASE_URL: ${{ secrets.OPENAI_BASE_URL }}
PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }}
RAPID_API_KEY: ${{ secrets.RAPID_API_KEY }}
TAVILY_API_KEY: ${{ secrets.TAVILY_API_KEY }}
VOYAGE_API_KEY: ${{ secrets.VOYAGE_API_KEY }}
WEAVIATE_API_KEY: ${{ secrets.WEAVIATE_API_KEY }}
WEAVIATE_HOST: ${{ secrets.WEAVIATE_HOST }}
- name: Publish test summary
if: always()
env:
SUMMARY_TITLE: 'Test Results (Integration Test, JDK ${{ matrix.java_version }})'
run: |
python3 << 'PYEOF'
import xml.etree.ElementTree as ET
import glob, os, re
files = glob.glob('**/target/*-reports/TEST-*.xml', recursive=True)
if not files:
raise SystemExit(0) # e.g. compilation failed before any test ran
total = failures = errors = skipped = 0
failed_tests = []
for path in files:
try:
root = ET.parse(path).getroot()
total += int(root.get('tests', 0))
failures += int(root.get('failures', 0))
errors += int(root.get('errors', 0))
skipped += int(root.get('skipped', 0))
for tc in root.findall('.//testcase'):
fail = tc.find('failure')
if fail is None:
fail = tc.find('error')
if fail is not None:
cls = tc.get('classname', '')
name = tc.get('name', '')
trace = fail.text or ''
m = re.search(r'\bat ' + re.escape(cls) + r'[.$][^\n(]*\(([^)]+\.java:\d+)\)', trace)
loc = f'`{m.group(1)}`' if m else ''
msg = (fail.get('message', '') or '').replace('\n', '<br>').replace('|', '\\|')
if len(msg) > 500:
msg = f"{msg[:500]}<details><summary>show more</summary>{msg[500:]}</details>"
failed_tests.append(f"| `{cls}` | `{name}` | {loc} | {msg} |")
except Exception:
pass
passed = total - failures - errors - skipped
title = os.environ.get('SUMMARY_TITLE', 'Test Results')
summary = os.environ.get('GITHUB_STEP_SUMMARY', '/dev/null')
with open(summary, 'a') as f:
f.write(f'## {title}\n\n')
if failures == 0 and errors == 0:
f.write(f':white_check_mark: **{passed} passed**, {skipped} skipped out of {total} tests\n')
else:
f.write(f':x: **{failures} failed, {errors} errors**, {passed} passed, {skipped} skipped out of {total} tests\n')
if failed_tests:
f.write('\n### Failures\n\n')
f.write('| Class | Test | Location | Error Message |\n')
f.write('|-------|------|----------|---------------|\n')
for line in failed_tests[:50]:
f.write(line + '\n')
if len(failed_tests) > 50:
f.write(f'\n*... and {len(failed_tests) - 50} more*\n')
PYEOF
- name: Surface build errors
if: failure()
run: |
{
echo '## Build Errors (Integration Test, JDK ${{ matrix.java_version }})'
echo ''
echo '```'
# Only Maven's own errors (compilation, javadoc, plugins). Exclude forked
# test-JVM output that Surefire re-emits with an [ERROR] prefix on channel
# corruption (e.g. mock-server stub dumps) — that is test noise, not a build error.
grep '^\[ERROR\]' maven-output.log \
| grep -vE '^\[ERROR\]( +"|[[:space:]]*(Stub|DEBUG:)|[[:space:]]*$)' \
| head -50
echo '```'
} >> $GITHUB_STEP_SUMMARY
- name: Clean Docker
run: docker system prune -af || true
# For checking some compliance things (require a recent JDK due to plugins so in a separate step)
compliance:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
- name: Set up JDK 17
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'
# Check we only rely on permissive licenses in the main parts of the library:
- name: License Compliance
run: |
set -o pipefail
mvn -P compliance org.honton.chas:license-maven-plugin:compliance 2>&1 | tee maven-output.log
- name: Surface build errors
if: failure()
run: |
{
echo '## Build Errors (License Compliance)'
echo ''
echo '```'
# Exclude forked-JVM output re-emitted with an [ERROR] prefix (test noise).
grep '^\[ERROR\]' maven-output.log \
| grep -vE '^\[ERROR\]( +"|[[:space:]]*(Stub|DEBUG:)|[[:space:]]*$)' \
| head -50
echo '```'
} >> $GITHUB_STEP_SUMMARY
spotless:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'
- name: Spotless Check
run: |
set -o pipefail
mvn -Pspotless validate 2>&1 | tee maven-output.log
- name: Surface build errors
if: failure()
run: |
{
echo '## Build Errors (Spotless)'
echo ''
echo '```'
# Exclude forked-JVM output re-emitted with an [ERROR] prefix (test noise).
grep '^\[ERROR\]' maven-output.log \
| grep -vE '^\[ERROR\]( +"|[[:space:]]*(Stub|DEBUG:)|[[:space:]]*$)' \
| head -50
echo '```'
} >> $GITHUB_STEP_SUMMARY