Skip to content

Commit b6918de

Browse files
BUILD-6082: Implement sbom generation (#5647)
BUILD-6082: Implement sbom generation Signed-off-by: Jayadeep Kinavoor Madam <jayadeep.kinavoormadam@sonarsource.com>
1 parent 0071e33 commit b6918de

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

.cirrus.yaml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ env:
1111
USERPROFILE: C:\sonar-ci
1212
PATH: C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin;C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\Program Files (x86)\Microsoft SDKs\ClickOnce\SignTool;C:\Program Files\DigiCert\DigiCert One Signing Manager Tools;C:\sonar-ci\.dotnet\tools;${PATH}
1313
CIRRUS_WORKING_DIR: C:\sonar-ci
14-
CIRRUS_CLONE_DEPTH: 50
1514

1615
ec2_instance_definition: &INSTANCE_DEFINITION
1716
region: eu-central-1
18-
type: t3a.xlarge
17+
type: c6i.xlarge
1918
image: base-windows-dotnet-v20240523071308
2019
platform: windows
2120

@@ -41,6 +40,8 @@ build_task:
4140
SONARSOURCE_SNK_FILE: ${TMP_DIR}\SonarSource.snk
4241
SONARSOURCE_SNK: VAULT[development/team/languages/kv/data/strong_named_key data.SonarSourceSecret_snk]
4342
SONAR_TOKEN: VAULT[development/kv/data/sonarcloud data.token]
43+
SIGN_KEY: VAULT[development/kv/data/sign data.key]
44+
SIGN_PASSPHRASE: VAULT[development/kv/data/sign data.passphrase]
4445
clone_script: |
4546
git config --global core.autocrlf true
4647
git init
@@ -50,7 +51,7 @@ build_task:
5051
5152
calculate_version_script: *CALCULATE_VERSION_SCRIPT_DEFINITION
5253
prepare_signing_script: |
53-
if [[ "${CIRRUS_BRANCH}" == "${CIRRUS_DEFAULT_BRANCH}" || "${CIRRUS_BRANCH}" =~ "branch-.*" || "${CIRRUS_BRANCH}" =~ "sign-.*" ]]; then
54+
if [[ "${CIRRUS_BRANCH}" == "${CIRRUS_DEFAULT_BRANCH}" ]] || echo "${CIRRUS_BRANCH}" | grep -qE "^branch-.*" || echo "${CIRRUS_BRANCH}" | grep -qE "^sign-.*"; then
5455
mkdir -p "${TMP_DIR}"
5556
echo "${SONARSOURCE_SNK}" | base64 -d > "${SONARSOURCE_SNK_FILE}"
5657
echo "${SM_CLIENT_CERT_FILE_BASE64}" | base64 -d > "${SM_CLIENT_CERT_FILE}"
@@ -74,14 +75,27 @@ build_task:
7475
msbuild.exe "${SOLUTION_PATH}" -p:VsVersion=17.0 -p:VsTargetVersion=2022 -p:SignArtifacts=${SHOULD_SIGN} -p:AssemblyOriginatorKeyFile=${SONARSOURCE_SNK_FILE} -p:DeployExtension=false -p:Sha1=${CIRRUS_CHANGE_IN_REPO} -p:BuildNumber=${CI_BUILD_NUMBER} -p:Configuration=Release
7576
sign_artifact_script: |
7677
if [[ "${SHOULD_SIGN}" == "true" ]]; then
77-
nuget sign "binaries/SonarLint.VSIX-${SONAR_PROJECT_VERSION}.${CIRRUS_BUILD_ID}-2022.vsix" -HashAlgorithm SHA256 -CertificateFingerprint ${SM_CERT_FP} -Timestamper http://timestamp.digicert.com -TimestampHashAlgorithm SHA256
78+
nuget sign "binaries/SonarLint.VSIX-${SONAR_PROJECT_VERSION}.${CI_BUILD_NUMBER}-2022.vsix" -HashAlgorithm SHA256 -CertificateFingerprint ${SM_CERT_FP} -Timestamper http://timestamp.digicert.com -TimestampHashAlgorithm SHA256
7879
else
7980
echo "Artifact not signed"
8081
fi
8182
tests_script: |
8283
vstest.console.exe --EnableCodeCoverage --Logger:trx --ResultsDirectory:"TestResults" src/**/bin/**/Sonar*.*Tests.dll
8384
sonarcloud_analysis_script:
8485
- dotnet sonarscanner end -d:sonar.token=${SONAR_TOKEN}
86+
sbom_generation_script: |
87+
if [[ "${SHOULD_SIGN}" == "true" ]]; then
88+
sbomname="SonarLint.visualstudio.sbom-$SONAR_PROJECT_VERSION.$CI_BUILD_NUMBER-2022.json"
89+
gpg --batch --passphrase "$SIGN_PASSPHRASE" --allow-secret-key-import --import <(echo "$SIGN_KEY")
90+
gpg --list-secret-keys
91+
dotnet tool install --global CycloneDX
92+
dotnet CycloneDX SonarLint.VisualStudio.Integration.sln -t -j -o binaries
93+
cd binaries
94+
mv bom.json $sbomname
95+
gpg --pinentry-mode loopback --passphrase "$SIGN_PASSPHRASE" --armor --detach-sig --default-key infra@sonarsource.com "$sbomname"
96+
echo "signed $sbomname"
97+
ls -al
98+
fi
8599
86100
dogfood_task:
87101
depends_on:

0 commit comments

Comments
 (0)