Skip to content

Commit

Permalink
Mac Support for ShellCheck (#14)
Browse files Browse the repository at this point in the history
* Mac Support for ShellCheck
  • Loading branch information
gitricko authored Jun 8, 2024
1 parent 7bb09a2 commit af9db33
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 55 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ jobs:

- name: Check Sonar Metrics
run: |
echo "Checking for any vulnerabilities in Sonar Metrics JSON"
echo "Checking for 0 vulnerabilities in Sonar Metrics JSON"
VULN=$(cat ./blahblah.json | jq -r '.component.measures[] | select(.metric == "vulnerabilities").value')
echo "# of vulnerabilities = ${VULN}"
[ ${VULN} -eq "0" ]
[ "${VULN}" -eq "0" ]
echo "Checking for any issues <= 2 in Sonar Metrics JSON"
ISSUES=$(cat ./blahblah.json | jq -r '.component.measures[] | select(.metric == "open_issues").value')
echo "# of issues = ${ISSUES}"
[ "${ISSUES}" -le 2 ]
95 changes: 48 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,59 @@

# Sonarless v1

This action and its developer friendly helper scripts enable sonarqube scanning for your repository without a need of a dedicated hosted sonarqube server. It boots up a sonarqube docker instance and enable developers to scan checkout code and give a metric json so that you can check the quality of the code.
This developer-friendly CLI and GitHub Action enable SonarQube scanning for your repository without the need for a dedicated hosted SonarQube server. It starts a SonarQube Docker instance, allowing developers to scan code, check results, and generate a JSON metrics file for automation. This ensures you can easily assess and maintain the quality of your code.

# What's new

Please refer to the [release page](https://github.com/gitricko/sonarless/releases/latest) for the latest release notes.

# Usage
# Use Sonarless in your Local Dev

To install CLI, paste and run the following in a terminal:
> `curl -s "https://raw.githubusercontent.com/gitricko/sonarless/main/install.sh" | bash`
```ssh
_
___ ___ _ __ __ _ _ __ | | ___ ___ ___
/ __| / _ \ | "_ \ / _` || "__|| | / _ \/ __|/ __|
\__ \| (_) || | | || (_| || | | || __/\__ \\__ \
|___/ \___/ |_| |_| \__,_||_| |_| \___||___/|___/
Now attempting installation...
Looking for a previous installation of SONARLESS...
Looking for docker...
Looking for jq...
Looking for sed...
Installing Sonarless helper scripts...
* Downloading...
######################################################################## 100.0%
Please open a new terminal, or run the following in the existing one:
alias sonarless='/home/runner/.sonarless/makefile.sh'
Then issue the following command:
sonarless help
Enjoy!!!
```
To understand CLI sub-commands, just run `sonarless help`

Usually, you only need to know 2 sub-commands
- `sonarless scan`: to start scanning your code in the current directory will be uploaded for scanning. When the scan is done, just login webui into your local personal instance of sonarqube via [http://localhost:9234](http://localhost:9234) to get details from SonarQube. The default password for `admin` is `sonarless`

- `sonarless results`: to generate `sonar-metrics.json` metrics file in your current directory

To clean up your sonar instance, just run `sonarless docker-clean`. SonarQube docker instance will be stop and all images removed.

This CLI works perfectly with Github CodeSpace


# GitHub Action Usage

<!-- start usage -->
```yaml
Expand Down Expand Up @@ -110,51 +156,6 @@ jobs:
sonar-instance-port: '1234'
```

# Use Sonarless in your Local Dev

To install automation scriptlets, paste and run the following in a terminal:
> `curl -s "https://raw.githubusercontent.com/gitricko/sonarless/main/install.sh" | bash`

```ssh
_
___ ___ _ __ __ _ _ __ | | ___ ___ ___
/ __| / _ \ | "_ \ / _` || "__|| | / _ \/ __|/ __|
\__ \| (_) || | | || (_| || | | || __/\__ \\__ \
|___/ \___/ |_| |_| \__,_||_| |_| \___||___/|___/


Now attempting installation...

Looking for a previous installation of SONARLESS...
Looking for docker...
Looking for jq...
Looking for sed...
Installing Sonarless helper scripts...
* Downloading...

######################################################################## 100.0%

Please open a new terminal, or run the following in the existing one:

alias sonarless='/home/runner/.sonarless/makefile.sh'

Then issue the following command:

sonarless help

Enjoy!!!
```
To understand the sub-commands, just run `sonarless help`

Usually, you only need to know 2 sub-commands
- `sonarless scan`: to start scanning your code in the current directory will be uploaded for scanning. When the scan is done, just login webui into your local personal instance of sonarqube via [http://localhost:9234](http://localhost:9234) to get details from SonarQube. The default password for `admin` is `sonarless`

- `sonarless results`: to generate `sonar-metrics.json` metrics file in your current directory

To clean up your sonar instance, just run `sonarless docker-clean`. SonarQube docker instance will be stop and all images removed.

This small scriptlet works perfectly with Github CodeSpace

# Coffee

If you find this small helper script and action helpful, buy me a [sip of coffee](https://ko-fi.com/gitricko) here to show your appreciation (only if you want to)
17 changes: 11 additions & 6 deletions makefile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,24 @@ function sonar-ext-get() {

if [ ! -f "${SONAR_EXTENSION_DIR}/shellcheck" ]; then
# src: https://github.com/koalaman/shellcheck/blob/master/Dockerfile.multi-arch
arch="$(uname -m)";
tag=latest
arch="$(uname -m)"
os="$(uname | sed 's/.*/\L&/')"
tag="v0.10.0"

if [ "${arch}" = 'armv7l' ]; then
arch='armv6hf';
arch='armv6hf'
fi

if [ "${arch}" = 'arm64' ]; then
arch='aarch64'
fi

url_base='https://github.com/koalaman/shellcheck/releases/download/'
tar_file="${tag}/shellcheck-${tag}.linux.${arch}.tar.xz";
tar_file="${tag}/shellcheck-${tag}.${os}.${arch}.tar.xz"
curl -s --fail --location --progress-bar "${url_base}${tar_file}" | tar xJf -

mv "shellcheck-${tag}/shellcheck" "${SONAR_EXTENSION_DIR}/";
rm -rf "shellcheck-${tag}";
mv "shellcheck-${tag}/shellcheck" "${SONAR_EXTENSION_DIR}/"
rm -rf "shellcheck-${tag}"
fi

SONAR_SHELLCHECK="sonar-shellcheck-plugin-2.5.0.jar"
Expand Down

0 comments on commit af9db33

Please sign in to comment.