Skip to content

Commit d4b224c

Browse files
authored
Merge pull request #630 from splitio/harness-pipeline/FME-17651
ci: add Harness CI pipeline (FME-17651)
2 parents 0ef8a3a + 8f1a24a commit d4b224c

12 files changed

Lines changed: 650 additions & 223 deletions

File tree

.github/CODEOWNERS

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/pull_request_template.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 0 additions & 90 deletions
This file was deleted.

.github/workflows/update-license-year.yml

Lines changed: 0 additions & 45 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,5 @@ dump.rdb
5656
release.sh
5757

5858
.scannerwork
59+
docs
60+
examples
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
inputSet:
2+
name: ruby-client
3+
identifier: rubyclient
4+
orgIdentifier: PROD
5+
projectIdentifier: Harness_Split
6+
pipeline:
7+
identifier: rubyclientrepo
8+
properties:
9+
ci:
10+
codebase:
11+
build:
12+
type: PR
13+
spec:
14+
number: <+trigger.prNumber>

.harness/pipeline.yaml

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
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"

spec/engine/sync_manager_spec.rb

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,27 @@
9595

9696
it 'start sync manager with wrong sse host url and non connect to server, must start polling.' do
9797
ENV['SPLITCLIENT_ENV'] = "prod"
98-
mock_server do |server|
99-
server.setup_response('/') do |_, res|
100-
send_content(res, 'content')
101-
end
98+
begin
99+
mock_server do |server|
100+
server.setup_response('/') do |_, res|
101+
send_content(res, 'content')
102+
end
102103

103-
config.streaming_service_url = 'https://fake-sse.io'
104-
config.connection_timeout = 1
104+
config.streaming_service_url = 'https://fake-sse.io'
105+
config.connection_timeout = 1
105106

106-
sync_manager = subject.new(config, synchronizer, telemetry_runtime_producer, telemetry_synchronizer, status_manager, sse_handler, push_manager, push_status_queue)
107-
sync_manager.start
107+
sync_manager = subject.new(config, synchronizer, telemetry_runtime_producer, telemetry_synchronizer, status_manager, sse_handler, push_manager, push_status_queue)
108+
sync_manager.start
108109

109-
sleep(2)
110-
expect(a_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.3&since=-1&rbSince=-1')).to have_been_made.once
110+
sleep(2)
111+
expect(a_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.3&since=-1&rbSince=-1')).to have_been_made.once
111112

112-
expect(config.threads.size).to eq(9)
113-
config.threads.values.each { |thread| Thread.kill(thread) }
113+
expect(config.threads.size).to eq(9)
114+
config.threads.values.each { |thread| Thread.kill(thread) }
115+
end
116+
ensure
117+
ENV['SPLITCLIENT_ENV'] = "test"
114118
end
115-
ENV['SPLITCLIENT_ENV'] = "test"
116119
end
117120

118121
it 'start sync manager receiving control message, must switch to polling' do

0 commit comments

Comments
 (0)