Skip to content

Commit

Permalink
Merge pull request #10 from patriotsoftware/DVO-4447
Browse files Browse the repository at this point in the history
DVO-4447 update project-validation-action
  • Loading branch information
maa37 authored Oct 30, 2023
2 parents 5048389 + a127fdc commit 331e8fe
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 61 deletions.
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# project-validation-action

This action is intended to share a common set of steps we use to
validate the quality of a project.
validate the quality of a project on SonarQube.

- Checkout the code
- Start Sonar
Expand All @@ -19,18 +19,6 @@ The Sonar tool version we install for this run. Default
is 5.8.0 but this param will allow one to override if
needed.

#### 'sonar-token' (required)
The secret Sonar token for authenticating with Sonar.

#### 'github-token' (required)
The secret Github token for authenticating with Github.

#### 'aws-access-key-id' (required)
The AWS access key id, should always be for dev.

#### 'aws-secret-access-key' (required)
The AWS secret access key, should always be for dev.

#### 'use-dependencies' (optional)
Tests can be ran with dependencies if needed. Dependencies
can be defined in a docker compose file. And this switch
Expand All @@ -42,12 +30,27 @@ This parameter tells the action where to find the
Docker compose file that defines the dependencies
needed. Default is 'docker-compose/test-dependencies-compose.yml'

#### 'sonar-token' (required)
The secret Sonar token for authenticating with Sonar.

#### 'path-to-repo-root' (optional)
This parameter helps docker containers access local files in the repo.

#### 'tests-path' (optional)
The path to .NET tests by default is 'test/'

#### 'dotnet-test-command-args' (optional)
Arguments set on 'dotnet test' command arguments

#### 'local-runsettings-filename' (optional)
Full 'local.runsettings' file path, use NONE when file not required

#### 'upload-sonar-results' (optional)
This parameter controls whether to upload Sonar results as an artifact.
default is '--filter TestCategory!="Smoke"'

#### 'fail-on-failure' (optional)
Quality Gate will turn red and fail. Set to 'true' by default.

## Sample Use

Expand All @@ -60,7 +63,4 @@ This parameter controls whether to upload Sonar results as an artifact.
with:
sonar-token: ${{ secrets.SONAR_TOKEN }}
github-repo-name: ${{ github.event.repository.name }}
github-token: ${{ secrets.GITHUB_TOKEN }}
aws-access-key-id: ${{ secrets.DEV_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.DEV_AWS_SECRET_ACCESS_KEY }}
```
111 changes: 66 additions & 45 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Project Validation'
name: 'Sonar Project Validation'
description: 'Run Sonar and Tests to Validate Quality'

inputs:
Expand All @@ -17,39 +17,47 @@ inputs:
docker-compose-file-path:
description: 'Path to docker compose file to start dependencies'
required: false
default: 'docker-compose/test-dependencies-compose.yml'
github-token:
description: 'Github Token'
required: true
default: 'docker-compose/test-dependencies-compose.yml'
sonar-token:
description: 'Sonar Token'
required: true
aws-access-key-id:
description: 'AWS Access Key ID'
required: true
aws-secret-access-key:
description: 'AWS Secret Access Key'
required: true
required: true
path-to-repo-root:
description: 'Path to Repo Root'
required: false
default: ''
tests-path:
description: 'Path to tests'
required: false
default: 'test/'
dotnet-test-command-args:
description: 'dotnet test command arguments'
required: false
default: '--filter TestCategory!="Smoke"'
local-runsettings-filename:
description: 'full local.runsettings file path, use NONE when file not required'
required: false
default: 'local.runsettings'
upload-sonar-results:
description: 'Whether to upload Sonar results as an artifact'
required: false
default: true
fail-on-failure:
description: 'set to true if you wish to fail this run when the Quality Gate is red'
required: false
default: true

runs:
using: 'composite'
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Java Install
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'

- name: Dotnet Sonar Scanner Install
run: |
if dotnet tool list -g | grep -q sonarscanner; then
Expand All @@ -69,53 +77,58 @@ runs:
echo "Dotnet Coverage now installed."
fi
shell: bash

- name: Containerized Dependencies
if: ${{ inputs.use-dependencies == true && inputs.path-to-repo-root == '' }}

- name: Sonarqube Run
run: |
echo "Running docker compose"
docker-compose -f ${{inputs.docker-compose-file-path}} up -d
export PATH=$PATH:$HOME/.dotnet/tools
dotnet sonarscanner begin /k:"SynergyDataSystems_${{ inputs.github-repo-name }}" /d:sonar.scm.revision=$GITHUB_SHA /d:sonar.token=${{ inputs.sonar-token }} /d:sonar.host.url=https://sonar.dev-internal.patriotsoftware.com /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml /d:sonar.verbose=false
shell: bash

- name: Containerized Dependencies with Path
if: ${{ inputs.use-dependencies == true && inputs.path-to-repo-root != '' }}
- name: Containerized Dependencies
if: ${{ inputs.use-dependencies == 'true' && inputs.path-to-repo-root == '' }}
run: |
echo "Running docker compose"
PATH_TO_REPO_ROOT='${{ inputs.path-to-repo-root }}' docker-compose -f ${{ inputs.docker-compose-file-path }} up -d
echo "Containerized Dependencies Running docker compose"
docker-compose -f ${{ inputs.docker-compose-file-path }} up -d
shell: bash

- name: Sonarqube Run
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
- name: Containerized Dependencies with Path
if: ${{ inputs.use-dependencies == 'true' && inputs.path-to-repo-root != '' }}
run: |
export PATH=$PATH:$HOME/.dotnet/tools
dotnet sonarscanner begin /k:"SynergyDataSystems_${{ inputs.github-repo-name }}" /d:sonar.scm.revision=$GITHUB_SHA /d:sonar.token=${{ inputs.sonar-token }} /d:sonar.host.url=https://sonar.dev-internal.patriotsoftware.com /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml /d:sonar.verbose=false
echo "Containerized Dependencies Running docker compose with path"
PATH_TO_REPO_ROOT='${{ inputs.path-to-repo-root }}' docker-compose -f ${{ inputs.docker-compose-file-path }} up -d
shell: bash

- name: Project Build
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
run: dotnet build
shell: bash

- name: Run Tests and Code Coverage
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
run: |
echo "running dotnet tests and code coverage....."
echo "setting variables for dotnet tests and code coverage..."
export LOCAL_RUNSETTINGS="${{ inputs.local-runsettings-filename }}"
export TESTS_PATH="${{ inputs.tests-path }}"
export COMMAND_ARGS='${{ inputs.dotnet-test-command-args }}'
if [ $LOCAL_RUNSETTINGS != "NONE" ]; then
echo "Using local.runsettings file."
COMMAND_ARGS+=" --settings:$TESTS_PATH$LOCAL_RUNSETTINGS"
fi
DOTNET_TEST_COMMAND=$(echo dotnet test --logger '"trx;LogFileName=test-results.trx"' --verbosity minimal --configuration Release $COMMAND_ARGS)
echo "running dotnet tests and code coverage....."
echo "COMMAND: dotnet-coverage collect '$DOTNET_TEST_COMMAND' -f xml -o 'coverage.xml'"
# command execution
dotnet tool update -g dotnet-coverage
export PATH=$PATH:$HOME/.dotnet/tools
. ~/.bashrc
dotnet-coverage collect 'dotnet test --logger "trx;LogFileName=test-results.trx" --verbosity minimal --configuration Release --filter TestCategory!="Smoke" --settings:test/local.runsettings' -f xml -o 'coverage.xml'
export PATH=$PATH:$HOME/.dotnet/tools
. ~/.bashrc
eval dotnet-coverage collect '$DOTNET_TEST_COMMAND' -f xml -o 'coverage.xml'
shell: bash

- name: Sonarqube end
run: |
export PATH=$PATH:$HOME/.dotnet/tools
. ~/.bashrc
dotnet sonarscanner end /d:sonar.token="${{ inputs.sonar-token }}"
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
shell: bash

- name: Where Am I
Expand All @@ -125,27 +138,35 @@ runs:
shell: bash

- uses: actions/upload-artifact@v3
if: ${{ inputs.upload-sonar-results == true }}
if: ${{ inputs.upload-sonar-results == 'true' }}
with:
name: sonar-report
path: .sonarqube/out/.sonar/report-task.txt

- name: SonarQube Quality Gate check
uses: sonarsource/sonarqube-quality-gate-action@master
if: ${{ inputs.fail-on-failure == 'true' }}
env:
SONAR_TOKEN: ${{ inputs.sonar-token }}
with:
scanMetadataReportFile: .sonarqube/out/.sonar/report-task.txt

- name: Output Docker Container Logs
uses: jwalton/gh-docker-logs@v2
if: ${{ inputs.use-dependencies == true && always() }}
if: ${{ inputs.use-dependencies == 'true' && always() }}

- name: Test Report
uses: dorny/test-reporter@v1
if: always()
with:
name: Project Validation Test Results
path: test/**/TestResults/**/test-results.trx
path: "${{ inputs.tests-path }}**/*.trx"
reporter: dotnet-trx

- name: Stop Containerized Dependencies
if: ${{ inputs.use-dependencies == true && always() }}
if: ${{ inputs.use-dependencies == 'true' && always() }}
run: |
echo "Stopping Docker Containers"
echo "Containerized Dependencies: Stopping Docker Containers"
docker-compose -f ${{inputs.docker-compose-file-path}} down -v --remove-orphans
shell: bash

Expand Down

0 comments on commit 331e8fe

Please sign in to comment.