fix: Auto sync docs workflow conditional, sync images too (#590)

This commit is contained in:
Brace Sproul 2025-07-29 11:29:57 -07:00 • committed by GitHub
parent 27c9e0096f
commit 37d2a4eb05
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4,12 +4,13 @@ on:
push: push:
branches: branches:
- main - main
paths:
- 'apps/docs/**'
workflow_dispatch: workflow_dispatch:
jobs: jobs:
sync-docs: sync-docs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' || contains(github.event.head_commit.modified, 'apps/docs/') || contains(github.event.head_commit.added, 'apps/docs/') || contains(github.event.head_commit.removed, 'apps/docs/')
steps: steps:
- name: Checkout source repository - name: Checkout source repository
@ -17,16 +18,31 @@ jobs:
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Check for MDX files in apps/docs - name: Check for MDX files and images in apps/docs
id: check-files id: check-files
run: | run: |
docs_found=false
images_found=false
if find apps/docs -name "*.mdx" -type f | head -1 | grep -q .; then if find apps/docs -name "*.mdx" -type f | head -1 | grep -q .; then
echo "docs_found=true" >> $GITHUB_OUTPUT docs_found=true
echo "Found MDX files to sync" echo "Found MDX files to sync"
fi
if [ -d "apps/docs/images" ] && find apps/docs/images -type f | head -1 | grep -q .; then
images_found=true
echo "Found images to sync"
fi
if [ "$docs_found" = true ] || [ "$images_found" = true ]; then
echo "docs_found=true" >> $GITHUB_OUTPUT
echo "At least MDX files or images found to sync"
else else
echo "docs_found=false" >> $GITHUB_OUTPUT echo "docs_found=false" >> $GITHUB_OUTPUT
echo "No MDX files found in apps/docs" echo "No MDX files or images found in apps/docs"
fi fi
echo "images_found=$images_found" >> $GITHUB_OUTPUT
- name: Clone LangChain docs repository - name: Clone LangChain docs repository
if: steps.check-files.outputs.docs_found == 'true' if: steps.check-files.outputs.docs_found == 'true'
@ -44,50 +60,81 @@ jobs:
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
git checkout -b "$BRANCH_NAME" git checkout -b "$BRANCH_NAME"
- name: Prepare target directory - name: Prepare target directories
if: steps.check-files.outputs.docs_found == 'true' if: steps.check-files.outputs.docs_found == 'true'
run: | run: |
cd langchain-docs cd langchain-docs
# Remove existing content to ensure clean sync # Remove existing content to ensure clean sync
rm -rf src/labs/swe rm -rf src/labs/swe
mkdir -p src/labs/swe mkdir -p src/labs/swe
# Prepare images directory
mkdir -p src/images
- name: Copy MDX files to LangChain docs - name: Copy MDX files to LangChain docs
if: steps.check-files.outputs.docs_found == 'true' if: steps.check-files.outputs.docs_found == 'true'
run: | run: |
# Copy all .mdx files from apps/docs to the target directory, preserving structure # Copy all .mdx files from apps/docs to the target directory, preserving structure
find apps/docs -name "*.mdx" -type f | while read file; do if find apps/docs -name "*.mdx" -type f | head -1 | grep -q .; then
# Get the relative path from apps/docs find apps/docs -name "*.mdx" -type f | while read file; do
rel_path="${file#apps/docs/}" # Get the relative path from apps/docs
# Create the directory structure in target rel_path="${file#apps/docs/}"
target_dir="langchain-docs/src/labs/swe/$(dirname "$rel_path")" # Create the directory structure in target
mkdir -p "$target_dir" target_dir="langchain-docs/src/labs/swe/$(dirname "$rel_path")"
# Copy the file mkdir -p "$target_dir"
cp "$file" "langchain-docs/src/labs/swe/$rel_path" # Copy the file
done cp "$file" "langchain-docs/src/labs/swe/$rel_path"
done
# List copied files for verification
echo "Copied MDX files:"
find langchain-docs/src/labs/swe/ -name "*.mdx" -type f
else
echo "No MDX files found to copy"
fi
# List copied files for verification
echo "Copied MDX files:"
find langchain-docs/src/labs/swe/ -name "*.mdx" -type f
echo "Directory structure:" echo "Directory structure:"
tree langchain-docs/src/labs/swe/ || find langchain-docs/src/labs/swe/ -type d tree langchain-docs/src/labs/swe/ || find langchain-docs/src/labs/swe/ -type d
- name: Copy images to LangChain docs
if: steps.check-files.outputs.docs_found == 'true' && steps.check-files.outputs.images_found == 'true'
run: |
# Copy all images from apps/docs/images to langchain-docs/src/images
if [ -d "apps/docs/images" ]; then
cp -r apps/docs/images/* langchain-docs/src/images/
# List copied images for verification
echo "Copied images:"
find langchain-docs/src/images/ -type f
else
echo "No images directory found to copy"
fi
- name: Commit changes - name: Commit changes
if: steps.check-files.outputs.docs_found == 'true' if: steps.check-files.outputs.docs_found == 'true'
id: commit id: commit
run: | run: |
cd langchain-docs cd langchain-docs
git add src/labs/swe/ git add src/labs/swe/
git add src/images/
if git diff --staged --quiet; then if git diff --staged --quiet; then
echo "No changes to commit" echo "No changes to commit"
echo "has_changes=false" >> $GITHUB_OUTPUT echo "has_changes=false" >> $GITHUB_OUTPUT
else else
git commit -m "Sync OpenSWE documentation files commit_message="Sync OpenSWE documentation files
- Updated MDX files from apps/docs/ - Updated MDX files from apps/docs/"
if [ "${{ steps.check-files.outputs.images_found }}" = "true" ]; then
commit_message="$commit_message
- Updated images from apps/docs/images/"
fi
commit_message="$commit_message
- Synced at $(date -u '+%Y-%m-%d %H:%M:%S UTC') - Synced at $(date -u '+%Y-%m-%d %H:%M:%S UTC')
- Source commit: ${{ github.sha }}" - Source commit: ${{ github.sha }}"
git commit -m "$commit_message"
echo "has_changes=true" >> $GITHUB_OUTPUT echo "has_changes=true" >> $GITHUB_OUTPUT
fi fi
@ -104,7 +151,9 @@ jobs:
**Changes:** **Changes:**
- Updated MDX files from \`apps/docs/\` - Updated MDX files from \`apps/docs/\`
- Target directory: \`src/labs/swe/\` - Target directory: \`src/labs/swe/\`$([ "${{ steps.check-files.outputs.images_found }}" = "true" ] && echo "
- Updated images from \`apps/docs/images/\`
- Target directory: \`src/images/\`" || echo "")
- Source commit: ${{ github.sha }} - Source commit: ${{ github.sha }}
- Synced at $(date -u '+%Y-%m-%d %H:%M:%S UTC') - Synced at $(date -u '+%Y-%m-%d %H:%M:%S UTC')
@ -112,4 +161,4 @@ jobs:
--head "$BRANCH_NAME" \ --head "$BRANCH_NAME" \
--base main --base main
env: env:
GH_TOKEN: ${{ secrets.LANGCHAIN_DOCS_TOKEN }} GH_TOKEN: ${{ secrets.LANGCHAIN_DOCS_TOKEN }}