|  | 
| 1 | 1 | name: CI | 
|  | 2 | + | 
| 2 | 3 | permissions: | 
| 3 |  | -  contents: read | 
|  | 4 | +  contents: write | 
|  | 5 | + | 
| 4 | 6 | on: | 
| 5 | 7 |   push: | 
| 6 |  | -    branches: ["**"] | 
| 7 |  | -  pull_request: | 
|  | 8 | +    branches:  | 
|  | 9 | +      - wzrdbrainjs | 
|  | 10 | +    paths: | 
|  | 11 | +      - 'src/wzrdbrain/wzrdbrain.py' | 
|  | 12 | +      - 'src/wzrdbrain/tricks.json' | 
|  | 13 | +      - '.github/workflows/ci.yml' | 
| 8 | 14 | 
 | 
| 9 | 15 | jobs: | 
| 10 | 16 |   test: | 
|  | 
| 29 | 35 |         run: mypy . | 
| 30 | 36 |       - name: Tests (pytest) | 
| 31 | 37 |         run: pytest | 
|  | 38 | +  translate: | 
|  | 39 | +    runs-on: ubuntu-latest | 
|  | 40 | + | 
|  | 41 | +    steps: | 
|  | 42 | +      - name: Checkout repository | 
|  | 43 | +        uses: actions/checkout@v4 | 
|  | 44 | + | 
|  | 45 | +      - name: Set up Python | 
|  | 46 | +        uses: actions/setup-python@v5 | 
|  | 47 | +        with: | 
|  | 48 | +          python-version: '3.13' | 
|  | 49 | + | 
|  | 50 | +      - name: Install dependencies | 
|  | 51 | +        run: pip install google-genai | 
|  | 52 | + | 
|  | 53 | +      - name: Translate Python to JavaScript | 
|  | 54 | +        run: | | 
|  | 55 | +          mkdir -p dist | 
|  | 56 | +          python utils/translate2js.py | 
|  | 57 | +        env: | 
|  | 58 | +          GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }} | 
|  | 59 | + | 
|  | 60 | +      - name: Show first lines of generated file | 
|  | 61 | +        run: | | 
|  | 62 | +          echo "Preview of src/wzrdbrain/wzrdbrain.src.js:" | 
|  | 63 | +          head -n 60 src/wzrdbrain/wzrdbrain.src.js || true | 
|  | 64 | +      - name: Detect changes in generated file | 
|  | 65 | +        id: diff | 
|  | 66 | +        shell: bash | 
|  | 67 | +        run: | | 
|  | 68 | +          # Determine if src/wzrdbrain/wzrdbrain.src.js is new or modified | 
|  | 69 | +          if git ls-files --error-unmatch src/wzrdbrain/wzrdbrain.src.js >/dev/null 2>&1; then | 
|  | 70 | +            if git diff --quiet -- src/wzrdbrain/wzrdbrain.src.js; then | 
|  | 71 | +              echo "changed=false" >> "$GITHUB_OUTPUT" | 
|  | 72 | +            else | 
|  | 73 | +              echo "changed=true" >> "$GITHUB_OUTPUT" | 
|  | 74 | +            fi | 
|  | 75 | +          else | 
|  | 76 | +            if [ -f src/wzrdbrain/wzrdbrain.src.js ]; then | 
|  | 77 | +              echo "changed=true" >> "$GITHUB_OUTPUT" | 
|  | 78 | +            else | 
|  | 79 | +              echo "changed=false" >> "$GITHUB_OUTPUT" | 
|  | 80 | +            fi | 
|  | 81 | +          fi | 
|  | 82 | +
 | 
|  | 83 | +      - name: Upload artifact for review | 
|  | 84 | +        uses: actions/upload-artifact@v4 | 
|  | 85 | +        with: | 
|  | 86 | +          name: wzrdbrain-js | 
|  | 87 | +          path: src/wzrdbrain/wzrdbrain.src.js | 
|  | 88 | + | 
|  | 89 | +      - name: Commit generated file to working branch | 
|  | 90 | +        if: steps.diff.outputs.changed == 'true' | 
|  | 91 | +        run: | | 
|  | 92 | +          branch="${{ github.ref_name }}" | 
|  | 93 | +          git config user.name "github-actions[bot]" | 
|  | 94 | +          git config user.email "github-actions[bot]@users.noreply.github.com" | 
|  | 95 | +          git checkout -B "$branch" | 
|  | 96 | +          git add src/wzrdbrain/wzrdbrain.src.js | 
|  | 97 | +          git commit -m "chore: update src/wzrdbrain/wzrdbrain.src.js via utils/translate2js.py [skip ci]" | 
|  | 98 | +          git push origin "$branch" | 
0 commit comments