diff options
author | Julien Carsique <julien.carsique@sonarsource.com> | 2023-12-27 19:01:16 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-01-23 20:04:15 +0000 |
commit | d26c2ca7db6af4b2cfc24d3f560e5354d0692f9e (patch) | |
tree | a97d938a49630b8ed3c61ccc22dbb8eb52978deb /.cirrus | |
parent | 29f0fde0bf04408dd3c35d5122bacda8289e6926 (diff) | |
download | sonarqube-d26c2ca7db6af4b2cfc24d3f560e5354d0692f9e.tar.gz sonarqube-d26c2ca7db6af4b2cfc24d3f560e5354d0692f9e.zip |
BUILD-3755 migrate Travis to Cirrus CI
Diffstat (limited to '.cirrus')
-rw-r--r-- | .cirrus/.cirrus.yml | 183 | ||||
-rw-r--r-- | .cirrus/Dockerfile | 51 | ||||
-rwxr-xr-x | .cirrus/cirrus-build.sh | 20 | ||||
-rwxr-xr-x | .cirrus/cirrus-cache-dependencies.sh | 13 | ||||
-rw-r--r-- | .cirrus/cirrus-env | 11 | ||||
-rwxr-xr-x | .cirrus/cirrus-junit.sh | 7 | ||||
-rwxr-xr-x | .cirrus/cirrus-sq-analysis.sh | 22 | ||||
-rwxr-xr-x | .cirrus/cirrus-yarn-lint-report.sh | 7 | ||||
-rwxr-xr-x | .cirrus/cirrus-yarn-validate-ci.sh | 7 |
9 files changed, 321 insertions, 0 deletions
diff --git a/.cirrus/.cirrus.yml b/.cirrus/.cirrus.yml new file mode 100644 index 00000000000..14ca811439f --- /dev/null +++ b/.cirrus/.cirrus.yml @@ -0,0 +1,183 @@ +only_if: $CIRRUS_TAG == "" && ($CIRRUS_PR != "" || $CIRRUS_BRANCH == $CIRRUS_DEFAULT_BRANCH || $CIRRUS_BRANCH =~ "branch-.*" || $CIRRUS_BUILD_SOURCE == 'api' ) +skip: $CIRRUS_BRANCH == "public_master" || $CIRRUS_BRANCH =~ "dogfood/.*" + +env: + CIRRUS_SHELL: bash + CIRRUS_CLONE_DEPTH: 0 + GRADLE_USER_HOME: ${CIRRUS_WORKING_DIR}/.gradle + FETCH_DEPTH: --depth=1 + +default_artifact_template: &DEFAULT_ARTIFACTS_TEMPLATE + on_failure: + jest_junit_cleanup_script: > + find . -type f -wholename "**/build/test-results/test-jest/junit.xml" -exec + xmlstarlet edit --inplace --delete '//testsuite[@errors=0 and @failures=0]' {} \; + junit_artifacts: + path: "**/build/test-results/**/*.xml" + type: "text/xml" + format: junit + reports_artifacts: + path: "**/build/reports/**/*" + screenshots_artifacts: + path: "**/build/screenshots/**/*" + log_artifacts: + path: "**/build/**/*.log" + +default_template: &DEFAULT_TEMPLATE + clone_script: | + git init + git remote add origin https://x-access-token:${CIRRUS_REPO_CLONE_TOKEN}@github.com/${CIRRUS_REPO_FULL_NAME}.git + git fetch origin $CIRRUS_CHANGE_IN_REPO $FETCH_DEPTH + git reset --hard $CIRRUS_CHANGE_IN_REPO + +gradle_cache_template: &GRADLE_CACHE_TEMPLATE + gradle_cache: + folder: ${GRADLE_USER_HOME}/caches + fingerprint_script: find -type f \( -name "*.gradle*" -or -name "gradle*.properties" \) | sort | xargs cat + populate_script: mkdir -p ${GRADLE_USER_HOME}/caches + +cleanup_gradle_cache_script_template: &CLEANUP_GRADLE_CACHE_SCRIPT + cleanup_gradle_script: | + rm -rf "${GRADLE_USER_HOME}"/caches/7.*/ + rm -rf "${GRADLE_USER_HOME}"/daemon/ + rm -rf "${GRADLE_USER_HOME}"/caches/transforms-* + rm -rf "${GRADLE_USER_HOME}"/caches/journal-* + /usr/bin/find "${GRADLE_USER_HOME}"/caches/ -name "*.lock" -type f -delete + +yarn_cache_template: &YARN_CACHE_TEMPLATE + yarn_cache: + folder: "~/.yarn/berry/cache" + fingerprint_script: cat server/sonar-web/yarn.lock + +jar_cache_template: &JAR_CACHE_TEMPLATE + jar_cache: + folder: "**/build/libs/*.jar" + fingerprint_key: jar-cache_$CIRRUS_BUILD_ID + +eslint_report_cache_template: &ESLINT_REPORT_CACHE_TEMPLATE + eslint_report_cache: + folders: + - server/sonar-web/eslint-report/ + - server/sonar-web/design-system/eslint-report/ + fingerprint_script: echo $CIRRUS_BUILD_ID + +jest_report_cache_template: &JEST_REPORT_CACHE_TEMPLATE + jest_report_cache: + folders: + - server/sonar-web/coverage/ + - server/sonar-web/design-system/coverage/ + fingerprint_script: echo $CIRRUS_BUILD_ID + +junit_report_cache_template: &JUNIT_REPORT_CACHE_TEMPLATE + junit_report_cache: + folders: + - "**/reports/jacoco" + - "**/test-results/test" + fingerprint_script: echo $CIRRUS_BUILD_ID + +cache_dependencies_task: + container: + dockerfile: .cirrus/Dockerfile + cpu: 2 + memory: 4Gb + <<: *DEFAULT_TEMPLATE + <<: *GRADLE_CACHE_TEMPLATE + script: + - .cirrus/cirrus-cache-dependencies.sh + <<: *CLEANUP_GRADLE_CACHE_SCRIPT + <<: *DEFAULT_ARTIFACTS_TEMPLATE + +build_task: + depends_on: cache_dependencies + container: + dockerfile: .cirrus/Dockerfile + cpu: 8 + memory: 8Gb + <<: *DEFAULT_TEMPLATE + <<: *GRADLE_CACHE_TEMPLATE + <<: *YARN_CACHE_TEMPLATE + <<: *JAR_CACHE_TEMPLATE + build_script: .cirrus/cirrus-build.sh + <<: *CLEANUP_GRADLE_CACHE_SCRIPT + <<: *DEFAULT_ARTIFACTS_TEMPLATE + +yarn_lint_task: + depends_on: cache_dependencies + container: + dockerfile: .cirrus/Dockerfile + cpu: 3 + memory: 4Gb + <<: *DEFAULT_TEMPLATE + <<: *GRADLE_CACHE_TEMPLATE + <<: *YARN_CACHE_TEMPLATE + <<: *ESLINT_REPORT_CACHE_TEMPLATE + script: + - .cirrus/cirrus-yarn-lint-report.sh + <<: *CLEANUP_GRADLE_CACHE_SCRIPT + <<: *DEFAULT_ARTIFACTS_TEMPLATE + +yarn_check_task: + depends_on: cache_dependencies + container: + dockerfile: .cirrus/Dockerfile + cpu: 3 + memory: 4Gb + <<: *DEFAULT_TEMPLATE + <<: *GRADLE_CACHE_TEMPLATE + <<: *YARN_CACHE_TEMPLATE + script: | + source .cirrus/cirrus-env + ./gradlew yarn_check-ci + <<: *CLEANUP_GRADLE_CACHE_SCRIPT + <<: *DEFAULT_ARTIFACTS_TEMPLATE + +yarn_validate_task: + depends_on: cache_dependencies + container: + dockerfile: .cirrus/Dockerfile + cpu: 8 + memory: 15Gb + <<: *DEFAULT_TEMPLATE + <<: *GRADLE_CACHE_TEMPLATE + <<: *YARN_CACHE_TEMPLATE + <<: *JEST_REPORT_CACHE_TEMPLATE + script: + - .cirrus/cirrus-yarn-validate-ci.sh + <<: *CLEANUP_GRADLE_CACHE_SCRIPT + <<: *DEFAULT_ARTIFACTS_TEMPLATE + +junit_task: + depends_on: cache_dependencies + container: + dockerfile: .cirrus/Dockerfile + cpu: 8 + memory: 10Gb + <<: *DEFAULT_TEMPLATE + <<: *GRADLE_CACHE_TEMPLATE + <<: *JUNIT_REPORT_CACHE_TEMPLATE + script: + - .cirrus/cirrus-junit.sh + <<: *CLEANUP_GRADLE_CACHE_SCRIPT + <<: *DEFAULT_ARTIFACTS_TEMPLATE + +sq_analysis_task: + depends_on: + - yarn_lint + - yarn_validate + - junit + container: + dockerfile: .cirrus/Dockerfile + cpu: 7.5 + memory: 15Gb + env: + SONAR_HOST_URL: https://next.sonarqube.com/sonarqube + SONAR_TOKEN: ENCRYPTED[!b6fd814826c51e64ee61b0b6f3ae621551f6413383f7170f73580e2e141ac78c4b134b506f6288c74faa0dd564c05a29!] + <<: *GRADLE_CACHE_TEMPLATE + <<: *YARN_CACHE_TEMPLATE + <<: *JEST_REPORT_CACHE_TEMPLATE + <<: *ESLINT_REPORT_CACHE_TEMPLATE + <<: *JUNIT_REPORT_CACHE_TEMPLATE + script: + - .cirrus/cirrus-sq-analysis.sh + <<: *CLEANUP_GRADLE_CACHE_SCRIPT + <<: *DEFAULT_ARTIFACTS_TEMPLATE diff --git a/.cirrus/Dockerfile b/.cirrus/Dockerfile new file mode 100644 index 00000000000..5828cd2fd23 --- /dev/null +++ b/.cirrus/Dockerfile @@ -0,0 +1,51 @@ +ARG JDK_VERSION=17 +FROM eclipse-temurin:${JDK_VERSION}-jdk-jammy + +ENV DEBIAN_FRONTEND=noninteractive + +SHELL ["/bin/bash", "-o", "pipefail", "-c"] +RUN set -o errexit -o nounset \ + && groupadd --system --gid 1000 sonarsource \ + && useradd --system --gid sonarsource --uid 1000 --shell /bin/bash --create-home sonarsource + +RUN echo 'Acquire::AllowReleaseInfoChange::Suite "true";' > /etc/apt/apt.conf.d/allow_release_info_change.conf + +# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=863199#23 +RUN mkdir -p /usr/share/man/man1 \ + && apt-get update \ + && apt-get -y install --no-install-recommends \ + lsb-release \ + ca-certificates \ + curl \ + wget \ + gnupg \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +ARG NODE_MAJOR=18 +RUN DISTRO="$(lsb_release -s -c)" \ + && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \ + && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" >> /etc/apt/sources.list.d/nodesource.list \ + && curl -sSL https://packages.atlassian.com/api/gpg/key/public | gpg --dearmor -o /etc/apt/keyrings/atlassian.gpg \ + && echo "deb [signed-by=/etc/apt/keyrings/atlassian.gpg] https://packages.atlassian.com/debian/atlassian-sdk-deb/ stable contrib" >> /etc/apt/sources.list.d/atlassian-sdk.list \ + && curl -sSL https://packages.adoptium.net/artifactory/api/gpg/key/public | gpg --dearmor -o /etc/apt/keyrings/adoptium-archive-keyring.gpg \ + && echo "deb [signed-by=/etc/apt/keyrings/adoptium-archive-keyring.gpg] https://packages.adoptium.net/artifactory/deb $DISTRO main" >> /etc/apt/sources.list.d/adoptopenjdk.list \ + && apt-get update \ + && apt-get -y install --no-install-recommends \ + git \ + unzip \ + nodejs="$NODE_MAJOR".* \ + jq \ + expect \ + atlassian-plugin-sdk \ + temurin-8-jdk \ + xmlstarlet \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* \ + && npm install -g yarn + +# Avoiding JVM Delays Caused by Random Number Generation (https://docs.oracle.com/cd/E13209_01/wlcp/wlss30/configwlss/jvmrand.html) +RUN sed -i 's|securerandom.source=file:/dev/random|securerandom.source=file:/dev/urandom|g' "$JAVA_HOME/conf/security/java.security" + +USER sonarsource +WORKDIR /home/sonarsource diff --git a/.cirrus/cirrus-build.sh b/.cirrus/cirrus-build.sh new file mode 100755 index 00000000000..74362be0452 --- /dev/null +++ b/.cirrus/cirrus-build.sh @@ -0,0 +1,20 @@ +#!/bin/bash +set -euo pipefail + +source .cirrus/cirrus-env + +./gradlew build \ + -DbuildNumber="$BUILD_NUMBER" \ + -x test \ + --parallel --console plain --build-cache + +pushToCirrusCiCache() { + cd "${1}" + zipfile=$(ls -- *.zip) + echo "Uploading $zipfile to CirrusCI cache" + curl -s -X POST --data-binary @"$zipfile" "http://$CIRRUS_HTTP_CACHE_HOST/$zipfile" + echo "$zipfile successfully uploaded to CirrusCI cache" +} + +export -f pushToCirrusCiCache +pushToCirrusCiCache sonar-application/build/distributions diff --git a/.cirrus/cirrus-cache-dependencies.sh b/.cirrus/cirrus-cache-dependencies.sh new file mode 100755 index 00000000000..38359fa23f4 --- /dev/null +++ b/.cirrus/cirrus-cache-dependencies.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -euo pipefail + +source .cirrus/cirrus-env + +if [ -d "${GRADLE_USER_HOME?}/caches" ]; then + echo "gradle dependency cache already exists, bypassing dependencies loading" +else + ./gradlew cacheDependencies \ + --parallel --console plain --build-cache --info + ./gradlew cacheDependencies \ + --parallel --console plain --build-cache -Pqa --info +fi diff --git a/.cirrus/cirrus-env b/.cirrus/cirrus-env new file mode 100644 index 00000000000..84df2e8aee3 --- /dev/null +++ b/.cirrus/cirrus-env @@ -0,0 +1,11 @@ +#!/bin/bash +set -uo pipefail + +export GIT_SHA1=${CIRRUS_CHANGE_IN_REPO?} +export GITHUB_BASE_BRANCH=${CIRRUS_BASE_BRANCH:-} +export GITHUB_BRANCH=${CIRRUS_BRANCH?} +export GITHUB_REPO=${CIRRUS_REPO_FULL_NAME?} +export BUILD_NUMBER=${CI_BUILD_NUMBER?} +export PULL_REQUEST=${CIRRUS_PR:-false} +export PULL_REQUEST_SHA=${CIRRUS_BASE_SHA:-} +export PIPELINE_ID=${CIRRUS_BUILD_ID?} diff --git a/.cirrus/cirrus-junit.sh b/.cirrus/cirrus-junit.sh new file mode 100755 index 00000000000..13c103b0d22 --- /dev/null +++ b/.cirrus/cirrus-junit.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -euo pipefail + +source .cirrus/cirrus-env + +./gradlew cleanTest test jacocoTestReport \ + --parallel --configure-on-demand --console plain -Pqa diff --git a/.cirrus/cirrus-sq-analysis.sh b/.cirrus/cirrus-sq-analysis.sh new file mode 100755 index 00000000000..cfc020cc25d --- /dev/null +++ b/.cirrus/cirrus-sq-analysis.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -euo pipefail + +source .cirrus/cirrus-env + +: "${SONAR_HOST_URL?}" "${SONAR_TOKEN?}" + +git fetch --unshallow || true +if [ -n "${GITHUB_BASE_BRANCH:-}" ]; then + git fetch origin "${GITHUB_BASE_BRANCH}" +fi + +./gradlew sonar \ + -DbuildNumber="$BUILD_NUMBER" \ + -Dsonar.projectKey=sonarqube \ + -Dsonar.host.url="$SONAR_HOST_URL" \ + -Dsonar.token="$SONAR_TOKEN" \ + -Dsonar.analysis.buildNumber="$BUILD_NUMBER" \ + -Dsonar.analysis.pipeline="$PIPELINE_ID" \ + -Dsonar.analysis.repository="$GITHUB_REPO" \ + -Dsonar.analysis.sha1="$GIT_SHA1" \ + --parallel --configure-on-demand --console plain -Pqa diff --git a/.cirrus/cirrus-yarn-lint-report.sh b/.cirrus/cirrus-yarn-lint-report.sh new file mode 100755 index 00000000000..e6f32e50ae6 --- /dev/null +++ b/.cirrus/cirrus-yarn-lint-report.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -euo pipefail + +source .cirrus/cirrus-env + +./gradlew yarn_lint-report-ci \ + --parallel --configure-on-demand --console plain -Pqa diff --git a/.cirrus/cirrus-yarn-validate-ci.sh b/.cirrus/cirrus-yarn-validate-ci.sh new file mode 100755 index 00000000000..b3884ed5e2e --- /dev/null +++ b/.cirrus/cirrus-yarn-validate-ci.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -euo pipefail + +source .cirrus/cirrus-env + +./gradlew yarn_validate-ci \ + --parallel --configure-on-demand --console plain -Pqa |