Skip to content

Commit 2bba42e

Browse files
Update documentation on setting up a SonarCloud project (nhs-england-tools#122)
## Description <!-- Describe your changes in detail. --> ## Context <!-- Why is this change required? What problem does it solve? --> ## Type of changes - [x] Refactoring (non-breaking change) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would change existing functionality) - [ ] Bug fix (non-breaking change which fixes an issue) ## Checklist - [x] I am familiar with the [contributing guidelines](../docs/CONTRIBUTING.md) - [x] I have followed the code style of the project - [ ] I have added tests to cover my changes - [x] I have updated the documentation accordingly - [ ] This PR is a result of pair or mob programming --- ## Sensitive Information Declaration To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including [PII (Personal Identifiable Information) / PID (Personal Identifiable Data)](https://digital.nhs.uk/data-and-information/keeping-data-safe-and-benefitting-the-public) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter. - [x] I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes. --------- Signed-off-by: Alex Young <[email protected]> Co-authored-by: Alex Young <[email protected]>
1 parent 8b79e0a commit 2bba42e

File tree

1 file changed

+51
-12
lines changed

1 file changed

+51
-12
lines changed

docs/user-guides/Perform_static_analysis.md

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
- [Guide: Perform static analysis](#guide-perform-static-analysis)
44
- [Overview](#overview)
55
- [Key files](#key-files)
6-
- [Configuration checklist](#configuration-checklist)
6+
- [Setup](#setup)
77
- [Testing](#testing)
8+
- [Configuration checklist](#configuration-checklist)
89

910
## Overview
1011

@@ -19,26 +20,64 @@ Static code analysis is an essential part of modern software development. It pro
1920
- [perform-static-analysis/action.yaml](../../.github/actions/perform-static-analysis/action.yaml): GitHub action to run the script as part of the CI/CD pipeline
2021
- [.gitignore](../../.gitignore): Excludes the `.scannerwork` temporary directory created during the process
2122

23+
## Setup
24+
25+
Contact the GitHub Admins via their mailbox to have your [SonarCloud](https://sonarcloud.io) access set up.
26+
27+
## Testing
28+
29+
You can run and test static analysis locally on a developer's workstation using the following command
30+
31+
```shell
32+
export SONAR_ORGANISATION_KEY=nhs-england-tools # Replace with your organisation key
33+
export SONAR_PROJECT_KEY=repository-template # Replace with your project key
34+
export SONAR_TOKEN=[replace-with-your-sonar-token]
35+
./scripts/reports/perform-static-analysis.sh
36+
```
37+
2238
## Configuration checklist
2339

24-
- Contact the GitHub Admins via email to have your [SonarCloud](https://sonarcloud.io) project created within the organisation space
25-
- Create a bot account for your service. For more details, please see this [note](../../docs/adr/ADR-003_Acceptable_use_of_GitHub_PAT_and_Apps_for_authN_and_authZ.md#recommendation-for-github-admins). This account should be given access to your project and must own the `SONAR_TOKEN` for security reasons. Use this account to complete the rest of the activities in the Sonar service
40+
> [!WARNING]<br>
41+
> This section is to be used by the GitHub Admins.
42+
43+
The list demonstrates the manual way of configuring a project, however our aim is to automate all the activities below.
44+
45+
- Create a Sonar project within the organisation space:
46+
- Navigate to `+ > Analyze new project > create a project manually`
47+
- Choose the appropriate organisation
48+
- Set "Display name"
49+
- Set "Project key" (it should be populated automatically)
50+
- Set project visibility to "Public"
51+
- After clicking the 'Next' button, set "The new code for this project will be based on" to "Previous version"
52+
- Click "Create project"
53+
- Add two new groups under `Administration > Groups`:
54+
- `[Programme Name]`, all members of the project
55+
- `[Programme Name] Admins`, who will the project's quality gates and quality profiles
56+
- Assign members to the above groups accordingly
57+
- Set group permissions under `Administration > Permissions`:
58+
- For the `[Programme Name] Admins` group, assign:
59+
- "Quality Gates"
60+
- "Quality Profiles"
61+
- Manage project permissions, navigate to `Administration > Projects Management` and select the project you created
62+
- Click on `Edit Permissions`
63+
- Search for `[Programme Name] Admins` group and assign the following:
64+
- "Administer Issues"
65+
- "Administer Security Hotspots"
66+
- "Administer"
67+
- Ensure that other groups do not have unnecessary permissions to administer this project
2668
- Navigate to project `Administration > Analysis Method > Manually` and select `Other (for JS, TS, Go, Python, PHP, ...)`
2769
- In the [sonar-scanner.properties](../../scripts/config/sonar-scanner.properties) file in your repository, set the following properties according to the information provided above
2870
- Set `sonar.[language].[coverage-tool].reportPaths` to ensure the unit test coverage is reported back to Sonar
2971
- Do not set the `sonar.organization` and `sonar.projectKey` properties in this file; do the next step instead
72+
73+
- Use the Sonar token owned by the "SonarCloud Token GitHub Admins" service user. There is an existing token named "Scan all"
74+
75+
> [!NOTE]<br>
76+
> For an advance configuration create a bot account for your service. For more details, please see this [note](../../docs/adr/ADR-003_Acceptable_use_of_GitHub_PAT_and_Apps_for_authN_and_authZ.md#recommendation-for-github-admins). This account should be given access to your project and must own the `SONAR_TOKEN` for security reasons.
77+
3078
- Follow the documentation on [creating encrypted secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets) to add the `SONAR_TOKEN` secret to your repository. The GitHub action is already configured to fetch that secret and pass it as a variable. In addition to that:
3179
- Add `SONAR_ORGANISATION_KEY` variable (not a secret)
3280
- Add `SONAR_PROJECT_KEY` variable (not a secret)
3381
- Navigate to project `Administration > Analysis Method` and turn off the `Automatic Analysis` option
3482
- Please refrain from adding your repository to the GitHub SonarCloud App, as this app should not be used. Doing so will duplicate reports and initiate them outside the primary pipeline workflow
3583
- Confirm that the _"Perform static analysis"_ GitHub action is part of your GitHub CI/CD workflow and enforces the _"Sonar Way"_ quality gates. You can find more information about this in the [NHSE Software Engineering Quality Framework](https://github.com/NHSDigital/software-engineering-quality-framework/blob/main/tools/sonarqube.md)
36-
37-
## Testing
38-
39-
You can run and test static analysis locally on a developer's workstation using the following command
40-
41-
```shell
42-
export SONAR_TOKEN=[replace-with-your-sonar-token]
43-
./scripts/perform-static-analysis.sh
44-
```

0 commit comments

Comments
 (0)