Skip to content

Commit

Permalink
Tidy bash (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonJagger committed Apr 29, 2024
1 parent b7cceec commit 912e958
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Expand Up @@ -283,7 +283,7 @@ jobs:
version: ${{ vars.KOSLI_CLI_VERSION }}

- name: Attest SonarCloud as generic attestation in Kosli
run: ./sh/sonarcloud-scan-and-attest.sh
run: ./sh/sonarcloud_scan_and_attest.sh


sdlc-control-gate:
Expand Down
49 changes: 0 additions & 49 deletions sh/sonarcloud-scan-and-attest.sh

This file was deleted.

53 changes: 53 additions & 0 deletions sh/sonarcloud_scan_and_attest.sh
@@ -0,0 +1,53 @@
#!/usr/bin/env bash
set -Eeu

repo_root() { git rev-parse --show-toplevel; }

readonly OWNER="${KOSLI_ORG}"
readonly REPO="${SERVICE_NAME}"
readonly JSON_FILENAME=results.json

get_checks_json()
{
curl \
--header "Authorization: ${SONARCLOUD_TOKEN}" \
--request GET \
--url "https://sonarcloud.io/api/measures/component?metricKeys=alert_status%2Cquality_gate_details%2Cbugs%2Csecurity_issues%2Ccode_smells%2Ccomplexity%2Cmaintainability_issues%2Creliability_issues%2Ccoverage&component=${OWNER}_${REPO}"
}

parse_json()
{
local success, metric
get_checks_json | jq '.' > "${JSON_FILENAME}"
local -r measures_length=$(jq '.component.measures | length' "${JSON_FILENAME}")

success=""
for i in $(seq 0 $(( measures_length - 1 ))); do
metric=$(jq -r ".component.measures[$i].metric" "${JSON_FILENAME}")
if [ "${metric}" = "alert_status" ] ; then
success=$(jq -r ".component.measures[$i].value" "${JSON_FILENAME}")
break
fi
done

KOSLI_COMPLIANT=$([ "${success}" = "OK" ] && echo "true" || echo "false")
}

attest_to_kosli_generic()
{
local -r url="https://sonarcloud.io/project/overview?id=${OWNER}_${REPO}"
kosli attest generic \
--attachments="${JSON_FILENAME}" \
--compliant="${KOSLI_COMPLIANT}" \
--name="${REPO}.sonarcloud-scan" \
--external-url="sonarcloud-code-analysis=${url}"
}

remove_json()
{
rm "${JSON_FILENAME}"
}

parse_json
attest_to_kosli_generic
remove_json

0 comments on commit 912e958

Please sign in to comment.