-
Notifications
You must be signed in to change notification settings - Fork 2
Improve security reporting on PR builds with comprehensive checks, condensed UI, and parallel workflow execution #1096
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a2b06bc
Initial plan
Copilot c3fcac4
Add comprehensive security check system for PR builds
Copilot 64ff312
Add security check documentation and update .gitignore
Copilot ec713cf
Add visual examples and complete security check system
Copilot 3cca08f
Add implementation summary for security check system
Copilot b5d1a6c
Add comprehensive guide for additional security scanning tools
Copilot 5389ac6
Add comprehensive test suites for security check scripts
Copilot 01fd908
Add overlap analysis and integration recommendations
Copilot 9d77bda
Add detailed CodeQL explanation covering testing scope and methodology
Copilot 7da16ad
Remove duplicate npm audit and extract common PR comment management
Copilot 490e1f7
Addressing PR comments
Copilot 62050d4
Resolve merge conflict: Accept main's code-quality.yml for parallel e…
Copilot 5695e17
Merge branch 'main' into copilot/improve-security-reporting
litlfred 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| name: PR Security Check | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened] | ||
| branches: [main] | ||
| paths: | ||
| - 'src/**' | ||
| - 'public/**' | ||
| - 'package.json' | ||
| - 'package-lock.json' | ||
| - 'scripts/**' | ||
| - '.github/workflows/**' | ||
| # Also run on pushes to feature branches | ||
| push: | ||
| branches-ignore: | ||
| - main | ||
| - develop | ||
| - gh-pages | ||
| - deploy | ||
| paths: | ||
| - 'src/**' | ||
| - 'public/**' | ||
| - 'package.json' | ||
| - 'package-lock.json' | ||
| - 'scripts/**' | ||
| - '.github/workflows/**' | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| security-check: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v5 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v5 | ||
| with: | ||
| node-version: '20' | ||
| cache: 'npm' | ||
|
|
||
| - name: Get PR information | ||
| id: pr_info | ||
| uses: actions/github-script@v8 | ||
| with: | ||
| script: | | ||
| let prNumber = null; | ||
|
|
||
| if (context.payload.pull_request) { | ||
| // Direct PR event | ||
| prNumber = context.payload.pull_request.number; | ||
| } else if (context.eventName === 'push') { | ||
| // Push event - find associated PR | ||
| const branchName = context.ref.replace('refs/heads/', ''); | ||
| const { data: prs } = await github.rest.pulls.list({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| state: 'open', | ||
| head: `${context.repo.owner}:${branchName}` | ||
| }); | ||
|
|
||
| if (prs.length > 0) { | ||
| prNumber = prs[0].number; | ||
| } | ||
| } | ||
|
|
||
| console.log(`PR Number: ${prNumber}`); | ||
| core.setOutput('pr_number', prNumber || ''); | ||
|
|
||
| return prNumber; | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci --legacy-peer-deps | ||
| continue-on-error: false | ||
|
|
||
| - name: Run security checks | ||
| id: security_check | ||
| continue-on-error: true | ||
| run: | | ||
| echo "🔒 Running comprehensive security checks..." | ||
|
|
||
| # Run the security check script | ||
| node scripts/run-security-checks.js | ||
|
|
||
| # Capture exit code | ||
| exit_code=$? | ||
| echo "security_exit_code=$exit_code" >> $GITHUB_OUTPUT | ||
|
|
||
| # Always continue to format the comment even if checks fail | ||
| exit 0 | ||
|
|
||
| - name: Format security comment | ||
| id: format_comment | ||
| if: always() | ||
| run: | | ||
| echo "📝 Formatting security check results..." | ||
|
|
||
| # Check if results file exists | ||
| if [ -f "security-check-results.json" ]; then | ||
| node scripts/format-security-comment.js | ||
| echo "comment_available=true" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "⚠️ Security check results not found" | ||
| echo "comment_available=false" >> $GITHUB_OUTPUT | ||
| fi | ||
|
|
||
| - name: Update PR comment | ||
| if: always() && steps.pr_info.outputs.pr_number != '' && steps.format_comment.outputs.comment_available == 'true' | ||
| continue-on-error: true | ||
| run: | | ||
| python3 scripts/manage-security-comment.py \ | ||
| --token "${{ secrets.GITHUB_TOKEN }}" \ | ||
| --repo "${{ github.repository }}" \ | ||
| --pr "${{ steps.pr_info.outputs.pr_number }}" \ | ||
| --comment-file "security-comment.md" | ||
|
|
||
| - name: Set status check | ||
| if: always() && steps.pr_info.outputs.pr_number != '' | ||
| uses: actions/github-script@v8 | ||
| with: | ||
| script: | | ||
| const exitCode = '${{ steps.security_check.outputs.security_exit_code }}'; | ||
| const prNumber = '${{ steps.pr_info.outputs.pr_number }}'; | ||
|
|
||
| // Read results to get more details | ||
| const fs = require('fs'); | ||
| let summary = 'Security checks completed'; | ||
| let conclusion = 'success'; | ||
|
|
||
| try { | ||
| if (fs.existsSync('security-check-results.json')) { | ||
| const results = JSON.parse(fs.readFileSync('security-check-results.json', 'utf8')); | ||
| const s = results.summary; | ||
|
|
||
| if (s.failed > 0) { | ||
| conclusion = 'failure'; | ||
| summary = `Security issues found: ${s.failed} failed, ${s.warned} warnings`; | ||
| } else if (s.warned > 0) { | ||
| conclusion = 'neutral'; | ||
| summary = `Security warnings: ${s.warned} warnings, ${s.passed} passed`; | ||
| } else { | ||
| conclusion = 'success'; | ||
| summary = `All security checks passed: ${s.passed} checks`; | ||
| } | ||
| } | ||
| } catch (e) { | ||
| console.error('Error reading results:', e); | ||
| } | ||
|
|
||
| console.log(`Security check conclusion: ${conclusion}`); | ||
| console.log(`Summary: ${summary}`); | ||
|
|
||
| // Don't fail the workflow for warnings | ||
| if (conclusion === 'failure') { | ||
| core.setFailed(summary); | ||
| } | ||
|
|
||
| - name: Upload security results as artifact | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: security-check-results | ||
| path: | | ||
| security-check-results.json | ||
| security-comment.md | ||
| retention-days: 30 | ||
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
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.
The GitHub token is passed as a command line argument, which could potentially expose it in process lists or logs. Consider using environment variables instead:
env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}