-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix the PG version check so a detected issue is reported instead of failing the job #11967
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Raffi1202
wants to merge
3
commits into
iNavFlight:maintenance-10.x
Choose a base branch
from
Raffi1202:fix/pg-version-check-output-10x
base: maintenance-10.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+185
−89
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| name: Parameter Group Version Check Comment | ||
|
|
||
| # Posts the PG version warning comment from a privileged context so it also works | ||
| # for PRs opened from forks, whose pull_request GITHUB_TOKEN is read-only. The | ||
| # unprivileged "Parameter Group Version Check" workflow uploads the checker output | ||
| # and PR number as artifacts; this workflow only downloads them — it never executes | ||
| # pull-request code. | ||
| on: | ||
| workflow_run: | ||
| workflows: ["Parameter Group Version Check"] | ||
| types: [completed] | ||
|
|
||
| jobs: | ||
| comment: | ||
| runs-on: ubuntu-latest | ||
| # Only act on pull_request-triggered runs that succeeded (a checker error fails | ||
| # the check job, so its conclusion is not 'success'). | ||
| if: > | ||
| github.event.workflow_run.event == 'pull_request' && | ||
| github.event.workflow_run.conclusion == 'success' | ||
| permissions: | ||
| actions: read | ||
| issues: write | ||
| pull-requests: write | ||
|
|
||
| steps: | ||
| - name: Download PG check result | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: pg-check-result | ||
| run-id: ${{ github.event.workflow_run.id }} | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Post or update comment | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const fs = require('fs'); | ||
| const prNumber = Number(fs.readFileSync('pr_number.txt', 'utf8').trim()); | ||
| const output = fs.readFileSync('pg_output.txt', 'utf8'); | ||
|
|
||
| if (!output.includes('PG version issue:')) { | ||
| console.log('No PG version issues to report; nothing to do.'); | ||
| return; | ||
| } | ||
|
|
||
| let issuesContent = ''; | ||
|
|
||
| try { | ||
| // Extract issues from output (everything after the warning line) | ||
| const lines = output.split('\n'); | ||
| let capturing = false; | ||
| let issues = []; | ||
|
|
||
| for (const line of lines) { | ||
| if (line.includes('PG version issue:')) { | ||
| capturing = true; | ||
| } | ||
| if (capturing) { | ||
| issues.push(line); | ||
| } | ||
| } | ||
|
|
||
| issuesContent = issues.join('\n'); | ||
| } catch (err) { | ||
| console.log('Error capturing issues:', err); | ||
| issuesContent = '*Unable to extract detailed 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' + | ||
| '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 | ||
| const { data: comments } = await github.rest.issues.listComments({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: prNumber, | ||
| }); | ||
|
|
||
| const botComment = comments.find(comment => | ||
| comment.user.login === 'github-actions[bot]' && | ||
| comment.body.includes('Parameter Group Version Check') | ||
| ); | ||
|
|
||
| if (botComment) { | ||
| // Update existing comment | ||
| await github.rest.issues.updateComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| comment_id: botComment.id, | ||
| body: commentBody | ||
| }); | ||
| console.log('Updated existing PG version check comment'); | ||
| } else { | ||
| // Post new comment | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: prNumber, | ||
| body: commentBody | ||
| }); | ||
| console.log('Posted new PG version check comment'); | ||
| } | ||
| } catch (err) { | ||
| core.setFailed(`Failed to post comment: ${err}`); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. Attackers can redirect bot comments
🐞 Bug⛨ SecurityAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools