-
Notifications
You must be signed in to change notification settings - Fork 0
Features/fix bug in autoregisterserviceattribute detection code generation #4
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
Features/fix bug in autoregisterserviceattribute detection code generation #4
Conversation
…rator - Updated tests for ServiceRegistrationGenerator to improve readability and maintainability. - Ensured generated source code matches expected output for various scenarios including default scoped registration, singleton lifetime, and self-registration. - Added tests to verify behavior for classes without interfaces and those with multiple interfaces without specified registration. - Refactored StrongIdGenerator tests to ensure correct generation of partial structs with ID properties for specified types. - Improved CompilationHelpers for better attribute handling in tests. - Cleaned up formatting and organization of test files for consistency.
| name: Build and analyze | ||
| runs-on: windows-latest | ||
| env: | ||
| SONAR_PROJECT: 'astar-dev-source-generators' | ||
| ProjectName: 'AStar.Dev.Source.Generators' | ||
| RepositoryName: 'astar-dev-source-generators' | ||
| steps: | ||
| - name: Set up JDK | ||
| uses: actions/[email protected] | ||
| with: | ||
| java-version: 17 | ||
| distribution: 'zulu' | ||
| - name: Checkout | ||
| uses: actions/[email protected] | ||
| with: | ||
| fetch-depth: 0 | ||
| - name: 🛠 Cache SonarQube Cloud packages | ||
| uses: actions/[email protected] | ||
| with: | ||
| path: ~\sonar\cache | ||
| key: ${{ runner.os }}-sonar | ||
| restore-keys: ${{ runner.os }}-sonar | ||
| - name: 🛠 Cache SonarQube Cloud scanner | ||
| id: cache-sonar-scanner | ||
| uses: actions/[email protected] | ||
| with: | ||
| path: .\.sonar\scanner | ||
| key: ${{ runner.os }}-sonar-scanner | ||
| restore-keys: ${{ runner.os }}-sonar-scanner | ||
| - name: 🛠 Install SonarQube Cloud scanner | ||
| if: steps.cache-sonar-scanner.outputs.cache-hit != 'true' | ||
| shell: powershell | ||
| run: | | ||
| New-Item -Path .\.sonar\scanner -ItemType Directory | ||
| dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner | ||
| - name: 🔍 Restore, 🛠 Build and 🧪 Test with ☁️ SonarCloud / Qube | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
| shell: powershell | ||
| run: | | ||
| dotnet tool install --global dotnet-coverage | ||
| .\.sonar\scanner\dotnet-sonarscanner begin /k:"astar-development_${{ env.SONAR_PROJECT }}" /o:"astar-development" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml /d:sonar.scanner.scanAll=false /d:sonar.scanner.skipJreProvisioning=true | ||
| dotnet build --configuration Release | ||
| dotnet-coverage collect 'dotnet test --filter "FullyQualifiedName!~Tests.EndToEnd"' -f xml -o 'coverage.xml' | ||
| .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" |
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 12 days ago
To fix the problem, explicitly declare minimal GITHUB_TOKEN permissions for the workflow or the build job. Since the job only checks out and reads code and uses GITHUB_TOKEN for Sonar/SonarCloud integration (not to write to the repo), we can safely limit permissions to contents: read. Declaring permissions at the workflow root applies to all jobs, and there is only one job here, so adding a root-level block is the simplest and least invasive fix.
The best fix is:
- Add a
permissions:block near the top of.github/workflows/dotnet.yml, at the root level (same indentation ason:andjobs:). - Set
contents: readas a minimal baseline. If later you discover this workflow must update PRs or commit statuses, you can extend this block accordingly.
Concretely:
- In
.github/workflows/dotnet.yml, betweenname: .NET(line 1) andon:(line 3), insert:
permissions:
contents: readNo additional imports, methods, or definitions are needed, as this is purely a YAML configuration change.
-
Copy modified lines R3-R5
| @@ -1,5 +1,8 @@ | ||
| name: .NET | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| push: |
|



No description provided.