Skip to content

Commit 6d4bcd9

Browse files
committed
using cirrus
1 parent 783e96f commit 6d4bcd9

15 files changed

+493
-571
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

+13-18
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[*]}"
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
3531

36-
sonar-scanner -X \
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.
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#!/bin/bash
2+
# shellcheck source=/dev/null
23

34
set -euo pipefail
45

56
source "$(dirname "$0")"/includes/git_utils
67
source "$(dirname "$0")"/includes/version_util
7-
source analyze
8+
source "$(dirname "$0")"/analyze
9+
source "$(dirname "$0")"/npm_deploy
810

9-
# source npm_deploy
10-
source npm_version_utils
11+
source "$(dirname "$0")"/npm_version_utils
1112

1213

1314
if is_master_branch && ! is_pull_request; then
@@ -19,27 +20,27 @@ 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"
2627
echo "Checked version format: $PROJECT_VERSION."
2728

2829
echo "Installing npm dependencies..."
29-
npm ci
30+
yarn install --immutable
3031

3132
echo "Running tests..."
32-
npm test
33+
yarn test
3334

3435
echo "Running Sonar Scanner..."
3536
run_sonar_scanner \
3637
-Dsonar.projectVersion="$CURRENT_VERSION"
3738

3839
echo "Building project..."
39-
npm run build
40+
yarn 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}"
@@ -57,13 +58,13 @@ elif is_maintenance_branch && not_pull_request; then
5758
check_version_format "$CURRENT_VERSION"
5859
fi
5960

60-
npm ci
61-
npm test
61+
yarn install --immutable
62+
yarn test
6263
run_sonar_scanner \
6364
-Dsonar.branch.name="$GITHUB_BRANCH"
6465

65-
npm run build
66-
jfrog_npm_publish
66+
yarn build
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
@@ -74,24 +75,24 @@ elif is_pull_request; then
7475

7576
check_version_format "$PROJECT_VERSION"
7677

77-
npm ci
78+
yarn install --immutable
7879

79-
npm test
80+
yarn test
8081
run_sonar_scanner \
8182
-Dsonar.analysis.prNumber="$PULL_REQUEST"
8283

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

8687
else
8788
echo '======= no deploy ======='
8889

89-
npm ci
90+
yarn install --immutable
9091

9192
run_sonar_scanner \
9293
-Dsonar.analysis.prNumber="$PULL_REQUEST"
9394

94-
npm run build
95+
yarn build
9596
fi
9697

9798
elif is_dogfood_branch && not_pull_request; then
@@ -102,21 +103,21 @@ elif is_dogfood_branch && not_pull_request; then
102103
set_npm_version_with_build_id "$BUILD_NUMBER"
103104
check_version_format "$PROJECT_VERSION"
104105

105-
npm ci
106-
npm run build
107-
jfrog_npm_publish
106+
yarn install --immutable
107+
yarn build
108+
jfrog_npm_publish "$@"
108109

109110
elif is_long_lived_feature_branch && not_pull_request; then
110-
npm ci
111+
yarn install --immutable
111112

112-
npm test
113+
yarn test
113114
run_sonar_scanner \
114115
-Dsonar.branch.name="$GITHUB_BRANCH"
115116

116-
npm run build
117+
yarn build
117118

118119
else
119-
npm ci
120-
npm test
121-
npm run build
120+
yarn install --immutable
121+
yarn test
122+
yarn build
122123
fi

npm_deploy .cirrus/npm_deploy

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jfrog_npm_publish() {
1616
local build_name=${3:-$CIRRUS_REPO_NAME}
1717
local build_number=${4:-$BUILD_NUMBER}
1818

19+
1920
jfrog npm-config --repo-resolve "$repo_resolve" --repo-deploy "$repo_deploy"
2021
jfrog npm publish --build-name="$build_name" --build-number="$build_number"
2122
jfrog rt build-publish "$build_name" "$build_number"

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)