-
Notifications
You must be signed in to change notification settings - Fork 0
feat(ci): Phase 1-2 — label automation + CodeQL security scanning #8
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
2 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| --- | ||
| name: CodeQL | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| - dev | ||
| paths: | ||
| - "**.cs" | ||
| - "**.csproj" | ||
|
|
||
| pull_request: | ||
| branches: | ||
| - "**" | ||
|
|
||
| workflow_dispatch: | ||
|
|
||
| schedule: | ||
| - cron: "31 0 * * 5" | ||
|
|
||
| jobs: | ||
| analyze: | ||
| name: Analyze | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| actions: read | ||
| contents: read | ||
| security-events: write | ||
|
|
||
| env: | ||
| CI: true | ||
|
|
||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| language: ["csharp"] | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup .NET | ||
| uses: actions/setup-dotnet@v4 | ||
| with: | ||
| dotnet-version: '10.0.x' | ||
| dotnet-quality: 'preview' | ||
|
|
||
| - name: Initialize CodeQL | ||
| uses: github/codeql-action/init@v3 | ||
| with: | ||
| languages: ${{ matrix.language }} | ||
|
|
||
| - name: Autobuild | ||
| uses: github/codeql-action/autobuild@v3 | ||
|
|
||
| - name: Perform CodeQL Analysis | ||
| uses: github/codeql-action/analyze@v3 |
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,176 @@ | ||
| --- | ||
| name: Squad Label Enforce | ||
|
|
||
| on: | ||
| issues: | ||
| types: [labeled] | ||
|
|
||
| permissions: | ||
| issues: write | ||
| contents: read | ||
|
|
||
| jobs: | ||
| enforce: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Enforce mutual exclusivity | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const issue = context.payload.issue; | ||
| const appliedLabel = context.payload.label.name; | ||
|
|
||
| // Namespaces with mutual exclusivity rules | ||
| const EXCLUSIVE_PREFIXES = ['go:', 'release:', 'type:', 'priority:']; | ||
|
|
||
| // Skip if not a managed namespace label | ||
| if (!EXCLUSIVE_PREFIXES.some(p => appliedLabel.startsWith(p))) { | ||
| core.info(`Label ${appliedLabel} is not in a managed namespace — skipping`); | ||
| return; | ||
| } | ||
|
|
||
| const allLabels = issue.labels.map(l => l.name); | ||
|
|
||
| // Handle go: namespace (mutual exclusivity) | ||
| if (appliedLabel.startsWith('go:')) { | ||
| const otherGoLabels = allLabels.filter(l => | ||
| l.startsWith('go:') && l !== appliedLabel | ||
| ); | ||
|
|
||
| if (otherGoLabels.length > 0) { | ||
| for (const label of otherGoLabels) { | ||
| await github.rest.issues.removeLabel({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issue.number, | ||
| name: label | ||
| }); | ||
| core.info(`Removed conflicting label: ${label}`); | ||
| } | ||
|
|
||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issue.number, | ||
| body: `🏷️ Triage verdict updated → \`${appliedLabel}\`` | ||
| }); | ||
| } | ||
|
|
||
| if (appliedLabel === 'go:yes') { | ||
| const hasReleaseLabel = allLabels.some(l => l.startsWith('release:')); | ||
| if (!hasReleaseLabel) { | ||
| await github.rest.issues.addLabels({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issue.number, | ||
| labels: ['release:backlog'] | ||
| }); | ||
|
|
||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issue.number, | ||
| body: `📋 Marked as \`release:backlog\` — assign a release target when ready.` | ||
| }); | ||
|
|
||
| core.info('Applied release:backlog for go:yes issue'); | ||
| } | ||
| } | ||
|
|
||
| if (appliedLabel === 'go:no') { | ||
| const releaseLabels = allLabels.filter(l => l.startsWith('release:')); | ||
| if (releaseLabels.length > 0) { | ||
| for (const label of releaseLabels) { | ||
| await github.rest.issues.removeLabel({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issue.number, | ||
| name: label | ||
| }); | ||
| core.info(`Removed release label from go:no issue: ${label}`); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Handle release: namespace (mutual exclusivity) | ||
| if (appliedLabel.startsWith('release:')) { | ||
| const otherReleaseLabels = allLabels.filter(l => | ||
| l.startsWith('release:') && l !== appliedLabel | ||
| ); | ||
|
|
||
| if (otherReleaseLabels.length > 0) { | ||
| for (const label of otherReleaseLabels) { | ||
| await github.rest.issues.removeLabel({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issue.number, | ||
| name: label | ||
| }); | ||
| core.info(`Removed conflicting label: ${label}`); | ||
| } | ||
|
|
||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issue.number, | ||
| body: `🏷️ Release target updated → \`${appliedLabel}\`` | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| // Handle type: namespace (mutual exclusivity) | ||
| if (appliedLabel.startsWith('type:')) { | ||
| const otherTypeLabels = allLabels.filter(l => | ||
| l.startsWith('type:') && l !== appliedLabel | ||
| ); | ||
|
|
||
| if (otherTypeLabels.length > 0) { | ||
| for (const label of otherTypeLabels) { | ||
| await github.rest.issues.removeLabel({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issue.number, | ||
| name: label | ||
| }); | ||
| core.info(`Removed conflicting label: ${label}`); | ||
| } | ||
|
|
||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issue.number, | ||
| body: `🏷️ Issue type updated → \`${appliedLabel}\`` | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| // Handle priority: namespace (mutual exclusivity) | ||
| if (appliedLabel.startsWith('priority:')) { | ||
| const otherPriorityLabels = allLabels.filter(l => | ||
| l.startsWith('priority:') && l !== appliedLabel | ||
| ); | ||
|
|
||
| if (otherPriorityLabels.length > 0) { | ||
| for (const label of otherPriorityLabels) { | ||
| await github.rest.issues.removeLabel({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issue.number, | ||
| name: label | ||
| }); | ||
| core.info(`Removed conflicting label: ${label}`); | ||
| } | ||
|
|
||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issue.number, | ||
| body: `🏷️ Priority updated → \`${appliedLabel}\`` | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| core.info(`Label enforcement complete for ${appliedLabel}`); |
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,94 @@ | ||
| --- | ||
| name: Squad PR Auto-Label | ||
|
|
||
| on: | ||
| pull_request_target: | ||
| types: [opened, reopened, synchronize] | ||
|
|
||
| permissions: | ||
| pull-requests: write | ||
| contents: read | ||
|
|
||
| jobs: | ||
| auto-label: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Auto-label PR for squad system | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const pr = context.payload.pull_request; | ||
| const author = pr.user.login; | ||
|
|
||
| // Fetch current labels on the PR | ||
| const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: pr.number | ||
| }); | ||
|
|
||
| const labelNames = currentLabels.map(l => l.name); | ||
|
|
||
| // Check if already has squad labels | ||
| const hasSquadLabel = labelNames.some(name => | ||
| name === 'squad' || name.startsWith('squad:') | ||
| ); | ||
|
|
||
| if (hasSquadLabel) { | ||
| core.info(`PR #${pr.number} already has squad label(s) — skipping`); | ||
| return; | ||
| } | ||
|
|
||
| let labelsToAdd = []; | ||
| let commentBody = ''; | ||
|
|
||
| // Handle known automation bots | ||
| const knownBots = ['dependabot[bot]', 'renovate[bot]', 'github-actions[bot]']; | ||
| if (knownBots.includes(author)) { | ||
| labelsToAdd = ['squad:boromir', 'squad']; | ||
| commentBody = [ | ||
| `### 🤖 Dependency Update PR`, | ||
| '', | ||
| `This PR was opened by **${author}** and has been automatically labeled for **Boromir** (DevOps) to review.`, | ||
| '', | ||
| `**Labels applied:**`, | ||
| `- \`squad:boromir\` — Assigned to DevOps for dependency updates`, | ||
| `- \`squad\` — In triage queue`, | ||
| '', | ||
| `> Dependency and infrastructure updates are owned by the DevOps team.` | ||
| ].join('\n'); | ||
| } else { | ||
| // Handle general PRs without squad labels | ||
| labelsToAdd = ['squad']; | ||
| commentBody = [ | ||
| `### 🏗️ PR Added to Squad Triage Queue`, | ||
| '', | ||
| `This PR has been labeled with \`squad\` and added to the triage queue.`, | ||
| '', | ||
| `**Next steps:**`, | ||
| `- The squad Lead will review and assign to an appropriate team member`, | ||
| `- A \`squad:member\` label will be added after triage`, | ||
| '', | ||
| `> If you know which squad member should handle this, you can add the appropriate \`squad:member\` label yourself.` | ||
| ].join('\n'); | ||
| } | ||
|
|
||
| // Add labels | ||
| await github.rest.issues.addLabels({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: pr.number, | ||
| labels: labelsToAdd | ||
| }); | ||
|
|
||
| core.info(`Added labels to PR #${pr.number}: ${labelsToAdd.join(', ')}`); | ||
|
|
||
| // Post comment | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: pr.number, | ||
| body: commentBody | ||
| }); | ||
|
|
||
| core.info(`Posted auto-label comment on PR #${pr.number}`); | ||
Oops, something went wrong.
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 workflow uses
github.rest.issues.*APIs to list/add labels and create a comment on the PR, but the workflow-levelpermissionsblock does not grantissues: write(orissues: read). With onlypull-requests: write, these calls can fail with permission errors. Addissues: writeto the permissions (and consider droppingpull-requests: writeif it's not otherwise needed).