|
| 1 | +pipeline: |
| 2 | + name: python-client |
| 3 | + identifier: pythonclient |
| 4 | + projectIdentifier: Harness_Split |
| 5 | + orgIdentifier: PROD |
| 6 | + tags: |
| 7 | + ai_generated: "true" |
| 8 | + properties: |
| 9 | + ci: |
| 10 | + codebase: |
| 11 | + connectorRef: <+input> |
| 12 | + repoName: <+input> |
| 13 | + build: <+input> |
| 14 | + variables: |
| 15 | + - name: sonarqube_token |
| 16 | + type: Secret |
| 17 | + value: <+secrets.getValue('sonarqube-token')> |
| 18 | + - name: github_token |
| 19 | + type: Secret |
| 20 | + value: <+secrets.getValue('github-devops-token')> |
| 21 | + stages: |
| 22 | + - stage: |
| 23 | + name: Build and Test |
| 24 | + identifier: ci_stage |
| 25 | + type: CI |
| 26 | + spec: |
| 27 | + cloneCodebase: true |
| 28 | + runtime: |
| 29 | + type: Cloud |
| 30 | + spec: |
| 31 | + size: medium |
| 32 | + nestedVirtualization: true |
| 33 | + platform: |
| 34 | + os: Linux |
| 35 | + arch: Amd64 |
| 36 | + execution: |
| 37 | + steps: |
| 38 | + - step: |
| 39 | + timeout: 30m |
| 40 | + type: Test |
| 41 | + name: Run Python Tests |
| 42 | + identifier: run_tests |
| 43 | + spec: |
| 44 | + connectorRef: account.harnessImage |
| 45 | + image: python:3.7.16-alpine |
| 46 | + shell: Sh |
| 47 | + command: |- |
| 48 | + apk update |
| 49 | + apk add --no-cache krb5-dev musl-dev libffi-dev build-base |
| 50 | +
|
| 51 | + # Run pytest with JUnit XML report output |
| 52 | + cd /harness |
| 53 | + pip install --upgrade pip |
| 54 | + pip install -U setuptools pip wheel |
| 55 | + pip install Cython==3.0.12 |
| 56 | + pip install aiohttp==3.8.4 |
| 57 | + pip install cryptography==45.0.7 |
| 58 | + pip install pycparser==2.21 |
| 59 | +
|
| 60 | + apk add redis |
| 61 | + redis-server /etc/redis.conf & |
| 62 | +
|
| 63 | + pip install redis==5.0.8 |
| 64 | + python setup.py test |
| 65 | + envVariables: |
| 66 | + PYTHONPATH: ${PYTHONPATH}:. |
| 67 | + PYTEST_ADDOPTS: "--verbose" |
| 68 | + - step: |
| 69 | + type: Run |
| 70 | + name: Install and Run SonarQube Scanner |
| 71 | + identifier: install_sonarqube_scanner |
| 72 | + spec: |
| 73 | + connectorRef: account.harnessImage |
| 74 | + image: sonarsource/sonar-scanner-cli |
| 75 | + shell: Bash |
| 76 | + command: | |
| 77 | + cd /harness |
| 78 | + if [ "<+codebase.prNumber>" != "" ]; then |
| 79 | + echo "Pull Request Analysis" |
| 80 | + sonar-scanner -X \ |
| 81 | + -Dsonar.host.url=https://sonar.harness.io \ |
| 82 | + -Dsonar.token=<+secrets.getValue('sonarqube-token')> \ |
| 83 | + -Dsonar.projectKey=python-client \ |
| 84 | + -Dsonar.scanner.skipJreProvisioning=true \ |
| 85 | + -Dsonar.pullrequest.key=<+codebase.prNumber> \ |
| 86 | + -Dsonar.pullrequest.branch=<+codebase.sourceBranch> \ |
| 87 | + -Dsonar.pullrequest.base=<+codebase.targetBranch> \ |
| 88 | + -Dsonar.scanner.skipSystemTruststore=true |
| 89 | + else |
| 90 | + echo "Branch Analysis" |
| 91 | + sonar-scanner \ |
| 92 | + -Dsonar.host.url=https://sonar.harness.io \ |
| 93 | + -Dsonar.token=<+secrets.getValue('sonarqube-token')> \ |
| 94 | + -Dsonar.projectKey=python-client \ |
| 95 | + -Dsonar.scanner.skipJreProvisioning=true \ |
| 96 | + -Dsonar.branch.name=<+codebase.branch> \ |
| 97 | + -Dsonar.scanner.skipSystemTruststore=true |
| 98 | + fi |
| 99 | + envVariables: |
| 100 | + SONAR_TOKEN: <+pipeline.variables.sonarqube_token> |
| 101 | + outputVariables: |
| 102 | + - name: SONAR_SCANNER_PATH |
| 103 | + timeout: 10m |
| 104 | + - step: |
| 105 | + type: Run |
| 106 | + name: Post Quality Gate to GitHub |
| 107 | + identifier: Post_Quality_Gate_to_GitHub |
| 108 | + spec: |
| 109 | + shell: Sh |
| 110 | + command: |- |
| 111 | + # Get SonarQube quality gate status |
| 112 | + curl -u <+secrets.getValue('sonarqube-token')>: \ |
| 113 | + -s "https://sonar.harness.io/api/qualitygates/project_status?projectKey=python-client&pullRequest=${<+codebase.prNumber>}" |
| 114 | +
|
| 115 | + curl -u <+secrets.getValue('sonarqube-token')>: -s 'https://sonar.harness.io/api/qualitygates/project_status?projectKey=python-client&pullRequest=${<+codebase.prNumber>}' | jq -r .projectStatus.status |
| 116 | +
|
| 117 | + QUALITY_GATE_STATUS=$(curl -u <+secrets.getValue('sonarqube-token')>: -s 'https://sonar.harness.io/api/qualitygates/project_status?projectKey=python-client&pullRequest=${<+codebase.prNumber>}' | jq -r .projectStatus.status) |
| 118 | +
|
| 119 | + echo "QUALITY_GATE_STATUS: $QUALITY_GATE_STATUS" |
| 120 | +
|
| 121 | + # Set GitHub status based on quality gate |
| 122 | + if [ "$QUALITY_GATE_STATUS" = "OK" ]; then |
| 123 | + STATE="success" |
| 124 | + DESCRIPTION="SonarQube Quality Gate passed" |
| 125 | + else |
| 126 | + STATE="failure" |
| 127 | + DESCRIPTION="SonarQube Quality Gate failed" |
| 128 | + fi |
| 129 | +
|
| 130 | + # Post status to GitHub |
| 131 | + curl -X POST \ |
| 132 | + -H "Authorization: token ${<+secrets.getValue('github-devops-token')>}" \ |
| 133 | + -H "Content-Type: application/json" \ |
| 134 | + -d "{ |
| 135 | + \"state\": \"${STATE}\", |
| 136 | + \"description\": \"${DESCRIPTION}\", |
| 137 | + \"context\": \"sonarqube/qualitygate\", |
| 138 | + \"target_url\": \"https://sonar.harness.io/dashboard?id=python-client&pullRequest=${<+codebase.prNumber>}\" |
| 139 | + }" \ |
| 140 | + "https://api.github.com/repos/splitio/python-client/statuses/<+codebase.commitSha>" |
| 141 | + rollbackSteps: [] |
| 142 | + rollbackSteps: [] |
| 143 | + caching: |
| 144 | + enabled: false |
| 145 | + paths: [] |
| 146 | + buildIntelligence: |
| 147 | + enabled: false |
| 148 | + description: "" |
| 149 | + description: This pipeline was updated by Harness AI on 2026-02-04 05:22:48 UTC by Bilal Al-Shahwany. |
0 commit comments