Skip to content

Commit 2dfc6cf

Browse files
committed
using cirrus
1 parent 783e96f commit 2dfc6cf

14 files changed

+79
-85
lines changed

.cirrus.star

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("github.com/SonarSource/cirrus-modules@b1f898b04170567791e1fd75f691f0266aab60af", "load_features") # 3.0.4
1+
load("github.com/SonarSource/cirrus-modules@5cd6425fdb78665f07284f2c12d495618a7bbc0a", "load_features") # 3.1.0
22

33
def main(ctx):
44
return load_features(ctx, only_if=dict())

.cirrus.yml

+8-6
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@ env:
66
CIRRUS_SHELL: bash
77

88
eks_container_definition: &CONTAINER_DEFINITION
9-
image: ${CIRRUS_AWS_ACCOUNT}.dkr.ecr.eu-central-1.amazonaws.com/base:latest
9+
image: 460386131003.dkr.ecr.eu-central-1.amazonaws.com/base-pr-118:node22-yarn2.4.3
1010
cluster_name: ${CIRRUS_CLUSTER_NAME}
1111
region: eu-central-1
1212
namespace: default
13-
docker_arguments:
14-
CIRRUS_AWS_ACCOUNT: ${CIRRUS_AWS_ACCOUNT}
1513

1614
build_task:
1715
auto_cancellation: $CIRRUS_BRANCH != 'master' && $CIRRUS_BRANCH != 'stable'
1816
eks_container:
1917
<<: *CONTAINER_DEFINITION
20-
cpu: 2
21-
memory: 2G
18+
builder_role: cirrus-builder
19+
builder_image: docker-builder-v*
20+
builder_instance_type: t2.small
21+
dockerfile: .cirrus/Dockerfile
22+
docker_arguments:
23+
CIRRUS_AWS_ACCOUNT: ${CIRRUS_AWS_ACCOUNT}
2224
env:
2325
ARTIFACTORY_DEPLOY_ACCESS_TOKEN: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-qa-deployer access_token]
2426
SONAR_HOST_URL: VAULT[development/kv/data/sonarcloud data.url]
@@ -38,7 +40,7 @@ build_task:
3840

3941
build_script:
4042
- source cirrus-env BUILD
41-
- regular_npm_build_deploy_analyze
43+
- ./.cirrus/npm_build_deploy_analyze
4244

4345
promote_task:
4446
depends_on:

.cirrus/Dockerfile

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
ARG CIRRUS_AWS_ACCOUNT
2+
FROM ${CIRRUS_AWS_ACCOUNT}.dkr.ecr.eu-central-1.amazonaws.com/base:j17-latest
3+
4+
USER root
5+
6+
# Update package list
7+
RUN apt-get update -y
8+
9+
# Install some tools
10+
RUN apt-get install -y jq
11+
12+
# Install vim
13+
RUN apt-get install -y vim
14+
15+
# Install Node.js
16+
ARG NODE_VERSION=20.*
17+
RUN apt-get install -y nodejs=${NODE_VERSION}
18+
19+
# Install Yarn
20+
RUN npm install -g yarn
21+
22+
# Install sonar-scanner-npm
23+
RUN npm install -g sonarqube-scanner
24+
25+
# Clean up cache after packages installation
26+
RUN apt-get clean
27+
28+
USER sonarsource

analyze .cirrus/analyze

+14-19
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,15 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
echo "Starting script..."
5-
6-
# SonarQube-related utility functions
7-
8-
: "${SONAR_HOST_URL?Environment variable missing}"
9-
: "${SONAR_TOKEN?Environment variable missing}"
10-
11-
echo "SONAR_HOST_URL: $SONAR_HOST_URL"
12-
echo "SONAR_TOKEN: $SONAR_TOKEN"
13-
144
git fetch --unshallow || true
155

166
if [ -n "${GITHUB_BASE_BRANCH:-}" ]; then
177
echo "Fetching base branch: $GITHUB_BASE_BRANCH"
188
git fetch origin "${GITHUB_BASE_BRANCH}"
199
fi
2010

21-
if [ -z "$PIPELINE_ID" ]; then
11+
if [ -z "${PIPELINE_ID:-}" ]; then
2212
PIPELINE_ID=$BUILD_NUMBER
23-
echo "PIPELINE_ID not set, using BUILD_NUMBER: $BUILD_NUMBER"
24-
else
25-
echo "PIPELINE_ID: $PIPELINE_ID"
2613
fi
2714

2815
# Runs the SonarQube scanner with default and additional parameters.
@@ -31,16 +18,24 @@ run_sonar_scanner() {
3118

3219
local additional_params=("$@")
3320

34-
echo "Running sonar-scanner with parameters: ${additional_params[*]}"
35-
36-
sonar-scanner -X \
21+
# echo "Running SonarQube scanner..."
22+
if [ -z "${SONAR_HOST_URL:-}" ]; then
23+
echo "SONAR_HOST_URL is required for SonarQube scanner"
24+
exit 1
25+
fi
26+
27+
if [ -z "${SONAR_TOKEN:-}" ]; then
28+
echo "SONAR_TOKEN is required for SonarQube scanner"
29+
exit 1
30+
fi
31+
32+
npx sonarqube-scanner -X \
3733
-Dsonar.host.url="$SONAR_HOST_URL" \
3834
-Dsonar.token="$SONAR_TOKEN" \
3935
-Dsonar.analysis.buildNumber="$BUILD_NUMBER" \
4036
-Dsonar.analysis.pipeline="$PIPELINE_ID" \
4137
-Dsonar.analysis.sha1="$GIT_SHA1" \
4238
-Dsonar.analysis.repository="$GITHUB_REPO" \
4339
"${additional_params[@]}"
40+
echo "SonarQube scanner finished"
4441
}
45-
46-
echo "Script finished."
File renamed without changes.
File renamed without changes.

includes/git_utils .cirrus/includes/git_utils

-7
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,31 @@
44
set -euo pipefail
55

66
fetch_git_history() {
7-
echo "Fetching git history..."
87
git fetch --unshallow || true
98
}
109

1110
fetch_pr_references() {
1211
if [ -n "${GITHUB_BASE_BRANCH:-}" ]; then
13-
echo "Fetching PR references for base branch: $GITHUB_BASE_BRANCH"
1412
git fetch origin "${GITHUB_BASE_BRANCH}"
1513
fi
1614
}
1715

1816
is_master_branch() {
19-
echo "Checking if current branch is master: $GITHUB_BRANCH"
2017
[[ "${GITHUB_BRANCH}" == "master" ]]
2118
}
2219

2320
is_maintenance_branch() {
24-
echo "Checking if current branch is a maintenance branch: $GITHUB_BRANCH"
2521
[[ "${GITHUB_BRANCH}" == "branch-"* ]]
2622
}
2723

2824
is_pull_request() {
29-
echo "Checking if this is a pull request: ${PULL_REQUEST:-}"
3025
[[ "${PULL_REQUEST:-}" != "false" ]]
3126
}
3227

3328
is_dogfood_branch() {
34-
echo "Checking if current branch is a dogfood branch: $GITHUB_BRANCH"
3529
[[ "${GITHUB_BRANCH}" == "dogfood-on-"* ]]
3630
}
3731

3832
is_long_lived_feature_branch() {
39-
echo "Checking if current branch is a long-lived feature branch: $GITHUB_BRANCH"
4033
[[ "${GITHUB_BRANCH}" == "feature/long/"* ]]
4134
}
File renamed without changes.
File renamed without changes.

npm_build_deploy_analyze .cirrus/npm_build_deploy_analyze

+8-7
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ set -euo pipefail
44

55
source "$(dirname "$0")"/includes/git_utils
66
source "$(dirname "$0")"/includes/version_util
7-
source analyze
7+
source .cirrus/analyze
8+
source .cirrus/npm_deploy
89

910
# source npm_deploy
10-
source npm_version_utils
11+
source .cirrus/npm_version_utils
1112

1213

1314
if is_master_branch && ! is_pull_request; then
@@ -19,7 +20,7 @@ if is_master_branch && ! is_pull_request; then
1920
CURRENT_VERSION=$(get_current_version)
2021
echo "Current version: $CURRENT_VERSION"
2122

22-
# set_npm_version_with_build_id "$BUILD_NUMBER"
23+
set_npm_version_with_build_id "$BUILD_NUMBER"
2324
echo "Set npm version with build ID: $BUILD_NUMBER."
2425

2526
check_version_format "$PROJECT_VERSION"
@@ -39,7 +40,7 @@ if is_master_branch && ! is_pull_request; then
3940
npm run build
4041

4142
echo "Publishing to JFrog..."
42-
jfrog_npm_publish
43+
jfrog_npm_publish "$@"
4344

4445
elif is_maintenance_branch && not_pull_request; then
4546
git fetch origin "${GITHUB_BRANCH}"
@@ -63,7 +64,7 @@ elif is_maintenance_branch && not_pull_request; then
6364
-Dsonar.branch.name="$GITHUB_BRANCH"
6465

6566
npm run build
66-
jfrog_npm_publish
67+
jfrog_npm_publish "$@"
6768

6869
elif is_pull_request; then
6970
# Do not deploy a SNAPSHOT version but the release version related to this build and PR
@@ -81,7 +82,7 @@ elif is_pull_request; then
8182
-Dsonar.analysis.prNumber="$PULL_REQUEST"
8283

8384
npm run build
84-
jfrog_npm_publish
85+
jfrog_npm_publish "$@"
8586

8687
else
8788
echo '======= no deploy ======='
@@ -104,7 +105,7 @@ elif is_dogfood_branch && not_pull_request; then
104105

105106
npm ci
106107
npm run build
107-
jfrog_npm_publish
108+
jfrog_npm_publish "$@"
108109

109110
elif is_long_lived_feature_branch && not_pull_request; then
110111
npm ci

npm_deploy .cirrus/npm_deploy

File renamed without changes.

npm_version_utils .cirrus/npm_version_utils

+9-7
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,26 @@ set -euo pipefail
55
PACKAGE_JSON="package.json"
66

77
function get_current_version() {
8-
jq -r .version "$PACKAGE_JSON"
8+
CURRENT_VERSION=$(jq -r .version "$PACKAGE_JSON")
9+
10+
if [ -z "$CURRENT_VERSION" ] || [ "$CURRENT_VERSION" == "null" ]; then
11+
echo "Could not get version from $PACKAGE_JSON" >&2
12+
exit 1
13+
fi
14+
15+
echo "$CURRENT_VERSION"
916
}
1017

1118
function set_npm_version_with_build_id() {
1219
local BUILD_ID=$1
1320

1421
CURRENT_VERSION=$(get_current_version)
1522

16-
if [ -z "$CURRENT_VERSION" ] || [ "$CURRENT_VERSION" == "null" ]; then
17-
echo "Could not get version from $PACKAGE_JSON" >&2
18-
exit 1
19-
fi
20-
2123
RELEASE_VERSION=${CURRENT_VERSION%"-SNAPSHOT"}
2224

2325
# In case of 2 digits, we need to add the 3rd digit (0 obviously)
2426
# Mandatory in order to compare versions (patch VS non patch)
25-
DIGIT_COUNT=$(echo "${RELEASE_VERSION//./ }" | wc --words)
27+
DIGIT_COUNT=$(echo "${RELEASE_VERSION//./ }" | wc -w)
2628
if [ "$DIGIT_COUNT" -lt 3 ]; then
2729
RELEASE_VERSION="$RELEASE_VERSION.0"
2830
fi

.github/workflows/build.yml

-38
This file was deleted.

src/index.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright (C) 2014-2024 SonarSource SA
3+
* All rights reserved
4+
* mailto:info AT sonarsource DOT com
5+
*/
6+
7+
function helloNpm() {
8+
return "hello NPM"
9+
}
10+
11+
module.exports = helloNpm

0 commit comments

Comments
 (0)