Fix YAML syntax error in workflow file#11277
Fix YAML syntax error in workflow file#11277sensei-hacker merged 1 commit intoiNavFlight:maintenance-9.xfrom
Conversation
Replace JavaScript template literals with string concatenation to avoid YAML parser confusion with template literal interpolation syntax. GitHub Actions YAML parser can misinterpret template literal dollar-brace syntax as expression delimiters.
a7252d3
into
iNavFlight:maintenance-9.x
PR Compliance Guide 🔍All compliance sections have been disabled in the configurations. |
There was a problem hiding this comment.
High-level Suggestion
To improve readability and maintainability, move the complex JavaScript logic from the inline script in the YAML workflow into a separate .js file. This avoids YAML parsing issues and separates code from configuration. [High-level, importance: 8]
Solution Walkthrough:
Before:
# in .github/workflows/pg-version-check.yml
- name: Post comment if issues found
if: steps.pg_check.outputs.exit_code == '1'
uses: actions/github-script@v7
with:
script: |
const output = '${{ steps.pg_check.outputs.output }}';
// ... logic to parse issues ...
const commentBody = '## ⚠️ Parameter Group Version Check\n\n' +
'The following parameter groups may need version increments:\n\n' +
issuesContent + '\n\n' +
'**Why this matters:**\n' +
// ... more concatenated strings ...
'*This is an automated check...*';
// ... logic to post comment ...
After:
# in .github/workflows/pg-version-check.yml
- name: Post comment if issues found
if: steps.pg_check.outputs.exit_code == '1'
uses: actions/github-script@v7
with:
script: |
const postCommentScript = require('./.github/scripts/post-comment.js');
await postCommentScript({
github,
context,
output: '${{ steps.pg_check.outputs.output }}'
});
# in .github/scripts/post-comment.js (new file)
module.exports = async ({ github, context, output }) => {
// ... logic to parse issues ...
const commentBody = `## ⚠️ Parameter Group Version Check
...
${issuesContent}
...`;
// ... logic to post comment ...
};
| script: | | ||
| // Use the captured output from the previous step | ||
| const output = `${{ steps.pg_check.outputs.output }}`; | ||
| const output = '${{ steps.pg_check.outputs.output }}'; |
There was a problem hiding this comment.
Suggestion: To prevent potential syntax errors, pass the step output to the script via an environment variable instead of string interpolation. This requires adding an env block to the step and accessing it with process.env. [general, importance: 7]
| const output = '${{ steps.pg_check.outputs.output }}'; | |
| const output = process.env.STEP_OUTPUT; |
| const commentBody = '## ⚠️ Parameter Group Version Check\n\n' + | ||
| 'The following parameter groups may need version increments:\n\n' + | ||
| issuesContent + '\n\n' + | ||
| '**Why this matters:**\n' + | ||
| 'Modifying PG struct fields without incrementing the version can cause settings corruption when users flash new firmware. The `pgLoad()` function validates versions and will use defaults if there\'s a mismatch, preventing corruption.\n\n' + | ||
| '**When to increment the version:**\n' + | ||
| '- ✅ Adding/removing fields\n' + | ||
| '- ✅ Changing field types or sizes\n' + | ||
| '- ✅ Reordering fields\n' + | ||
| '- ✅ Adding/removing packing attributes\n' + | ||
| '- ❌ Only changing default values in `PG_RESET_TEMPLATE`\n' + | ||
| '- ❌ Only changing comments\n\n' + | ||
| '**Reference:**\n' + | ||
| '- [Parameter Group Documentation](../docs/development/parameter_groups/)\n' + | ||
| '- Example: [PR #11236](https://github.com/iNavFlight/inav/pull/11236) (field removal requiring version increment)\n\n' + | ||
| '---\n' + | ||
| '*This is an automated check. False positives are possible. If you believe the version increment is not needed, please explain in a comment.*'; |
There was a problem hiding this comment.
Suggestion: Refactor the commentBody string concatenation into an array of strings, then use .join('\n') to construct the final message. This improves readability and maintainability. [general, importance: 6]
| const commentBody = '## ⚠️ Parameter Group Version Check\n\n' + | |
| 'The following parameter groups may need version increments:\n\n' + | |
| issuesContent + '\n\n' + | |
| '**Why this matters:**\n' + | |
| 'Modifying PG struct fields without incrementing the version can cause settings corruption when users flash new firmware. The `pgLoad()` function validates versions and will use defaults if there\'s a mismatch, preventing corruption.\n\n' + | |
| '**When to increment the version:**\n' + | |
| '- ✅ Adding/removing fields\n' + | |
| '- ✅ Changing field types or sizes\n' + | |
| '- ✅ Reordering fields\n' + | |
| '- ✅ Adding/removing packing attributes\n' + | |
| '- ❌ Only changing default values in `PG_RESET_TEMPLATE`\n' + | |
| '- ❌ Only changing comments\n\n' + | |
| '**Reference:**\n' + | |
| '- [Parameter Group Documentation](../docs/development/parameter_groups/)\n' + | |
| '- Example: [PR #11236](https://github.com/iNavFlight/inav/pull/11236) (field removal requiring version increment)\n\n' + | |
| '---\n' + | |
| '*This is an automated check. False positives are possible. If you believe the version increment is not needed, please explain in a comment.*'; | |
| const commentBody = [ | |
| '## ⚠️ Parameter Group Version Check', | |
| '', | |
| 'The following parameter groups may need version increments:', | |
| issuesContent, | |
| '', | |
| '**Why this matters:**', | |
| 'Modifying PG struct fields without incrementing the version can cause settings corruption when users flash new firmware. The `pgLoad()` function validates versions and will use defaults if there\'s a mismatch, preventing corruption.', | |
| '', | |
| '**When to increment the version:**', | |
| '- ✅ Adding/removing fields', | |
| '- ✅ Changing field types or sizes', | |
| '- ✅ Reordering fields', | |
| '- ✅ Adding/removing packing attributes', | |
| '- ❌ Only changing default values in `PG_RESET_TEMPLATE`', | |
| '- ❌ Only changing comments', | |
| '', | |
| '**Reference:**', | |
| '- [Parameter Group Documentation](../docs/development/parameter_groups/)', | |
| '- Example: [PR #11236](https://github.com/iNavFlight/inav/pull/11236)', | |
| '', | |
| '---', | |
| '*This is an automated check. False positives are possible. If you believe the version increment is not needed, please explain in a comment.*' | |
| ].join('\n'); |
User description
Replace JavaScript template literals with string concatenation to avoid YAML parser confusion with template literal interpolation syntax. GitHub Actions YAML parser can misinterpret template literal dollar-brace syntax as expression delimiters.
PR Type
Bug fix
Description
Replace template literals with string concatenation in GitHub Actions workflow
Avoid YAML parser confusion with template literal dollar-brace syntax
Fix potential expression delimiter misinterpretation by GitHub Actions
Diagram Walkthrough
File Walkthrough
pg-version-check.yml
Replace template literals with string concatenation.github/workflows/pg-version-check.yml
outputvariable withsingle-quoted string
commentBodyto stringconcatenation with explicit newline characters
syntax