Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 18 additions & 24 deletions .github/workflows/pg-version-check.yml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High-level Suggestion

To improve readability and maintainability, extract the inline JavaScript from the YAML workflow into a separate .js file. This avoids syntax conflicts and makes the script easier to manage. [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 }}';
      let issuesContent = '...';
      // ... 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' +
        '...';
      
      // ... 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 script = require('./.github/scripts/post-comment.js');
      await script({
        github, 
        context, 
        output: `${{ steps.pg_check.outputs.output }}`
      });

# in a new file .github/scripts/post-comment.js
module.exports = async ({ github, context, output }) => {
  let issuesContent = '...';
  // ... logic to parse issues from `output` ...
  const commentBody = `## ⚠️ Parameter Group Version Check

  The following parameter groups may need version increments:

  ${issuesContent}

  **Why this matters:**
  ...`;
  // ... logic to post comment ...
};

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
with:
script: |
// Use the captured output from the previous step
const output = `${{ steps.pg_check.outputs.output }}`;
const output = '${{ steps.pg_check.outputs.output }}';
let issuesContent = '';
Comment on lines +52 to 53
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Add a size/emptiness guard for output (GitHub comments have limits and step outputs can be empty/huge) and truncate or fall back before parsing/using it. [Learned best practice, importance: 6]

Suggested change
const output = '${{ steps.pg_check.outputs.output }}';
let issuesContent = '';
const rawOutput = '${{ steps.pg_check.outputs.output }}';
const MAX_OUTPUT_CHARS = 60000; // keep below GitHub comment limits
const output = (rawOutput ?? '').toString().slice(0, MAX_OUTPUT_CHARS);
let issuesContent = output.length ? '' : '*No output captured from pg_check step*';


try {
Expand All @@ -73,29 +73,23 @@ jobs:
issuesContent = '*Unable to extract detailed issues*';
}

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) (field removal requiring version increment)

---
*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\n\n' +
'The following parameter groups may need version increments:\n\n' +
issuesContent + '\n\n' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Wrap the issuesContent variable in a fenced code block to prevent unintended markdown formatting in the final comment. [general, importance: 6]

Suggested change
issuesContent + '\n\n' +
'```\n' + issuesContent + '\n```\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.*';

try {
// Check if we already commented
Expand Down
Loading