Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions .github/workflows/lecture-translation-migration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Lecture Translation Migration

on:
repository_dispatch:
types: [pr-opened, pr-synchronized]
workflow_dispatch:
inputs:
source_repo:
description: 'Source repository (e.g., QuantEcon/lecture-python.myst)'
required: true
default: 'QuantEcon/lecture-python.myst'
pr_number:
description: 'PR number in source repository'
required: true
type: number
target_repo:
description: 'Target repository (e.g., QuantEcon/lecture-python.zh-cn)'
required: true
default: 'QuantEcon/lecture-python.zh-cn'

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
TRANSLATION_REVIEWER: nisha617

jobs:
check-translation-status:
runs-on: ubuntu-latest
outputs:
translated-files: ${{ steps.check.outputs.translated-files }}
should-proceed: ${{ steps.check.outputs.should-proceed }}
steps:
- name: Checkout meta repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install dependencies
run: |
pip install requests PyYAML openai gitpython

- name: Get PR details and check translation status
id: check
run: |
python scripts/check_translation_status.py \
--source-repo "${{ github.event.client_payload.repository || inputs.source_repo }}" \
--pr-number "${{ github.event.client_payload.pr_number || inputs.pr_number }}" \
--target-repo "${{ github.event.client_payload.target_repo || inputs.target_repo }}"

create-translation-pr:
needs: check-translation-status
if: needs.check-translation-status.outputs.should-proceed == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout meta repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install dependencies
run: |
pip install requests PyYAML openai gitpython diff-match-patch

- name: Create translation PR
run: |
python scripts/create_translation_pr.py \
--source-repo "${{ github.event.client_payload.repository || inputs.source_repo }}" \
--pr-number "${{ github.event.client_payload.pr_number || inputs.pr_number }}" \
--target-repo "${{ github.event.client_payload.target_repo || inputs.target_repo }}" \
--translated-files '${{ needs.check-translation-status.outputs.translated-files }}'

create-fallback-issue:
needs: [check-translation-status, create-translation-pr]
if: always() && (needs.check-translation-status.outputs.should-proceed == 'false' || failure())
runs-on: ubuntu-latest
steps:
- name: Checkout meta repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install dependencies
run: |
pip install requests PyYAML

- name: Create fallback issue
run: |
python scripts/create_fallback_issue.py \
--source-repo "${{ github.event.client_payload.repository || inputs.source_repo }}" \
--pr-number "${{ github.event.client_payload.pr_number || inputs.pr_number }}" \
--target-repo "${{ github.event.client_payload.target_repo || inputs.target_repo }}" \
--reason "${{ needs.create-translation-pr.result }}"
55 changes: 55 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# Virtual environments
venv/
env/
ENV/

# IDE
.vscode/
.idea/
*.swp
*.swo

# OS
.DS_Store
Thumbs.db

# Logs
*.log

# Temporary files
*.tmp
*.temp

# Environment variables
.env
.env.local
.env.production

# Test outputs
test_output/
temp_repos/
79 changes: 79 additions & 0 deletions INTEGRATION_EXAMPLE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Integration with Source Repository

To fully integrate this translation workflow, add the following workflow to the source repository (`QuantEcon/lecture-python.myst`):

## `.github/workflows/trigger-translation.yml`

```yaml
name: Trigger Translation Check

on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- 'lectures/*.md'

jobs:
trigger-translation:
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
steps:
- name: Trigger translation workflow
run: |
curl -X POST \
-H "Authorization: token ${{ secrets.META_REPO_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
-H "Content-Type: application/json" \
https://api.github.com/repos/QuantEcon/meta/dispatches \
-d '{
"event_type": "pr-opened",
"client_payload": {
"repository": "${{ github.repository }}",
"pr_number": ${{ github.event.number }},
"target_repo": "QuantEcon/lecture-python.zh-cn"
}
}'

- name: Comment on PR
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '🔄 Translation workflow triggered! If any of the modified lectures have been translated to Chinese, a translation PR will be automatically created.'
})
```

## Required Secrets

Add the following secret to the source repository:

- `META_REPO_TOKEN`: A GitHub personal access token with the following permissions:
- `repo` scope for the meta repository
- Permission to trigger workflow dispatches

## Alternative: Webhook Integration

Instead of using repository dispatch, you can set up a webhook:

1. Go to repository Settings → Webhooks
2. Add webhook with URL: `https://api.github.com/repos/QuantEcon/meta/dispatches`
3. Set content type to `application/json`
4. Select "Pull requests" events
5. Add webhook secret if needed

## Testing the Integration

1. Create a test PR in the source repository that modifies a lecture file
2. Check that the workflow is triggered in the meta repository
3. Verify that the correct files are identified for translation
4. Check that PRs or issues are created as expected

## Monitoring

Monitor the workflow execution in:
- Actions tab of the meta repository
- Check logs for debugging information
- Review created PRs and issues in target repository
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,36 @@
# meta
For issues and discussion covering more than one repository

## Translation Automation Workflow

This repository now includes an automated workflow for translating lecture changes from English to Chinese. When lectures are modified in `QuantEcon/lecture-python.myst`, the system automatically:

1. **Detects** which lectures have been changed
2. **Checks** if those lectures have been translated to Chinese
3. **Translates** the changes using AI
4. **Creates** a pull request in `QuantEcon/lecture-python.zh-cn`
5. **Tags** reviewers for verification

### Quick Start

1. **Setup Secrets**: Configure `GITHUB_TOKEN` and `OPENAI_API_KEY` in repository settings
2. **Integration**: Add trigger workflow to source repository (see `INTEGRATION_EXAMPLE.md`)
3. **Test**: Create a PR in the English repository to test the workflow

### Files

- 📋 **`.github/workflows/lecture-translation-migration.yml`** - Main workflow
- 🐍 **`scripts/`** - Python automation scripts
- 📚 **`TRANSLATION_WORKFLOW.md`** - Detailed documentation
- 🔗 **`INTEGRATION_EXAMPLE.md`** - Source repository integration
- ✅ **`scripts/validate_setup.py`** - Setup validation
- 🎬 **`scripts/demo_workflow.py`** - Workflow demonstration

### Quick Validation

```bash
python scripts/validate_setup.py # Check setup
python scripts/demo_workflow.py # See workflow demo
```

See `TRANSLATION_WORKFLOW.md` for complete documentation.
Loading