Skip to content

Commit

Permalink
SONARPHP-1523 Migrate CI pipeline to Starlak (#1300)
Browse files Browse the repository at this point in the history
  • Loading branch information
GabinL21 authored Nov 7, 2024
1 parent 717d0fc commit 5488645
Show file tree
Hide file tree
Showing 7 changed files with 415 additions and 214 deletions.
38 changes: 36 additions & 2 deletions .cirrus.star
Original file line number Diff line number Diff line change
@@ -1,4 +1,38 @@
load("github.com/SonarSource/cirrus-modules@v2", "load_features")
# Check Starlark specs: https://github.com/bazelbuild/starlark/blob/master/spec.md
# DevInfra modules
load("github.com/SonarSource/cirrus-modules@v3", "load_features")
# Modules
load(
"github.com/SonarSource/cirrus-modules/cloud-native/helper.star@analysis/master",
"merge_dict"
)
load(".cirrus/modules/env.star", "env")
load(
".cirrus/modules/build.star",
"build_task",
"build_test_analyze_task",
"sca_scan_task"
)
load(
".cirrus/modules/qa.star",
"qa_os_win_task",
"qa_plugin_task",
"qa_ruling_task",
"qa_pr_analysis_task"
)
load(".cirrus/modules/promote.star", "promote_task")


def main(ctx):
return load_features(ctx)
conf = dict()
merge_dict(conf, load_features(ctx))
merge_dict(conf, env())
merge_dict(conf, build_task())
merge_dict(conf, build_test_analyze_task())
merge_dict(conf, qa_os_win_task())
merge_dict(conf, sca_scan_task())
merge_dict(conf, qa_plugin_task())
merge_dict(conf, qa_ruling_task())
merge_dict(conf, qa_pr_analysis_task())
merge_dict(conf, promote_task())
return conf
212 changes: 0 additions & 212 deletions .cirrus.yml

This file was deleted.

144 changes: 144 additions & 0 deletions .cirrus/modules/build.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
load(
"github.com/SonarSource/cirrus-modules/cloud-native/env.star@analysis/master",
"pgp_signing_env",
"next_env",
"whitesource_api_env"
)
load(
"github.com/SonarSource/cirrus-modules/cloud-native/conditions.star@analysis/master",
"is_main_branch",
"is_branch_qa_eligible"
)
load(
"github.com/SonarSource/cirrus-modules/cloud-native/platform.star@analysis/master",
"base_image_container_builder"
)
load(
"github.com/SonarSource/cirrus-modules/cloud-native/cache.star@analysis/master",
"gradle_cache",
"cleanup_gradle_script",
"gradle_wrapper_cache",
"project_version_cache",
"store_project_version_script"
)


#
# Common
#

def profile_report_artifacts():
return {
"profile_report_artifacts": {
"path": "build/reports/profile/profile-*.html"
}
}


#
# Build
#

def build_script():
return [
"source cirrus-env BUILD",
"source .cirrus/use-gradle-wrapper.sh",
"regular_gradle_build_deploy_analyze ${BUILD_ARGUMENTS}",
"source set_gradle_build_version ${BUILD_NUMBER}",
"echo export PROJECT_VERSION=${PROJECT_VERSION} >> ~/.profile"
]


def build_env():
env = pgp_signing_env()
env |= next_env()
env |= {
"DEPLOY_PULL_REQUEST": "true",
"BUILD_ARGUMENTS": "-x test -x sonar"
}
return env


def build_task():
return {
"build_task": {
"env": build_env(),
"eks_container": base_image_container_builder(cpu=2, memory="4G"),
"project_version_cache": project_version_cache(),
"gradle_cache": gradle_cache(),
"gradle_wrapper_cache": gradle_wrapper_cache(),
"build_script": build_script(),
"cleanup_gradle_script": cleanup_gradle_script(),
"store_project_version_script": store_project_version_script()
}
}


#
# Build test analyze
#

def build_test_env():
env = pgp_signing_env()
env |= next_env()
env |= {
"DEPLOY_PULL_REQUEST": "false",
"BUILD_ARGUMENTS": "-x artifactoryPublish"
}
return env


def build_test_analyze_task():
return {
"build_test_analyze_task": {
"only_if": is_branch_qa_eligible(),
"depends_on": "build",
"env": build_test_env(),
"eks_container": base_image_container_builder(cpu=2, memory="4G"),
"gradle_cache": gradle_cache(),
"gradle_wrapper_cache": gradle_wrapper_cache(),
"build_script": build_script(),
"on_failure": {
"junit_artifacts": {
"path": "**/test-results/**/*.xml",
"format": "junit"
}
},
"cleanup_gradle_script": cleanup_gradle_script(),
}
}


#
# WhiteSource scan
#

def whitesource_script():
return [
"source cirrus-env QA",
"source .cirrus/use-gradle-wrapper.sh",
"source ${PROJECT_VERSION_CACHE_DIR}/evaluated_project_version.txt",
"GRADLE_OPTS=\"-Xmx64m -Dorg.gradle.jvmargs='-Xmx3G' -Dorg.gradle.daemon=false\" ./gradlew ${GRADLE_COMMON_FLAGS} :php-frontend:processResources -Pkotlin.compiler.execution.strategy=in-process",
"source ws_scan.sh"
]


def sca_scan_task():
return {
"sca_scan_task": {
"only_if": is_main_branch(),
"depends_on": "build",
"env": whitesource_api_env(),
"eks_container": base_image_container_builder(cpu=1, memory="4G"),
"gradle_cache": gradle_cache(),
"gradle_wrapper_cache": gradle_wrapper_cache(),
"whitesource_script": whitesource_script(),
"cleanup_gradle_script": cleanup_gradle_script(),
"allow_failures": "true",
"always": {
"ws_artifacts": {
"path": "whitesource/**/*"
}
},
}
}
Loading

0 comments on commit 5488645

Please sign in to comment.