Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 12, 2025

This PR implements a comprehensive GitHub Actions workflow that automatically detects when lectures are modified in the English repository (QuantEcon/lecture-python.myst) and migrates those changes to the Chinese repository (QuantEcon/lecture-python.zh-cn) when the lectures have already been translated.

Workflow Overview

The system provides a complete automation pipeline:

  1. Detection: Monitors PRs in the English repository for lecture file changes
  2. Translation Check: Cross-references modified files against the Chinese repository's _toc.yml to identify which lectures have been translated
  3. AI Translation: Uses OpenAI GPT-4 to translate content while preserving markdown formatting, code blocks, and mathematical formulas
  4. PR Creation: Automatically creates a pull request in the Chinese repository with translated changes
  5. Review Integration: Tags @nisha617 for translation review with detailed context
  6. Fallback Handling: Creates issues for manual review when automatic translation fails

Key Components

GitHub Actions Workflow

  • Trigger: Repository dispatch events from source repository or manual workflow dispatch
  • Multi-job pipeline: Separate jobs for checking translation status, creating PRs, and handling fallbacks
  • Error handling: Graceful degradation with comprehensive logging

Python Automation Scripts

  • check_translation_status.py: Analyzes PR diffs and determines which files need translation
  • create_translation_pr.py: Handles AI translation and PR creation with proper branch management
  • create_fallback_issue.py: Creates detailed issues when automation cannot proceed
  • Support scripts for testing, validation, and demonstration

AI Translation Features

  • Specialized prompts for academic/technical content preservation
  • Code snippet and mathematical formula protection
  • Consistent academic Chinese terminology
  • Markdown structure preservation

Setup Requirements

The workflow requires two repository secrets:

  • GITHUB_TOKEN: Personal access token with repository permissions
  • OPENAI_API_KEY: OpenAI API key for translation services

Integration with the source repository can be achieved through repository dispatch events or webhooks as documented in INTEGRATION_EXAMPLE.md.

Testing and Validation

Includes comprehensive testing infrastructure:

  • Syntax validation for all components
  • Setup validation with detailed guidance
  • Interactive workflow demonstration
  • Example integration code for source repository

Example Usage

When a PR modifying lectures/linear_algebra.md is opened in the English repository:

  1. The workflow detects the change and checks if linear_algebra exists in the Chinese _toc.yml
  2. If found, it translates the modified content using GPT-4
  3. Creates a new branch translation-update-pr-{number} in the Chinese repository
  4. Opens a PR with the translated content and tags @nisha617
  5. Provides detailed review context including links to the original PR

If translation fails or no translated lectures are found, it creates an issue for manual review instead.

This automation significantly reduces the manual overhead of keeping translations synchronized while maintaining quality through AI assistance and human review.

Fixes #187.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] CI: Write a GitHub Action to check if a lecture has been translated to Chinese and open a PR to migrate changes CI: Implement automated translation workflow for lecture synchronization Aug 12, 2025
Copilot AI requested a review from mmcky August 12, 2025 06:01
@mmcky
Copy link
Contributor

mmcky commented Aug 12, 2025

@nisha617 later this week I will do some debugging to see if this will work. It might save us a lot of time.

You may get pinged during the testing via GitHub, please feel free to ignore them for now and I'll update you re: when the debug process / testing phase is done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CI: Write a GitHub Action to check if a lecture has been translated to Chinese and open a PR to migrate changes

2 participants