Skip to content

Commit e946db0

Browse files
CCM-15866: Address Sonar Findings (#105)
* CCM-15866: Address Sonar Findings - Avoid input interpolation within run blocks * CCM-15866: Address Sonar Findings - Bash Conditional Construct Fixes * CCM-15866: Address Sonar Findings - Bash Conditional Construct Fixes * CCM-15866: Address Sonar Findings - Exclude Container Tests * CCM-15866: Address Sonar Findings - Exclude Container Tests and ESLint config * CCM-15866: Address Sonar Findings - Better Perms in Jekyll Container * CCM-15866: Address Sonar Findings - Revert Better Perms in Jekyll Container * CCM-15866: Address Sonar Findings - Additional Excludes for Coverage of Boilerplate Coder * CCM-15866: Address Sonar Findings - Additional Excludes for Coverage of Boilerplate Coder * CCM-15866: Address Sonar Findings - Lots more
1 parent 702468c commit e946db0

28 files changed

Lines changed: 331 additions & 117 deletions

.github/actions/build-docs/action.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ runs:
3030
working-directory: ./docs
3131
# Outputs to the './_site' directory by default
3232
shell: bash
33-
run: make build BASE_URL="${{ steps.pages.outputs.base_path }}" VERSION="${{ inputs.version }}"
33+
run: make build BASE_URL="$BASE_URL" VERSION="$VERSION"
3434
#run: bundle exec jekyll build --baseurl "${{ steps.pages.outputs.base_path }}"
3535
env:
3636
JEKYLL_ENV: production
37+
BASE_URL: ${{ steps.pages.outputs.base_path }}
38+
VERSION: ${{ inputs.version }}
3739
- name: Upload artifact
3840
# Automatically uploads an artifact from the './_site' directory by default
3941
uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3

.github/actions/create-lines-of-code-report/action.yaml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ runs:
2424
steps:
2525
- name: "Create CLOC report"
2626
shell: bash
27+
env:
28+
BUILD_DATETIME: ${{ inputs.build_datetime }}
2729
run: |
28-
export BUILD_DATETIME=${{ inputs.build_datetime }}
2930
./scripts/reports/create-lines-of-code-report.sh
3031
- name: "Compress CLOC report"
3132
shell: bash
@@ -40,8 +41,15 @@ runs:
4041
- name: "Check prerequisites for sending the report"
4142
shell: bash
4243
id: check
44+
env:
45+
ROLE_NAME: ${{ inputs.idp_aws_report_upload_role_name }}
46+
BUCKET_ENDPOINT: ${{ inputs.idp_aws_report_upload_bucket_endpoint }}
4347
run: |
44-
echo "secrets_exist=${{ inputs.idp_aws_report_upload_role_name != '' && inputs.idp_aws_report_upload_bucket_endpoint != '' }}" >> $GITHUB_OUTPUT
48+
if [[ -n "$ROLE_NAME" && -n "$BUCKET_ENDPOINT" ]]; then
49+
echo "secrets_exist=true" >> "$GITHUB_OUTPUT"
50+
else
51+
echo "secrets_exist=false" >> "$GITHUB_OUTPUT"
52+
fi
4553
- name: "Authenticate to send the report"
4654
if: steps.check.outputs.secrets_exist == 'true'
4755
uses: aws-actions/configure-aws-credentials@ec61189d14ec14c8efccab744f656cffd0e33f37 # v6
@@ -51,7 +59,10 @@ runs:
5159
- name: "Send the CLOC report to the central location"
5260
shell: bash
5361
if: steps.check.outputs.secrets_exist == 'true'
62+
env:
63+
BUCKET_ENDPOINT: ${{ inputs.idp_aws_report_upload_bucket_endpoint }}
64+
BUILD_TIMESTAMP: ${{ inputs.build_timestamp }}
5465
run: |
5566
aws s3 cp \
5667
./lines-of-code-report.json.zip \
57-
${{ inputs.idp_aws_report_upload_bucket_endpoint }}/${{ inputs.build_timestamp }}-lines-of-code-report.json.zip
68+
"$BUCKET_ENDPOINT/$BUILD_TIMESTAMP-lines-of-code-report.json.zip"

.github/actions/perform-static-analysis/action.yaml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,21 @@ runs:
1616
- name: "Check prerequisites for performing static analysis"
1717
shell: bash
1818
id: check
19-
run: echo "secret_exist=${{ inputs.sonar_token != '' }}" >> $GITHUB_OUTPUT
19+
env:
20+
SONAR_TOKEN: ${{ inputs.sonar_token }}
21+
run: |
22+
if [[ -n "$SONAR_TOKEN" ]]; then
23+
echo "secret_exist=true" >> "$GITHUB_OUTPUT"
24+
else
25+
echo "secret_exist=false" >> "$GITHUB_OUTPUT"
26+
fi
2027
- name: "Perform static analysis"
2128
shell: bash
2229
if: steps.check.outputs.secret_exist == 'true'
30+
env:
31+
SONAR_ORGANISATION_KEY: ${{ inputs.sonar_organisation_key }}
32+
SONAR_PROJECT_KEY: ${{ inputs.sonar_project_key }}
33+
SONAR_TOKEN: ${{ inputs.sonar_token }}
2334
run: |
2435
export BRANCH_NAME=${GITHUB_HEAD_REF:-$(echo $GITHUB_REF | sed 's#refs/heads/##')}
25-
export SONAR_ORGANISATION_KEY=${{ inputs.sonar_organisation_key }}
26-
export SONAR_PROJECT_KEY=${{ inputs.sonar_project_key }}
27-
export SONAR_TOKEN=${{ inputs.sonar_token }}
2836
./scripts/reports/perform-static-analysis.sh

.github/actions/scan-dependencies/action.yaml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ runs:
2424
steps:
2525
- name: "Generate SBOM"
2626
shell: bash
27+
env:
28+
BUILD_DATETIME: ${{ inputs.build_datetime }}
2729
run: |
28-
export BUILD_DATETIME=${{ inputs.build_datetime }}
2930
./scripts/reports/create-sbom-report.sh
3031
- name: "Compress SBOM report"
3132
shell: bash
@@ -39,8 +40,9 @@ runs:
3940
retention-days: 21
4041
- name: "Scan vulnerabilities"
4142
shell: bash
43+
env:
44+
BUILD_DATETIME: ${{ inputs.build_datetime }}
4245
run: |
43-
export BUILD_DATETIME=${{ inputs.build_datetime }}
4446
./scripts/reports/scan-vulnerabilities.sh
4547
- name: "Compress vulnerabilities report"
4648
shell: bash
@@ -55,7 +57,15 @@ runs:
5557
- name: "Check prerequisites for sending the reports"
5658
shell: bash
5759
id: check
58-
run: echo "secrets_exist=${{ inputs.idp_aws_report_upload_role_name != '' && inputs.idp_aws_report_upload_bucket_endpoint != '' }}" >> $GITHUB_OUTPUT
60+
env:
61+
ROLE_NAME: ${{ inputs.idp_aws_report_upload_role_name }}
62+
BUCKET_ENDPOINT: ${{ inputs.idp_aws_report_upload_bucket_endpoint }}
63+
run: |
64+
if [[ -n "$ROLE_NAME" && -n "$BUCKET_ENDPOINT" ]]; then
65+
echo "secrets_exist=true" >> "$GITHUB_OUTPUT"
66+
else
67+
echo "secrets_exist=false" >> "$GITHUB_OUTPUT"
68+
fi
5969
- name: "Authenticate to send the reports"
6070
if: steps.check.outputs.secrets_exist == 'true'
6171
uses: aws-actions/configure-aws-credentials@ec61189d14ec14c8efccab744f656cffd0e33f37 # v6
@@ -65,10 +75,13 @@ runs:
6575
- name: "Send the SBOM and vulnerabilities reports to the central location"
6676
shell: bash
6777
if: steps.check.outputs.secrets_exist == 'true'
78+
env:
79+
BUCKET_ENDPOINT: ${{ inputs.idp_aws_report_upload_bucket_endpoint }}
80+
BUILD_TIMESTAMP: ${{ inputs.build_timestamp }}
6881
run: |
6982
aws s3 cp \
7083
./sbom-repository-report.json.zip \
71-
${{ inputs.idp_aws_report_upload_bucket_endpoint }}/${{ inputs.build_timestamp }}-sbom-repository-report.json.zip
84+
"$BUCKET_ENDPOINT/$BUILD_TIMESTAMP-sbom-repository-report.json.zip"
7285
aws s3 cp \
7386
./vulnerabilities-repository-report.json.zip \
74-
${{ inputs.idp_aws_report_upload_bucket_endpoint }}/${{ inputs.build_timestamp }}-vulnerabilities-repository-report.json.zip
87+
"$BUCKET_ENDPOINT/$BUILD_TIMESTAMP-vulnerabilities-repository-report.json.zip"

.github/scripts/dispatch_internal_repo_workflow.sh

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Usage:
5050
[--overrideProjectName <name>] \
5151
[--overrideRoleName <name>]
5252
EOF
53+
return 0
5354
}
5455

5556
require_arg() {
@@ -61,6 +62,8 @@ require_arg() {
6162
usage
6263
exit 1
6364
fi
65+
66+
return 0
6467
}
6568

6669
while [[ $# -gt 0 ]]; do
@@ -110,7 +113,7 @@ while [[ $# -gt 0 ]]; do
110113
shift 2
111114
;;
112115
*)
113-
echo "[ERROR] Unknown argument: $1"
116+
echo "[ERROR] Unknown argument: $1" >&2
114117
exit 1
115118
;;
116119
esac
@@ -124,20 +127,23 @@ require_arg "--targetComponent" "${targetComponent:-}"
124127
require_arg "--targetAccountGroup" "${targetAccountGroup:-}"
125128

126129
if [[ -z "$APP_PEM_FILE" ]]; then
127-
echo "[ERROR] PEM_FILE environment variable is not set or is empty."
130+
echo "[ERROR] PEM_FILE environment variable is not set or is empty." >&2
128131
exit 1
129132
fi
130133

131134
if [[ -z "$APP_CLIENT_ID" ]]; then
132-
echo "[ERROR] CLIENT_ID environment variable is not set or is empty."
135+
echo "[ERROR] CLIENT_ID environment variable is not set or is empty." >&2
133136
exit 1
134137
fi
135138

136139
now=$(date +%s)
137140
iat=$((${now} - 60)) # Issues 60 seconds in the past
138141
exp=$((${now} + 600)) # Expires 10 minutes in the future
139142

140-
b64enc() { openssl base64 | tr -d '=' | tr '/+' '_-' | tr -d '\n'; }
143+
b64enc() {
144+
openssl base64 | tr -d '=' | tr '/+' '_-' | tr -d '\n'
145+
return 0
146+
}
141147

142148
header_json='{
143149
"typ":"JWT",
@@ -178,7 +184,7 @@ PR_TRIGGER_PAT=$(curl --request POST \
178184

179185
# Set default values if not provided
180186
if [[ -z "$PR_TRIGGER_PAT" ]]; then
181-
echo "[ERROR] PR_TRIGGER_PAT environment variable is not set or is empty."
187+
echo "[ERROR] PR_TRIGGER_PAT environment variable is not set or is empty." >&2
182188
exit 1
183189
fi
184190

@@ -244,7 +250,7 @@ trigger_response=$(curl -s -L \
244250
-d "$DISPATCH_EVENT" 2>&1)
245251

246252
if [[ $? -ne 0 ]]; then
247-
echo "[ERROR] Failed to trigger workflow. Response: $trigger_response"
253+
echo "[ERROR] Failed to trigger workflow. Response: $trigger_response" >&2
248254
exit 1
249255
fi
250256

@@ -264,8 +270,8 @@ for _ in {1..18}; do
264270
"https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/runs?event=workflow_dispatch")
265271

266272
if ! echo "$response" | jq empty 2>/dev/null; then
267-
echo "[ERROR] Invalid JSON response from GitHub API during workflow polling:"
268-
echo "$response"
273+
echo "[ERROR] Invalid JSON response from GitHub API during workflow polling:" >&2
274+
echo "$response" >&2
269275
exit 1
270276
fi
271277

@@ -303,7 +309,7 @@ for _ in {1..18}; do
303309
done
304310

305311
if [[ -z "$workflow_run_url" || "$workflow_run_url" == null ]]; then
306-
echo "[ERROR] Failed to get the workflow run url. Exiting."
312+
echo "[ERROR] Failed to get the workflow run url. Exiting." >&2
307313
exit 1
308314
fi
309315

@@ -318,21 +324,21 @@ while true; do
318324
status=$(echo "$response" | jq -r '.status')
319325
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Workflow status: $status"
320326

321-
if [ "$status" == "completed" ]; then
327+
if [[ "$status" == "completed" ]]; then
322328
conclusion=$(echo "$response" | jq -r '.conclusion')
323329
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Workflow conclusion: $conclusion"
324330

325-
if [ -z "$conclusion" ] || [ "$conclusion" == "null" ]; then
331+
if [[ -z "$conclusion" || "$conclusion" == "null" ]]; then
326332
echo "[WARN] Workflow marked completed but conclusion not yet available, retrying..."
327333
sleep 5
328334
continue
329335
fi
330336

331-
if [ "$conclusion" == "success" ]; then
337+
if [[ "$conclusion" == "success" ]]; then
332338
echo "[SUCCESS] Workflow completed successfully!"
333339
exit 0
334340
else
335-
echo "[FAIL] Workflow failed with conclusion: $conclusion"
341+
echo "[FAIL] Workflow failed with conclusion: $conclusion" >&2
336342
exit 1
337343
fi
338344
fi

.github/workflows/cicd-3-deploy.yaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ jobs:
7676
shell: bash
7777
env:
7878
GH_TOKEN: ${{ github.token }}
79+
INCLUDE_PRERELEASES: ${{ inputs.include_prereleases }}
80+
REQUESTED_VERSION: ${{ inputs.version }}
7981
run: |
80-
if [[ ${{inputs.include_prereleases}} == true ]]; then
82+
if [[ "$INCLUDE_PRERELEASES" == "true" ]]; then
8183
json=$(gh release list --json tagName --limit 1 --exclude-drafts)
8284
else
8385
json=$(gh release list --json tagName --limit 1 --exclude-drafts --exclude-pre-releases)
@@ -88,19 +90,20 @@ jobs:
8890
release_version=$(echo $json | (jq -r '.[0].tagName'))
8991
if [[ $release_version == null ]]; then exit 1; else echo $release_version; fi
9092
91-
if [[ ${{inputs.version}} == latest ]]; then
92-
echo release_version=$(echo $release_version) >> $GITHUB_OUTPUT
93+
if [[ "$REQUESTED_VERSION" == "latest" ]]; then
94+
echo "release_version=$release_version" >> "$GITHUB_OUTPUT"
9395
else
94-
echo release_version=$(echo ${{inputs.version}}) >> $GITHUB_OUTPUT
96+
echo "release_version=$REQUESTED_VERSION" >> "$GITHUB_OUTPUT"
9597
fi
9698
9799
- name: "Get release version"
98100
id: download-asset
99101
shell: bash
100102
env:
101103
GH_TOKEN: ${{ github.token }}
104+
RELEASE_VERSION: ${{ steps.get-asset-version.outputs.release_version }}
102105
run: |
103-
gh release download ${{steps.get-asset-version.outputs.release_version}} -p jekyll-docs-*.tar --output artifact.tar
106+
gh release download "$RELEASE_VERSION" -p jekyll-docs-*.tar --output artifact.tar
104107
105108
- uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6
106109
with:

containers/example-app/src/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Placeholder HTTP server for AppRunner. Replace with real application code.
2-
import http from 'http';
2+
import http from 'node:http';
33

44
export const createRequestHandler = () => {
55
return (_req: http.IncomingMessage, res: http.ServerResponse) => {

scripts/config/sonar-scanner.properties

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
sonar.host.url=https://sonarcloud.io
44
sonar.qualitygate.wait=true
55
sonar.sourceEncoding=UTF-8
6-
sonar.exclusions=lambdas/*/src/__tests__/**/*
6+
sonar.sources=.
7+
sonar.exclusions=lambdas/*/src/__tests__/**/*,infrastructure/terraform/bin/terraform.sh
78
sonar.terraform.provider.aws.version=5.54.1
89
sonar.cpd.exclusions=**.test.*
9-
sonar.coverage.exclusions=tests/, **/*.dev.*, lambdas/**/src/__tests__, utils/utils/src/zod-validators.ts ,**/jest.config.ts,scripts/**/*
10+
sonar.coverage.exclusions=tests/, **/*.dev.*, lambdas/**/src/__tests__, utils/utils/src/zod-validators.ts ,**/jest.config.ts,scripts/**/*, containers/**/src/__tests__, eslint.config.mjs, docs/assets/js/nhs-notify.js, containers/example-app/src/server.ts
1011
sonar.javascript.lcov.reportPaths=lcov.info

scripts/docker/dgoss.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ CONTAINER_RUNTIME="${CONTAINER_RUNTIME:-docker}"
1515

1616
info() {
1717
echo -e "INFO: $*" >&2;
18+
return 0
1819
}
1920
error() {
2021
echo -e "ERROR: $*" >&2;
@@ -24,14 +25,15 @@ error() {
2425
cleanup() {
2526
set +e
2627
{ kill "$log_pid" && wait "$log_pid"; } 2> /dev/null
27-
if [ -n "$CONTAINER_LOG_OUTPUT" ]; then
28+
if [[ -n "$CONTAINER_LOG_OUTPUT" ]]; then
2829
cp "$tmp_dir/docker_output.log" "$CONTAINER_LOG_OUTPUT"
2930
fi
3031
rm -rf "$tmp_dir"
3132
if [[ $id ]];then
3233
info "Deleting container"
3334
$CONTAINER_RUNTIME rm -vf "$id" > /dev/null
3435
fi
36+
return 0
3537
}
3638

3739
run(){
@@ -47,7 +49,7 @@ run(){
4749
case "$GOSS_FILES_STRATEGY" in
4850
mount)
4951
info "Starting $CONTAINER_RUNTIME container"
50-
if [ "$CONTAINER_RUNTIME" == "podman" -a $# == 2 ]; then
52+
if [[ "$CONTAINER_RUNTIME" == "podman" && $# == 2 ]]; then
5153
id=$($CONTAINER_RUNTIME run -d -v "$tmp_dir:/goss:z" "${@:2}" sleep infinity)
5254
else
5355
id=$($CONTAINER_RUNTIME run -d -v "$tmp_dir:/goss:z" "${@:2}")
@@ -67,6 +69,7 @@ run(){
6769
$CONTAINER_RUNTIME logs -f "$id" > "$tmp_dir/docker_output.log" 2>&1 &
6870
log_pid=$!
6971
info "Container ID: ${id:0:8}"
72+
return 0
7073
}
7174

7275
get_docker_file() {
@@ -79,6 +82,7 @@ get_docker_file() {
7982
$CONTAINER_RUNTIME cp "${cid}:${src}" "${dst}"
8083
info "Copied '${src}' from container to '${dst}'"
8184
fi
85+
return 0
8286
}
8387

8488
# Main
@@ -113,7 +117,7 @@ case "$1" in
113117
fi
114118
[[ $GOSS_SLEEP ]] && { info "Sleeping for $GOSS_SLEEP"; sleep "$GOSS_SLEEP"; }
115119
info "Container health"
116-
if [ "true" != "$($CONTAINER_RUNTIME inspect -f '{{.State.Running}}' "$id")" ]; then
120+
if [[ "true" != "$($CONTAINER_RUNTIME inspect -f '{{.State.Running}}' "$id")" ]]; then
117121
$CONTAINER_RUNTIME logs "$id" >&2
118122
error "the container failed to start"
119123
fi

0 commit comments

Comments
 (0)