Skip to content

Commit 604d99f

Browse files
committed
BUILD-6984 test new scripts
1 parent f71d7b6 commit 604d99f

13 files changed

+2595
-13
lines changed

.github/workflows/build.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Node.js CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
strategy:
12+
matrix:
13+
node-version: [14.x, 16.x, 18.x]
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v2
18+
19+
- name: Set up Node.js ${{ matrix.node-version }}
20+
uses: actions/setup-node@v2
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
24+
- name: Execute npm_build_deploy_analyze script
25+
run: ./npm_build_deploy_analyze

analyze

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
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+
14+
git fetch --unshallow || true
15+
16+
if [ -n "${GITHUB_BASE_BRANCH:-}" ]; then
17+
echo "Fetching base branch: $GITHUB_BASE_BRANCH"
18+
git fetch origin "${GITHUB_BASE_BRANCH}"
19+
fi
20+
21+
if [ -z "$PIPELINE_ID" ]; then
22+
PIPELINE_ID=$BUILD_NUMBER
23+
echo "PIPELINE_ID not set, using BUILD_NUMBER: $BUILD_NUMBER"
24+
else
25+
echo "PIPELINE_ID: $PIPELINE_ID"
26+
fi
27+
28+
# Runs the SonarQube scanner with default and additional parameters.
29+
# Usage: run_sonar_scanner [additional_parameters...]
30+
run_sonar_scanner() {
31+
32+
local additional_params=("$@")
33+
34+
echo "Running sonar-scanner with parameters: ${additional_params[*]}"
35+
36+
sonar-scanner -X \
37+
-Dsonar.host.url="$SONAR_HOST_URL" \
38+
-Dsonar.token="$SONAR_TOKEN" \
39+
-Dsonar.analysis.buildNumber="$BUILD_NUMBER" \
40+
-Dsonar.analysis.pipeline="$PIPELINE_ID" \
41+
-Dsonar.analysis.sha1="$GIT_SHA1" \
42+
-Dsonar.analysis.repository="$GITHUB_REPO" \
43+
"${additional_params[@]}"
44+
}
45+
46+
echo "Script finished."

includes/cirrus-env

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
3+
set +o verbose
4+
set -euo pipefail
5+
6+
# generic environment variables used by Gradle build
7+
export GIT_SHA1=$CIRRUS_CHANGE_IN_REPO
8+
export GITHUB_BASE_BRANCH=${CIRRUS_BASE_BRANCH:-}
9+
export GITHUB_BRANCH=$CIRRUS_BRANCH
10+
export GITHUB_REPO=${CIRRUS_REPO_FULL_NAME}
11+
export PROJECT=${CIRRUS_REPO_NAME}
12+
export PULL_REQUEST=${CIRRUS_PR:-false}
13+
export PULL_REQUEST_SHA=${CIRRUS_BASE_SHA:-}
14+
export PIPELINE_ID=${CIRRUS_BUILD_ID}
15+
16+
export LANG=C.UTF-8
17+
18+
TASK_TYPE=$1
19+
if [[ "$TASK_TYPE" != "BUILD"* ]]; then
20+
export SONARSOURCE_QA=true
21+
fi
22+
23+
: "${CI_BUILD_NUMBER?missing parameter. See https://xtranet-sonarsource.atlassian.net/wiki/spaces/RE/pages/2992210934}"
24+
BUILD_NUMBER=${CI_BUILD_NUMBER}
25+
BUILD_ID=${CI_BUILD_NUMBER}
26+
echo "BUILD_NUMBER: $BUILD_NUMBER"
27+
export BUILD_NUMBER BUILD_ID
28+
29+
if [[ "${GITHUB_TOKEN:-}" == "ENCRYPTED"* ]]; then
30+
echo "Unsetting GITHUB_TOKEN"
31+
unset GITHUB_TOKEN
32+
fi
33+
34+
M2_SOURCE=~/.m2
35+
if [[ -f "/c/buildTools-docker/mvn/settings-public-auth.xml" ]]; then
36+
# /c/buildTools-docker/mvn is populated during Windows image creation
37+
M2_SOURCE=/c/buildTools-docker/mvn
38+
fi
39+
40+
[[ ! -d ~/.m2 ]] && mkdir ~/.m2
41+
if [[ "${TASK_TYPE}" == *"-PRIVATE" || "${TASK_TYPE}" == "QA"* || "${TASK_TYPE}" == "PROMOTE"* ]]; then
42+
cp "${M2_SOURCE}/settings-private.xml" ~/.m2/settings.xml
43+
else
44+
if [[ -n "${ARTIFACTORY_ACCESS_TOKEN:-}" ]]; then
45+
cp "${M2_SOURCE}/settings-public-auth.xml" ~/.m2/settings.xml
46+
else
47+
echo "No ARTIFACTORY_ACCESS_TOKEN found, Repox will not be accessible".
48+
fi
49+
fi
50+
51+
case $BUILD_ID in
52+
''|*[!0-9]*) echo "$BUILD_ID is not a number" && exit 1 ;;
53+
esac
54+
set -o verbose

includes/cirrus_error_advices

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
# This script is responsible to provide functions to give advices to end users.
3+
# If during the execution of a re-ci-images base scripts some errors occurs, then some advices might be given
4+
# in order to assist the user to resolve them (when possible).
5+
#
6+
# WARN: Please do not use this script out of re-ci-images base bash scripts.
7+
# (using it in another context might break in future releases)
8+
#
9+
# Usage: source includes/cirrus_error_advices
10+
11+
# Requires the environment variables:
12+
# none are required yet the functions are able to autofix
13+
14+
function is_using_cirrus(){
15+
[ "${CIRRUS_CI:-false}" == "true" ]
16+
}
17+
18+
# CIRRUS_REPO_NAME is provided out of the box by Cirrus CI
19+
function print_invalid_github_token_for_cirrus_advice(){
20+
REPOSITORY_SHORTNAME=${CIRRUS_REPO_NAME:-"REPOSITORY_NAME"}
21+
echo "Tips:"
22+
cat <<EOF
23+
24+
1) Check the Hashicorp Vault policy for this repository in
25+
26+
https://github.com/SonarSource/re-terraform-aws-vault/tree/master/orders
27+
28+
The policy of this repository should contains the following declarations:
29+
30+
$REPOSITORY_SHORTNAME
31+
secrets:
32+
github:
33+
presets: [default]
34+
customs:
35+
- <<: *github_promotion
36+
repositories: [$REPOSITORY_SHORTNAME]
37+
38+
and
39+
40+
github_promotion: &github_promotion
41+
organization: SonarSource
42+
suffix: promotion
43+
description: add a github check containing the build version to the current commit (required by cirrus_promote_maven)
44+
permissions: {statuses: write}
45+
46+
2) Check the .cirrus.yml file:
47+
48+
The token should be declared this way:
49+
50+
GITHUB_TOKEN: VAULT[development/github/token/\${CIRRUS_REPO_OWNER}-\${CIRRUS_REPO_NAME}-promotion token]
51+
"
52+
EOF
53+
}

includes/git_utils

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
# Git-related utility functions
3+
4+
set -euo pipefail
5+
6+
fetch_git_history() {
7+
echo "Fetching git history..."
8+
git fetch --unshallow || true
9+
}
10+
11+
fetch_pr_references() {
12+
if [ -n "${GITHUB_BASE_BRANCH:-}" ]; then
13+
echo "Fetching PR references for base branch: $GITHUB_BASE_BRANCH"
14+
git fetch origin "${GITHUB_BASE_BRANCH}"
15+
fi
16+
}
17+
18+
is_master_branch() {
19+
echo "Checking if current branch is master: $GITHUB_BRANCH"
20+
[[ "${GITHUB_BRANCH}" == "master" ]]
21+
}
22+
23+
is_maintenance_branch() {
24+
echo "Checking if current branch is a maintenance branch: $GITHUB_BRANCH"
25+
[[ "${GITHUB_BRANCH}" == "branch-"* ]]
26+
}
27+
28+
is_pull_request() {
29+
echo "Checking if this is a pull request: ${PULL_REQUEST:-}"
30+
[[ "${PULL_REQUEST:-}" != "false" ]]
31+
}
32+
33+
is_dogfood_branch() {
34+
echo "Checking if current branch is a dogfood branch: $GITHUB_BRANCH"
35+
[[ "${GITHUB_BRANCH}" == "dogfood-on-"* ]]
36+
}
37+
38+
is_long_lived_feature_branch() {
39+
echo "Checking if current branch is a long-lived feature branch: $GITHUB_BRANCH"
40+
[[ "${GITHUB_BRANCH}" == "feature/long/"* ]]
41+
}

includes/jfrog_utils.sh

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
function extract_module_names() {
5+
artifact=$1
6+
module=$(echo "$artifact" | sed -E "s,^([^/]+/[^/]+/([^/]+))/([^/]+)/(([0-9].)+[0-9]+)/.*$,\1:\3:\4," | sed "s,/,.,g")
7+
echo "$module"
8+
}
9+
10+
function extract_artifacts() {
11+
public_artifacts=()
12+
private_artifacts=()
13+
artifacts=$(grep Installing | sed 's,.*\.m2/repository/,,')
14+
while read -r artifact; do
15+
if [[ $artifact == "org/"* ]]; then
16+
public_artifacts+=("$artifact")
17+
elif [[ $artifact == "com/"* ]]; then
18+
private_artifacts+=("$artifact")
19+
fi
20+
done <<<"$artifacts"
21+
}
22+
23+
function upload_artifacts() {
24+
jfrog config add test --artifactory-url "$ARTIFACTORY_URL" --access-token "$ARTIFACTORY_DEPLOY_PASSWORD"
25+
pushd "${CIRRUS_WORKING_DIR}/.m2/repository/"
26+
for artifact in "${public_artifacts[@]}"; do
27+
echo "Deploying public artifact: $artifact"
28+
module=$(extract_module_names "$artifact")
29+
jfrog rt u --module "$module" --build-name "${CIRRUS_REPO_NAME}" --build-number "${BUILD_ID}" "$artifact" "${ARTIFACTORY_DEPLOY_REPO}"
30+
done
31+
32+
jfrog config edit test --artifactory-url "$ARTIFACTORY_URL" --access-token "$ARTIFACTORY_PRIVATE_DEPLOY_PASSWORD"
33+
for artifact in "${private_artifacts[@]}"; do
34+
echo "Deploying private artifact: $artifact"
35+
module=$(extract_module_names "$artifact")
36+
jfrog rt u --module "$module" --build-name "${CIRRUS_REPO_NAME}" --build-number "${BUILD_ID}" "$artifact" "${ARTIFACTORY_PRIVATE_DEPLOY_REPO}"
37+
done
38+
popd
39+
}

includes/version_util

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
# This script is responsible to provide functions to verify that the specified version follows the Sonar way proposed
3+
# by the RE Team.
4+
#
5+
# Usage: source includes/version_util
6+
7+
# Requires the environment variables:
8+
# none are required yet the functions are able to autofix
9+
10+
11+
# Verify that the version declared in pom.xml or in gradle.properties
12+
# use the following pattern: x.x.x.x (<major>.<minor>.<patch>.<buildNumber>) and warn if not.
13+
# Args:
14+
# $1 The version string to check
15+
function check_version_format(){
16+
local version=$1
17+
local extracted_points="${version//[^.]}"
18+
local point_count=${#extracted_points}
19+
if [[ "$point_count" != 3 ]]; then
20+
echo "WARN: This version $version does not match the standardized format used commonly across the organization: '<MAJOR>.<MINOR>.<PATCH>.<BUILD NUMBER>'."
21+
fi
22+
}

0 commit comments

Comments
 (0)