|
| 1 | +name: Code Quality |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + pull_request: |
| 8 | + types: [opened, synchronize, reopened, ready_for_review] |
| 9 | + pull_request_target: |
| 10 | + types: [opened, synchronize, reopened, ready_for_review] # added for fork PRs |
| 11 | + workflow_dispatch: |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + |
| 16 | +jobs: |
| 17 | + build: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + permissions: |
| 20 | + contents: read |
| 21 | + pull-requests: read |
| 22 | + strategy: |
| 23 | + fail-fast: false |
| 24 | + matrix: |
| 25 | + include: |
| 26 | + - python-version: 3.10.9 |
| 27 | + toxenv: py310,style,coverage-ci |
| 28 | + - python-version: 3.11 |
| 29 | + toxenv: py311,style,coverage-ci |
| 30 | + - python-version: 3.12 |
| 31 | + toxenv: py312,style,coverage-ci |
| 32 | + |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 |
| 35 | + with: |
| 36 | + submodules: recursive |
| 37 | + fetch-depth: 0 # shallow clones should be disabled for analysis |
| 38 | + |
| 39 | + - name: Setup python |
| 40 | + uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c |
| 41 | + with: |
| 42 | + python-version: ${{ matrix.python-version }} |
| 43 | + |
| 44 | + - name: Setup Node.js |
| 45 | + uses: actions/setup-node@v3 |
| 46 | + with: |
| 47 | + node-version: '20' |
| 48 | + |
| 49 | + - name: Install dependencies |
| 50 | + run: | |
| 51 | + pip install --upgrade virtualenv |
| 52 | + pip install tox |
| 53 | + npm --prefix plugins/magma install |
| 54 | + npm --prefix plugins/magma run build |
| 55 | +
|
| 56 | + - name: Run tests |
| 57 | + env: |
| 58 | + TOXENV: ${{ matrix.toxenv }} |
| 59 | + run: tox |
| 60 | + |
| 61 | + # --- Sonar scan for pushes and same-repo PRs only --- |
| 62 | + - name: SonarQube Scan |
| 63 | + if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false }} |
| 64 | + uses: SonarSource/sonarqube-scan-action@v6.0.0 |
| 65 | + env: |
| 66 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # needed for PR info |
| 67 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 68 | + # Uncomment if your sonar-project.properties is in a subfolder: |
| 69 | + # with: |
| 70 | + # args: | |
| 71 | + # -Dsonar.projectBaseDir=caldera |
| 72 | + |
| 73 | + # --- Sonar scan for forked PRs (runs safely with pull_request_target) --- |
| 74 | + sonar_fork_pr: |
| 75 | + runs-on: ubuntu-latest |
| 76 | + if: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.fork }} |
| 77 | + permissions: |
| 78 | + contents: read |
| 79 | + pull-requests: write # remove if you don't want PR comments |
| 80 | + steps: |
| 81 | + - name: Checkout base repo |
| 82 | + uses: actions/checkout@v4 |
| 83 | + with: |
| 84 | + ref: ${{ github.event.pull_request.base.sha }} |
| 85 | + fetch-depth: 0 |
| 86 | + |
| 87 | + - name: Checkout PR HEAD (fork) |
| 88 | + uses: actions/checkout@v4 |
| 89 | + with: |
| 90 | + repository: ${{ github.event.pull_request.head.repo.full_name }} |
| 91 | + ref: ${{ github.event.pull_request.head.sha }} |
| 92 | + path: pr |
| 93 | + fetch-depth: 0 |
| 94 | + submodules: recursive |
| 95 | + |
| 96 | + # Detect where the sonar-project.properties actually is (pr/ or pr/caldera) |
| 97 | + - name: Detect Sonar base dir |
| 98 | + id: detect |
| 99 | + run: | |
| 100 | + set -euo pipefail |
| 101 | + if [ -f pr/caldera/sonar-project.properties ]; then |
| 102 | + echo "base=pr/caldera" >> "$GITHUB_OUTPUT" |
| 103 | + elif [ -f pr/sonar-project.properties ]; then |
| 104 | + echo "base=pr" >> "$GITHUB_OUTPUT" |
| 105 | + else |
| 106 | + echo "No sonar-project.properties found under pr/ or pr/caldera" |
| 107 | + echo "base=pr" >> "$GITHUB_OUTPUT" # fallback to repo root |
| 108 | + fi |
| 109 | + echo "Using base dir: $(grep '^base=' "$GITHUB_OUTPUT" | cut -d= -f2)" |
| 110 | + echo "Has SONAR_TOKEN? $([ -n "${SONAR_TOKEN:-}" ] && echo yes || echo no)" |
| 111 | + env: |
| 112 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 113 | + |
| 114 | + # If your project key/org are NOT in the properties file, uncomment and set below |
| 115 | + - name: SonarQube Scan (fork PR) |
| 116 | + uses: SonarSource/sonarqube-scan-action@v6.0.0 |
| 117 | + env: |
| 118 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 119 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 120 | + # SONAR_HOST_URL: https://sonarcloud.io # set if you’re self-hosted or non-default |
| 121 | + with: |
| 122 | + projectBaseDir: ${{ steps.detect.outputs.base }} |
| 123 | + args: | |
| 124 | + -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} |
| 125 | + -Dsonar.pullrequest.branch=${{ github.event.pull_request.head.ref }} |
| 126 | + -Dsonar.pullrequest.base=${{ github.event.pull_request.base.ref }} |
0 commit comments