|
| 1 | +pipeline: |
| 2 | + name: ruby-client-repo |
| 3 | + identifier: rubyclientrepo |
| 4 | + projectIdentifier: Harness_Split |
| 5 | + orgIdentifier: PROD |
| 6 | + tags: {} |
| 7 | + properties: |
| 8 | + ci: |
| 9 | + codebase: |
| 10 | + connectorRef: fmegithubharnessgitops |
| 11 | + repoName: ruby-client |
| 12 | + build: |
| 13 | + type: branch |
| 14 | + spec: |
| 15 | + branch: <+input> |
| 16 | + stages: |
| 17 | + - stage: |
| 18 | + name: Build and Test |
| 19 | + identifier: Build_and_Test |
| 20 | + description: "" |
| 21 | + type: CI |
| 22 | + spec: |
| 23 | + cloneCodebase: true |
| 24 | + caching: |
| 25 | + enabled: true |
| 26 | + override: true |
| 27 | + platform: |
| 28 | + os: Linux |
| 29 | + arch: Amd64 |
| 30 | + runtime: |
| 31 | + type: Cloud |
| 32 | + spec: |
| 33 | + size: flex |
| 34 | + execution: |
| 35 | + steps: |
| 36 | + - step: |
| 37 | + type: Run |
| 38 | + name: Install Ruby |
| 39 | + identifier: Install_Ruby |
| 40 | + spec: |
| 41 | + shell: Bash |
| 42 | + command: |- |
| 43 | + curl https://mise.run | sh |
| 44 | + export PATH="$HOME/.local/bin:$PATH" |
| 45 | + mise use --global ruby@<+matrix.rubyVersion> |
| 46 | + ruby --version |
| 47 | + gem --version |
| 48 | + - step: |
| 49 | + type: Run |
| 50 | + name: Start Redis |
| 51 | + identifier: Start_Redis |
| 52 | + spec: |
| 53 | + shell: Sh |
| 54 | + command: |- |
| 55 | + apt-get install -y redis-server -qq |
| 56 | + redis-server --daemonize yes --port 6379 |
| 57 | + redis-cli ping |
| 58 | + - step: |
| 59 | + type: Run |
| 60 | + name: Wait for Redis |
| 61 | + identifier: Wait_for_Redis |
| 62 | + spec: |
| 63 | + shell: Sh |
| 64 | + command: |- |
| 65 | + for i in $(seq 1 15); do |
| 66 | + redis-cli ping && break |
| 67 | + echo "Waiting for Redis... attempt $i" |
| 68 | + sleep 1 |
| 69 | + done |
| 70 | + - step: |
| 71 | + type: Run |
| 72 | + name: Install Dependencies |
| 73 | + identifier: Install_Dependencies |
| 74 | + spec: |
| 75 | + shell: Bash |
| 76 | + command: |- |
| 77 | + export PATH="$HOME/.local/bin:$PATH" |
| 78 | + eval "$(mise activate bash)" |
| 79 | + gem install bundler:2.4.19 --no-document |
| 80 | + bundle install --jobs 4 --retry 3 |
| 81 | + - step: |
| 82 | + type: Run |
| 83 | + name: Run Tests |
| 84 | + identifier: Run_Tests |
| 85 | + spec: |
| 86 | + shell: Bash |
| 87 | + command: |- |
| 88 | + export PATH="$HOME/.local/bin:$PATH" |
| 89 | + eval "$(mise activate bash)" |
| 90 | + bundle exec rake |
| 91 | + - step: |
| 92 | + type: Run |
| 93 | + name: Fix Coverage Paths |
| 94 | + identifier: Fix_Coverage_Paths |
| 95 | + when: |
| 96 | + stageStatus: Success |
| 97 | + condition: <+matrix.rubyVersion> == "3.2.2" |
| 98 | + spec: |
| 99 | + shell: Bash |
| 100 | + command: |- |
| 101 | + export PATH="$HOME/.local/bin:$PATH" |
| 102 | + eval "$(mise activate bash)" |
| 103 | + cd coverage |
| 104 | + sed -i "s@${HARNESS_WORKSPACE}@/harness/workspace/@g" .resultset.json |
| 105 | + ruby -rjson -e ' |
| 106 | + sqube = JSON.load(File.read(".resultset.json"))["RSpec"]["coverage"].transform_values {|lines| lines["lines"]} |
| 107 | + total = { "RSpec" => { "coverage" => sqube, "timestamp" => Time.now.to_i }} |
| 108 | + puts JSON.dump(total) |
| 109 | + ' > .resultset.sonarqube.json |
| 110 | + - step: |
| 111 | + type: Run |
| 112 | + name: SonarQube Scan |
| 113 | + identifier: SonarQube_Scan |
| 114 | + when: |
| 115 | + stageStatus: Success |
| 116 | + condition: <+matrix.rubyVersion> == "3.2.2" |
| 117 | + spec: |
| 118 | + shell: Sh |
| 119 | + command: |- |
| 120 | + export SONAR_SCANNER_VERSION=5.0.1.3006 |
| 121 | + curl -sSLo sonar-scanner.zip \ |
| 122 | + "https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${SONAR_SCANNER_VERSION}-linux.zip" |
| 123 | + unzip -q sonar-scanner.zip |
| 124 | + export PATH="$PWD/sonar-scanner-${SONAR_SCANNER_VERSION}-linux/bin:$PATH" |
| 125 | + apt-get install -y openjdk-17-jdk -qq |
| 126 | + sonar-scanner \ |
| 127 | + -Dsonar.projectKey=ruby-client \ |
| 128 | + -Dsonar.sources=lib \ |
| 129 | + -Dsonar.tests=spec \ |
| 130 | + -Dsonar.host.url=https://sonar.harness.io \ |
| 131 | + -Dsonar.token=<+secrets.getValue("sonarqube-token")> \ |
| 132 | + -Dsonar.ruby.coverage.reportPaths=coverage/.resultset.sonarqube.json \ |
| 133 | + -Dsonar.coverage.exclusions="spec/**,**/vendor/**" \ |
| 134 | + -Dsonar.exclusions="**/vendor/**,**/.git/**" |
| 135 | + - step: |
| 136 | + type: Run |
| 137 | + name: Post Quality Gate |
| 138 | + identifier: Post_Quality_Gate |
| 139 | + when: |
| 140 | + stageStatus: Success |
| 141 | + condition: <+matrix.rubyVersion> == "3.2.2" |
| 142 | + spec: |
| 143 | + shell: Bash |
| 144 | + command: |- |
| 145 | + #!/bin/bash |
| 146 | + set -e |
| 147 | +
|
| 148 | + SONAR_TOKEN="<+secrets.getValue("sonarqube-token")>" |
| 149 | + SONAR_URL="https://sonar.harness.io" |
| 150 | + SONAR_PROJECT_KEY="ruby-client" |
| 151 | + GITHUB_TOKEN="<+secrets.getValue("github-devops-token")>" |
| 152 | + GITHUB_REPO="ruby-client" |
| 153 | + COMMIT_SHA="<+codebase.commitSha>" |
| 154 | +
|
| 155 | + STATUS_JSON=$(curl -sf \ |
| 156 | + -H "Authorization: Bearer ${SONAR_TOKEN}" \ |
| 157 | + "${SONAR_URL}/api/qualitygates/project_status?projectKey=${SONAR_PROJECT_KEY}") |
| 158 | +
|
| 159 | + QG_STATUS=$(echo "$STATUS_JSON" | python3 -c "import sys,json; print(json.load(sys.stdin)['projectStatus']['status'])") |
| 160 | +
|
| 161 | + case "$QG_STATUS" in |
| 162 | + OK) GH_STATE="success"; DESCRIPTION="Quality gate passed" ;; |
| 163 | + ERROR) GH_STATE="failure"; DESCRIPTION="Quality gate failed" ;; |
| 164 | + WARN) GH_STATE="success"; DESCRIPTION="Quality gate passed with warnings" ;; |
| 165 | + *) GH_STATE="pending"; DESCRIPTION="Quality gate status unknown" ;; |
| 166 | + esac |
| 167 | +
|
| 168 | + TARGET_URL="${SONAR_URL}/dashboard?id=${SONAR_PROJECT_KEY}" |
| 169 | +
|
| 170 | + curl -sf -X POST \ |
| 171 | + -H "Authorization: token ${GITHUB_TOKEN}" \ |
| 172 | + -H "Accept: application/vnd.github.v3+json" \ |
| 173 | + -H "Content-Type: application/json" \ |
| 174 | + -d "{\"state\":\"${GH_STATE}\",\"description\":\"${DESCRIPTION}\",\"context\":\"sonarqube/quality-gate\",\"target_url\":\"${TARGET_URL}\"}" \ |
| 175 | + "https://api.github.com/repos/splitio/${GITHUB_REPO}/statuses/${COMMIT_SHA}" |
| 176 | +
|
| 177 | + echo "Posted SonarQube quality gate status: ${GH_STATE}" |
| 178 | + strategy: |
| 179 | + matrix: |
| 180 | + rubyVersion: |
| 181 | + - "2.7.8" |
| 182 | + - "3.2.2" |
0 commit comments