Skip to content

Commit 37fe6f3

Browse files
committed
Refactor GitHub Actions workflow: consolidate translation steps into ci.yml and update output path for generated JavaScript file
1 parent b7b4736 commit 37fe6f3

File tree

3 files changed

+71
-87
lines changed

3 files changed

+71
-87
lines changed

.github/workflows/ci.yml

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
name: CI
2+
23
permissions:
3-
contents: read
4+
contents: write
5+
46
on:
57
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'
814

915
jobs:
1016
test:
@@ -29,3 +35,64 @@ jobs:
2935
run: mypy .
3036
- name: Tests (pytest)
3137
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"

.github/workflows/translate2js.yml

Lines changed: 0 additions & 83 deletions
This file was deleted.

utils/translate2js.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
PROJECT_ROOT = Path(__file__).resolve().parent.parent
1212
PYTHON_SOURCE_PATH = PROJECT_ROOT / "src" / "wzrdbrain" / "wzrdbrain.py"
1313
TRICK_DATA_PATH = PROJECT_ROOT / "src" / "wzrdbrain" / "tricks.json"
14-
JS_OUTPUT_PATH = PROJECT_ROOT / "dist" / "wzrdbrain.src.js"
14+
JS_OUTPUT_PATH = PROJECT_ROOT / "src" / "wzrdbrain" /"wzrdbrain.src.js"
1515
JS_SOURCE_PATH = PROJECT_ROOT / "utils" / "wzrdbrain.base.js"
1616
MODEL_NAME = "gemini-2.5-pro"
1717

0 commit comments

Comments
 (0)