| name: Code Quality |
| |
| on: |
| push: |
| branches: |
| - master |
| pull_request: |
| types: [opened, synchronize, reopened, ready_for_review] |
| pull_request_target: |
| types: [opened, synchronize, reopened, ready_for_review] # added for fork PRs |
| workflow_dispatch: |
| |
| permissions: |
| contents: read |
| |
| jobs: |
| build: |
| runs-on: ubuntu-latest |
| permissions: |
| contents: read |
| pull-requests: read |
| strategy: |
| fail-fast: false |
| matrix: |
| include: |
| - python-version: 3.10.9 |
| toxenv: py310,style,coverage-ci |
| - python-version: 3.11 |
| toxenv: py311,style,coverage-ci |
| - python-version: 3.12 |
| toxenv: py312,style,coverage-ci |
| |
| steps: |
| - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 |
| with: |
| submodules: recursive |
| fetch-depth: 0 # shallow clones should be disabled for analysis |
| |
| - name: Setup python |
| uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c |
| with: |
| python-version: ${{ matrix.python-version }} |
| |
| - name: Setup Node.js |
| uses: actions/setup-node@v3 |
| with: |
| node-version: '20' |
| |
| - name: Install dependencies |
| run: | |
| pip install --upgrade virtualenv |
| pip install tox |
| npm --prefix plugins/magma install |
| npm --prefix plugins/magma run build |
| |
| - name: Run tests |
| env: |
| TOXENV: ${{ matrix.toxenv }} |
| run: tox |
| |
| # --- Sonar scan for pushes and same-repo PRs only --- |
| - name: SonarQube Scan |
| if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false }} |
| uses: SonarSource/sonarqube-scan-action@v6.0.0 |
| env: |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # needed for PR info |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| # Uncomment if your sonar-project.properties is in a subfolder: |
| # with: |
| # args: | |
| # -Dsonar.projectBaseDir=caldera |
| |
| # --- Sonar scan for forked PRs (runs safely with pull_request_target) --- |
| sonar_fork_pr: |
| runs-on: ubuntu-latest |
| if: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.fork }} |
| permissions: |
| contents: read |
| pull-requests: write # remove if you don't want PR comments |
| steps: |
| - name: Checkout base repo |
| uses: actions/checkout@v4 |
| with: |
| ref: ${{ github.event.pull_request.base.sha }} |
| fetch-depth: 0 |
| |
| - name: Checkout PR HEAD (fork) |
| uses: actions/checkout@v4 |
| with: |
| repository: ${{ github.event.pull_request.head.repo.full_name }} |
| ref: ${{ github.event.pull_request.head.sha }} |
| path: pr |
| fetch-depth: 0 |
| submodules: recursive |
| |
| # Detect where the sonar-project.properties actually is (pr/ or pr/caldera) |
| - name: Detect Sonar base dir |
| id: detect |
| run: | |
| set -euo pipefail |
| if [ -f pr/caldera/sonar-project.properties ]; then |
| echo "base=pr/caldera" >> "$GITHUB_OUTPUT" |
| elif [ -f pr/sonar-project.properties ]; then |
| echo "base=pr" >> "$GITHUB_OUTPUT" |
| else |
| echo "No sonar-project.properties found under pr/ or pr/caldera" |
| echo "base=pr" >> "$GITHUB_OUTPUT" # fallback to repo root |
| fi |
| echo "Using base dir: $(grep '^base=' "$GITHUB_OUTPUT" | cut -d= -f2)" |
| echo "Has SONAR_TOKEN? $([ -n "${SONAR_TOKEN:-}" ] && echo yes || echo no)" |
| env: |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| |
| # If your project key/org are NOT in the properties file, uncomment and set below |
| - name: SonarQube Scan (fork PR) |
| uses: SonarSource/sonarqube-scan-action@v6.0.0 |
| env: |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| # SONAR_HOST_URL: https://sonarcloud.io # set if you’re self-hosted or non-default |
| with: |
| projectBaseDir: ${{ steps.detect.outputs.base }} |
| args: | |
| -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} |
| -Dsonar.pullrequest.branch=${{ github.event.pull_request.head.ref }} |
| -Dsonar.pullrequest.base=${{ github.event.pull_request.base.ref }} |