ci: fetch Sonar token from Azure Key Vault via OIDC #42
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
| name: SonarCloud QA Gate | |
| on: | |
| workflow_dispatch: | |
| pull_request: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| sonarcloud: | |
| runs-on: ubuntu-latest | |
| environment: org-prod | |
| permissions: | |
| id-token: write | |
| contents: read | |
| pull-requests: write | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Azure login (OIDC) | |
| uses: azure/login@v2 | |
| with: | |
| client-id: ${{ vars.AZURE_CLIENT_ID }} | |
| tenant-id: ${{ vars.AZURE_TENANT_ID }} | |
| subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }} | |
| - name: Read SonarCloud token from Key Vault | |
| shell: bash | |
| run: | | |
| SONAR_TOKEN="$(az keyvault secret show \ | |
| --vault-name "${{ vars.AZURE_KEYVAULT_NAME }}" \ | |
| --name "sonar-cloud-token" \ | |
| --query value -o tsv)" | |
| echo "::add-mask::$SONAR_TOKEN" | |
| echo "SONAR_TOKEN=$SONAR_TOKEN" >> "$GITHUB_ENV" | |
| - uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.12' | |
| - name: Install dependencies | |
| run: make install-dev | |
| - name: Run tests with coverage | |
| run: make coverage-sonar | |
| - name: SonarCloud scan | |
| uses: SonarSource/sonarcloud-github-action@ffc3010689be73b8e5ae0c57ce35968afd7909e8 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| SONAR_TOKEN: ${{ env.SONAR_TOKEN }} | |
| with: | |
| args: > | |
| -Dsonar.host.url=https://sonarcloud.io | |
| -Dsonar.organization=codingworkflow | |
| -Dsonar.projectKey=codingworkflow_claude-code-api | |
| -Dsonar.python.coverage.reportPaths=dist/quality/coverage/coverage.xml | |
| -Dsonar.python.xunit.reportPath=dist/quality/sonar/xunit-report.xml | |
| -Dsonar.enableIssueAnnotation=true | |
| - name: SonarCloud quality gate | |
| uses: SonarSource/sonarqube-quality-gate-action@cf038b0e0cdecfa9e56c198bbb7d21d751d62c3b | |
| with: | |
| scanMetadataReportFile: dist/quality/sonar/scannerwork/report-task.txt | |
| env: | |
| SONAR_TOKEN: ${{ env.SONAR_TOKEN }} | |
| SONAR_HOST_URL: https://sonarcloud.io | |
| timeout-minutes: 5 |