Skip to content

Commit 6131f20

Browse files
committed
fix(workflow): preserve newlines in ONLY_FILES for filenames with spaces
The previous workflow converted newlines to spaces using tr, but the Python script splits by newlines. Filenames with spaces (e.g., 'Introduction to Airflow in Python.md') were being parsed incorrectly. Now ONLY_FILES preserves newline separation for proper parsing.
1 parent 46958e3 commit 6131f20

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

.github/workflows/translate-to-english.yml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,45 @@ jobs:
2222
- name: Get changed blog posts
2323
id: changes
2424
run: |
25-
POSTS=$(git diff --name-only HEAD~1 HEAD -- 'src/content/blog/*.md' | tr '\n' ' ')
26-
echo "posts=$POSTS" >> $GITHUB_OUTPUT
27-
echo "Changed posts: $POSTS"
25+
POSTS=$(git diff --name-only HEAD~1 HEAD -- 'src/content/blog/*.md')
26+
if [ -n "$POSTS" ]; then
27+
echo "has_posts=true" >> $GITHUB_OUTPUT
28+
echo "Changed posts:"
29+
echo "$POSTS"
30+
else
31+
echo "has_posts=false" >> $GITHUB_OUTPUT
32+
echo "No changed posts"
33+
fi
2834
2935
- name: Set ONLY_FILES env
30-
if: steps.changes.outputs.posts != ''
36+
if: steps.changes.outputs.has_posts == 'true'
3137
run: |
3238
echo 'ONLY_FILES<<EOF' >> $GITHUB_ENV
33-
echo '${{ steps.changes.outputs.posts }}' >> $GITHUB_ENV
39+
git diff --name-only HEAD~1 HEAD -- 'src/content/blog/*.md' >> $GITHUB_ENV
3440
echo 'EOF' >> $GITHUB_ENV
3541
3642
- name: Set up Python
37-
if: steps.changes.outputs.posts != ''
43+
if: steps.changes.outputs.has_posts == 'true'
3844
uses: actions/setup-python@v5
3945
with:
4046
python-version: '3.11'
4147

4248
- name: Install dependencies
43-
if: steps.changes.outputs.posts != ''
49+
if: steps.changes.outputs.has_posts == 'true'
4450
run: |
4551
python -m pip install --upgrade pip
4652
pip install openai PyYAML python-frontmatter
4753
4854
- name: Generate English translations
49-
if: steps.changes.outputs.posts != ''
55+
if: steps.changes.outputs.has_posts == 'true'
5056
env:
5157
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
5258
TRANSLATION_MODEL: ${{ vars.TRANSLATION_MODEL }}
5359
run: |
5460
python scripts/translate_to_en.py
5561
5662
- name: Commit and push translations
57-
if: steps.changes.outputs.posts != ''
63+
if: steps.changes.outputs.has_posts == 'true'
5864
uses: stefanzweifel/git-auto-commit-action@v5
5965
with:
6066
commit_message: "chore: add English translations"

0 commit comments

Comments
 (0)