diff --git a/.harness/orgs/PROD/projects/Harness_Split/pipelines/splitopenfeatureproviderjs/input_sets/splitopenfeatureproviderjsinputset.yaml b/.harness/orgs/PROD/projects/Harness_Split/pipelines/splitopenfeatureproviderjs/input_sets/splitopenfeatureproviderjsinputset.yaml new file mode 100644 index 0000000..4e6c742 --- /dev/null +++ b/.harness/orgs/PROD/projects/Harness_Split/pipelines/splitopenfeatureproviderjs/input_sets/splitopenfeatureproviderjsinputset.yaml @@ -0,0 +1,14 @@ +inputSet: + identifier: splitopenfeatureproviderjsinputset + name: splitopenfeatureproviderjsinputset + orgIdentifier: PROD + projectIdentifier: Harness_Split + pipeline: + identifier: splitopenfeatureproviderjs + properties: + ci: + codebase: + build: + type: PR + spec: + number: <+trigger.prNumber> diff --git a/.harness/pipeline.yaml b/.harness/pipeline.yaml new file mode 100644 index 0000000..9f4957e --- /dev/null +++ b/.harness/pipeline.yaml @@ -0,0 +1,170 @@ +pipeline: + name: split-openfeature-provider-js + identifier: splitopenfeatureproviderjs + projectIdentifier: Harness_Split + orgIdentifier: PROD + tags: {} + properties: + ci: + codebase: + connectorRef: fmegithubharnessgitops + repoName: split-openfeature-provider-js + build: <+input> + stages: + - stage: + name: Build and Test + identifier: Build_and_Test + description: "" + type: CI + spec: + cloneCodebase: true + caching: + enabled: true + override: true + platform: + os: Linux + arch: Amd64 + runtime: + type: Cloud + spec: + size: flex + execution: + steps: + - step: + type: Run + name: Install Node + identifier: Install_Node + spec: + shell: Bash + command: |- + curl https://mise.run | sh + export PATH="$HOME/.local/bin:$PATH" + mise use --global node@<+matrix.nodeVersion> + node --version + npm --version + - step: + type: Run + name: Start Redis + identifier: Start_Redis + spec: + shell: Sh + command: |- + curl -fsSL https://packages.redis.io/gpg | gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg + echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/redis.list + apt-get update -qq + apt-get install -y redis-server -qq + redis-server --daemonize yes --port 6379 + redis-cli ping + - step: + type: Run + name: Wait for Redis + identifier: Wait_for_Redis + spec: + shell: Sh + command: |- + for i in $(seq 1 15); do + redis-cli ping && break + echo "Waiting for Redis... attempt $i" + sleep 1 + done + - step: + type: Run + name: Install Dependencies + identifier: Install_Dependencies + spec: + shell: Bash + command: |- + export PATH="$HOME/.local/bin:$PATH" + eval "$(mise activate bash)" + npm ci + - step: + type: Run + name: Run Checks + identifier: Run_Checks + spec: + shell: Bash + command: |- + export PATH="$HOME/.local/bin:$PATH" + eval "$(mise activate bash)" + npm run check + - step: + type: Run + name: Run Tests + identifier: Run_Tests + spec: + shell: Bash + command: |- + export PATH="$HOME/.local/bin:$PATH" + eval "$(mise activate bash)" + npm run test + - step: + type: Run + name: SonarQube Scan + identifier: SonarQube_Scan + when: + stageStatus: Success + condition: <+matrix.nodeVersion> == "lts" + spec: + shell: Sh + command: |- + export SONAR_SCANNER_VERSION=5.0.1.3006 + curl -sSLo sonar-scanner.zip \ + "https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${SONAR_SCANNER_VERSION}-linux.zip" + unzip -q sonar-scanner.zip + export PATH="$PWD/sonar-scanner-${SONAR_SCANNER_VERSION}-linux/bin:$PATH" + apt-get install -y openjdk-17-jdk -qq + sonar-scanner \ + -Dsonar.projectKey=split-openfeature-provider-js \ + -Dsonar.sources=src \ + -Dsonar.tests=src/__tests__ \ + -Dsonar.host.url=https://sonar.harness.io \ + -Dsonar.token=<+secrets.getValue("sonarqube-token")> \ + -Dsonar.exclusions="**/node_modules/**,**/dist/**,src/__tests__/**" \ + -Dsonar.coverage.exclusions="**/__tests__/**,**/node_modules/**" + - step: + type: Run + name: Post Quality Gate + identifier: Post_Quality_Gate + when: + stageStatus: Success + condition: <+matrix.nodeVersion> == "lts" + spec: + shell: Bash + command: |- + #!/bin/bash + set -e + + SONAR_TOKEN="<+secrets.getValue("sonarqube-token")>" + SONAR_URL="https://sonar.harness.io" + SONAR_PROJECT_KEY="split-openfeature-provider-js" + GITHUB_TOKEN="<+secrets.getValue("github-devops-token")>" + GITHUB_REPO="split-openfeature-provider-js" + COMMIT_SHA="<+codebase.commitSha>" + + STATUS_JSON=$(curl -sf \ + -H "Authorization: Bearer ${SONAR_TOKEN}" \ + "${SONAR_URL}/api/qualitygates/project_status?projectKey=${SONAR_PROJECT_KEY}") + + QG_STATUS=$(echo "$STATUS_JSON" | python3 -c "import sys,json; print(json.load(sys.stdin)['projectStatus']['status'])") + + case "$QG_STATUS" in + OK) GH_STATE="success"; DESCRIPTION="Quality gate passed" ;; + ERROR) GH_STATE="failure"; DESCRIPTION="Quality gate failed" ;; + WARN) GH_STATE="success"; DESCRIPTION="Quality gate passed with warnings" ;; + *) GH_STATE="pending"; DESCRIPTION="Quality gate status unknown" ;; + esac + + TARGET_URL="${SONAR_URL}/dashboard?id=${SONAR_PROJECT_KEY}" + + curl -sf -X POST \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + -H "Content-Type: application/json" \ + -d "{\"state\":\"${GH_STATE}\",\"description\":\"${DESCRIPTION}\",\"context\":\"sonarqube/quality-gate\",\"target_url\":\"${TARGET_URL}\"}" \ + "https://api.github.com/repos/splitio/${GITHUB_REPO}/statuses/${COMMIT_SHA}" + + echo "Posted SonarQube quality gate status: ${GH_STATE}" + strategy: + matrix: + nodeVersion: + - "lts"