Fix language parameter handling in news-article-generator workflow#172
Fix language parameter handling in news-article-generator workflow#172
Conversation
Co-authored-by: pethers <[email protected]>
Co-authored-by: pethers <[email protected]>
🔍 Lighthouse Performance Audit
📥 Download full Lighthouse report Budget Compliance: Performance budgets enforced via |
There was a problem hiding this comment.
Pull request overview
Improves multi-language generation reliability for the news article generator by fixing whitespace handling in CLI parsing and updating the agent workflow instructions/docs to consistently invoke the existing generation script with expanded language presets.
Changes:
- Trim whitespace when parsing
--typesand--languagesinscripts/generate-news-enhanced.js. - Update
.github/workflows/news-article-generator.mdagent instructions to expand language presets and rungenerate-news-enhanced.js, plus add a language coverage validation step. - Add a comprehensive manual testing guide for language options under
docs/.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| scripts/generate-news-enhanced.js | Trims CLI inputs for article types and languages to correctly handle lists like "no, da, fi". |
| .github/workflows/news-article-generator.md | Adds explicit bash examples for expanding presets and calling the generation script, plus language coverage validation guidance. |
| docs/LANGUAGE_OPTIONS_TESTING.md | Adds a manual test/validation playbook for language presets, whitespace edge cases, and RTL verification. |
scripts/generate-news-enhanced.js
Outdated
| } | ||
|
|
||
| const languages = languagesInput.split(',').filter(l => ALL_LANGUAGES.includes(l.trim())); | ||
| const languages = languagesInput.split(',').map(l => l.trim()).filter(l => ALL_LANGUAGES.includes(l)); |
There was a problem hiding this comment.
The preset expansion checks LANGUAGE_PRESETS[languagesInput] before trimming, so inputs like --languages="nordic " (or newline/space from workflow inputs) won’t expand and will later be filtered to zero valid languages. Normalize languagesInput (trim and ideally lowercase) before the preset lookup so whitespace doesn’t break presets.
There was a problem hiding this comment.
Fixed in 047eb4c. Added .trim().toLowerCase() to normalize languagesInput before preset lookup. Now handles "nordic ", " NORDIC ", and mixed case correctly.
| LANGUAGES_INPUT="${{ github.event.inputs.languages }}" | ||
| if [ -z "$LANGUAGES_INPUT" ]; then | ||
| LANGUAGES_INPUT="en,sv" | ||
| fi | ||
|
|
||
| # Expand language presets | ||
| case "$LANGUAGES_INPUT" in | ||
| "nordic") | ||
| LANG_ARG="en,sv,da,no,fi" | ||
| echo "🌍 Expanding 'nordic' to: $LANG_ARG" | ||
| ;; | ||
| "eu-core") |
There was a problem hiding this comment.
The languages preset case statement uses the raw LANGUAGES_INPUT. If the input contains leading/trailing whitespace, presets like nordic/eu-core won’t match and the script may fail later. Trim/normalize LANGUAGES_INPUT before the case so preset handling is robust.
There was a problem hiding this comment.
Fixed in 047eb4c. Added LANGUAGES_INPUT=$(echo "$LANGUAGES_INPUT" | xargs) before the case statement to trim whitespace. Presets now match reliably.
| for lang in "${LANG_ARRAY[@]}"; do | ||
| lang_trimmed=$(echo "$lang" | xargs) # Trim whitespace | ||
|
|
||
| # Count articles for this language | ||
| count=$(find news -name "*-${lang_trimmed}.html" -type f -mmin -10 | wc -l) | ||
|
|
||
| if [ $count -gt 0 ]; then | ||
| echo " ✅ $lang_trimmed: $count articles generated" | ||
| else | ||
| echo " ❌ $lang_trimmed: No articles found (expected at least 1)" | ||
| fi | ||
| done | ||
|
|
There was a problem hiding this comment.
This validation loop prints an error when a requested language has no generated articles, but it never fails the run. If this is meant to be a real validation gate, track missing languages and exit 1 when any are missing so the agent/workflow can’t proceed with partial output.
| for lang in "${LANG_ARRAY[@]}"; do | |
| lang_trimmed=$(echo "$lang" | xargs) # Trim whitespace | |
| # Count articles for this language | |
| count=$(find news -name "*-${lang_trimmed}.html" -type f -mmin -10 | wc -l) | |
| if [ $count -gt 0 ]; then | |
| echo " ✅ $lang_trimmed: $count articles generated" | |
| else | |
| echo " ❌ $lang_trimmed: No articles found (expected at least 1)" | |
| fi | |
| done | |
| # Track any languages that are missing articles | |
| missing_langs=() | |
| for lang in "${LANG_ARRAY[@]}"; do | |
| lang_trimmed=$(echo "$lang" | xargs) # Trim whitespace | |
| # Count articles for this language | |
| count=$(find news -name "*-${lang_trimmed}.html" -type f -mmin -10 | wc -l) | |
| if [ "$count" -gt 0 ]; then | |
| echo " ✅ $lang_trimmed: $count articles generated" | |
| else | |
| echo " ❌ $lang_trimmed: No articles found (expected at least 1)" | |
| missing_langs+=("$lang_trimmed") | |
| fi | |
| done | |
| # Fail the workflow if any requested languages are missing articles | |
| if [ "${#missing_langs[@]}" -ne 0 ]; then | |
| echo "❌ Validation failed: No articles generated for the following requested languages: ${missing_langs[*]}" | |
| exit 1 | |
| else | |
| echo "✅ Validation passed: Articles generated for all requested languages." | |
| fi |
There was a problem hiding this comment.
Fixed in 047eb4c. Implemented suggestion exactly as provided - now tracks missing_langs array and exits with exit 1 when any requested languages have zero articles. This creates a proper validation gate.
docs/LANGUAGE_OPTIONS_TESTING.md
Outdated
| if [ -f "news/$(ls -t news/*-${lang}.html 2>/dev/null | head -1)" ]; then | ||
| if grep -q 'dir="rtl"' "news/"*-${lang}.html; then |
There was a problem hiding this comment.
The file existence check is incorrect: ls -t news/*-${lang}.html already returns paths that include news/, so wrapping it with news/$(...) produces news/news/... and the -f test will fail even when files exist. Remove the extra news/ prefix or restructure the existence check.
| if [ -f "news/$(ls -t news/*-${lang}.html 2>/dev/null | head -1)" ]; then | |
| if grep -q 'dir="rtl"' "news/"*-${lang}.html; then | |
| if ls -t news/*-"$lang".html 1>/dev/null 2>&1; then | |
| if grep -q 'dir="rtl"' news/*-"$lang".html; then |
There was a problem hiding this comment.
Fixed in 047eb4c. Simplified to ls -t news/*-"$lang".html 1>/dev/null 2>&1 to avoid the double news/ prefix. File existence check now works correctly.
|
@copilot apply changes based on the comments in this thread |
Co-authored-by: pethers <[email protected]>
All 4 review comments addressed in commit 047eb4c:
Bonus: Also fixed same issues in |
🔍 Lighthouse Performance Audit
📥 Download full Lighthouse report Budget Compliance: Performance budgets enforced via |
DevOps Fix: Language Parameter Handling - Review Comments Addressed
Changes Made
1. ✅ Fixed Preset Expansion with Whitespace (Comment 2807597523)
File:
scripts/generate-news-enhanced.jsLANGUAGE_PRESETS[languagesInput]before trimming, so"nordic "(with trailing space) wouldn't match.trim().toLowerCase()before preset lookup on line 50"nordic "," NORDIC ","Nordic"correctly2. ✅ Fixed Bash Case Statement Matching (Comment 2807597529)
File:
.github/workflows/news-article-generator.mdcasestatement used rawLANGUAGES_INPUTwithout trimmingLANGUAGES_INPUT=$(echo "$LANGUAGES_INPUT" | xargs)before case statement (line 280)3. ✅ Added Validation Gate (Comment 2807597531)
File:
.github/workflows/news-article-generator.mdexit 1when any are missing (lines 521-535)4. ✅ Fixed File Existence Check (Comment 2807597535)
File:
docs/LANGUAGE_OPTIONS_TESTING.mdnews/$(ls -t news/*-${lang}.html ...)producednews/news/...pathls -t news/*-"$lang".html 1>/dev/null 2>&1(line 262)5. ✅ Bonus: Fixed Same Issues in Backport Script
File:
scripts/generate-news-backport.jsTesting Results
Test 1: Preset with Trailing Space
Test 2: Preset with Spaces and Uppercase
Test 3: Validation Gate
The validation now tracks missing languages and exits with error code 1, preventing incomplete article generation from being accepted.
Files Changed
scripts/generate-news-enhanced.jsscripts/generate-news-backport.js.github/workflows/news-article-generator.mddocs/LANGUAGE_OPTIONS_TESTING.mdNext Steps
All review comments addressed. Ready for re-review and merge.
Commit: Applying all 4 PR review comments
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.