Skip to content

BUILD-7780: Use monthly cache for orchestrator #596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,30 @@
preemptible: false
use_ssd: true

orchestrator_cache_definition: &ORCHESTRATOR_CACHE_DEFINITION
set_orchestrator_home_script: |
# Check if SQ_VERSION exists and create an intermediary variable
if [ -n "$SQ_VERSION" ]; then
FOLDER="${SQ_VERSION}"
else
FOLDER="DEFAULT"
fi

CURRENT_MONTH=$(date +"%B")
echo "CURRENT_MONTH=${CURRENT_MONTH}" >> $CIRRUS_ENV
echo "ORCHESTRATOR_HOME=${CIRRUS_WORKING_DIR}/orchestrator/${FOLDER}/${CURRENT_MONTH}" >> $CIRRUS_ENV
echo "FOLDER=${FOLDER}" >> $CIRRUS_ENV
mkdir_orchestrator_home_script: |
echo "Create dir ${ORCHESTRATOR_HOME} if needed"
mkdir -p ${ORCHESTRATOR_HOME}
orchestrator_cache:
folder: ${ORCHESTRATOR_HOME}
fingerprint_script: echo ${FOLDER}-${CURRENT_MONTH}
reupload_on_changes: "true"

cleanup_orchestrator_cache_script_template: &CLEANUP_ORCHESTRATOR_CACHE_SCRIPT
cleanup_orchestrator_cache_script: .cirrus/clean-orchestrator-cache.sh

setup_gradle_cache_template: &SETUP_GRADLE_CACHE
gradle_cache:
folder: .gradle/caches
Expand All @@ -78,6 +102,7 @@

gradle_its_template: &GRADLE_ITS_TEMPLATE
<<: *SETUP_GRADLE_CACHE
<<: *ORCHESTRATOR_CACHE_DEFINITION
run_its_script:
- |
if [ -n "${GIT_SUB_MODULE}" ]; then
Expand All @@ -89,6 +114,7 @@
"-DbuildNumber=$BUILD_NUMBER"
--info --console plain --no-daemon --build-cache
<<: *CLEANUP_GRADLE_CACHE_SCRIPT
<<: *CLEANUP_ORCHESTRATOR_CACHE_SCRIPT

only_if_sonarsource_qa_template: &ONLY_IF_SONARSOURCE_QA
only_if: $CIRRUS_USER_COLLABORATOR == 'true' && $CIRRUS_TAG == "" && ($CIRRUS_PR != "" || $CIRRUS_BRANCH == "master" || $CIRRUS_BRANCH =~ "branch-.*" || $CIRRUS_BRANCH =~ "dogfood-on-.*")
Expand Down Expand Up @@ -198,6 +224,7 @@
GIT_SUB_MODULE: "its/sources"
<<: *LINUX_6_CPU_12G_JAVA_17
<<: *SETUP_GRADLE_CACHE
<<: *ORCHESTRATOR_CACHE_DEFINITION
run_its_script:
- |
if [ -n "${GIT_SUB_MODULE}" ]; then
Expand All @@ -209,6 +236,7 @@
"-DbuildNumber=$BUILD_NUMBER"
--info --console plain --no-daemon --build-cache
<<: *CLEANUP_GRADLE_CACHE_SCRIPT
<<: *CLEANUP_ORCHESTRATOR_CACHE_SCRIPT

build_win_task:
<<: *QA_TASK_FILTER
Expand All @@ -223,7 +251,7 @@
path: "*.hprof"
<<: *CLEANUP_GRADLE_CACHE_SCRIPT

promote_task:

Check warning on line 254 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L254

task "promote" depends on task "ws_scan", but their only_if conditions are different

Check warning on line 254 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L254

task "promote" depends on task "ws_scan", but their only_if conditions are different
depends_on:
- build
- build_test_analyze
Expand Down
27 changes: 27 additions & 0 deletions .cirrus/clean-orchestrator-cache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
set -euo pipefail

cd "$ORCHESTRATOR_HOME" || exit 1

# Find all sonar-application-* JAR files, sort them by version, and list them
files=$(/usr/bin/find . -name 'sonar-application-*' | /usr/bin/sort --field-separator=- --key=3V --reverse)

echo "File that will not be deleted:"
echo "$files" | head -n 1

kotlin_files=$(/usr/bin/find . -name 'sonar-kotlin-plugin-*.jar')

# Get the files to delete: all sonar-application except the latest one, and all sonar-kotlin-plugin JAR files
files_to_delete=$(echo "$files" | tail -n +2; echo "$kotlin_files")

echo ""
if [ -z "$files_to_delete" ]; then
echo "No files will be deleted."
else
echo "Files that will be deleted:"
echo "$files_to_delete"

# Delete obsolete sonar-application files
# shellcheck disable=SC2016
echo "$files_to_delete" | xargs -I {} sh -c 'rm -f "{}" && rmdir "$(dirname "{}")" 2>/dev/null || true'
fi