Skip to content

date

date #194

name: CI - Build and Tests
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
FIRESTORE_CREDENTIALS: ${{ secrets.FIRESTORE_CREDENTIALS }}
FIRESTORE_PROJECT_ID: audit-net
ACCEPT_EULA: 'Y'
jobs:
# Run the tests that are not compatible with Mono in a separate job on Windows
build-and-test-windows:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
2.1.x
3.1.x
6.0.x
7.0.x
8.0.x
9.0.x
10.0.x
- name: Setup NuGet
uses: NuGet/setup-nuget@v1.0.2
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true'
with:
nuget-version: '6.x'
- name: Dotnet Restore
run: dotnet restore
- name: Dotnet Build Audit.NET.sln
run: dotnet build .\Audit.NET.sln --no-restore -c release
- name: Run tests
run: |
dotnet test .\Audit.NET.sln --no-build -c release `
--filter "TestCategory=MonoIncompatible" `
--logger "console;verbosity=normal" --logger "trx;LogFilePrefix=VSTest" "-m:1" --results-directory "./test/TestResult"
# Main job to build and test the project
build-and-test-linux:
runs-on: ubuntu-22.04 #Can't use a newer version due to Mono requirements
timeout-minutes: 60
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Free Disk Space (Ubuntu)
uses: insightsengineering/disk-space-reclaimer@v1
with:
android: true
dotnet: true
haskell: false
large-packages: false
swap-storage: true
docker-images: true
tools-cache: false
- name: Check available disk space before build
run: df -h
- name: List directory
shell: bash
run: ls -R
- name: Extract version from Directory.Build.props
shell: bash
run: |
version=$(grep -oP '<Version>\K[\d\.]+(?:-[\w\-\.]+)?' Directory.Build.props)
echo "PROJECT_VERSION=$version" >> $GITHUB_ENV
echo "PROJECT_VERSION=$version"
# Google Cloud (Firestore)
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ env.FIRESTORE_CREDENTIALS }}
- name: Install .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
2.1.x
3.1.x
6.0.x
7.0.x
8.0.x
9.0.x
10.0.x
- name: Show docker versions
run: |
docker --version
docker compose version
- name: Docker pull
run: docker compose -f ./Docker/docker-compose.yml pull
- name: Docker compose
run: |
docker compose -f ./Docker/docker-compose.yml up -d --remove-orphans
- name: Install librdkafka-dev
run: sudo apt-get install -y librdkafka-dev
- name: Sleep for 60 seconds
run: sleep 60s
shell: bash
- name: Wait for services
run: |
set -e
wait_for_port() {
host=$1
port=$2
name=$3
retries=60
echo "Waiting for $host:$port ..."
for i in $(seq 1 $retries); do
if timeout 1 bash -c "cat < /dev/null > /dev/tcp/$host/$port" 2>/dev/null; then
echo "$host:$port $name is available"
return 0
fi
sleep 1
done
echo "Timeout waiting for $host:$port $name" >&2
return 1
}
# List of host:port pairs to check. Adjust or expand as needed.
wait_for_port localhost 3322 immudb
wait_for_port localhost 8000 dynamodb
wait_for_port localhost 5432 postgresql
wait_for_port localhost 3306 mysql
wait_for_port localhost 6379 redis
wait_for_port localhost 9200 elasticsearch
wait_for_port localhost 9250 opensearch
wait_for_port localhost 27017 mongodb
wait_for_port localhost 8080 ravendb
wait_for_port localhost 5672 eventhubs
wait_for_port localhost 8082 cosmosdb
wait_for_port localhost 10000 azurite
wait_for_port localhost 1433 sqlserver
wait_for_port localhost 9094 kafka
- name: Setup NuGet
uses: NuGet/setup-nuget@v1.0.2
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true'
with:
nuget-version: '6.x'
- name: Install dotnet Tools
run: |
dotnet new tool-manifest
dotnet tool install dotnet-reportgenerator-globaltool
dotnet tool install --global dotnet-sonarscanner --version 10.1.2
- name: Elasticsearch - Create Indexes and configure
run: |
curl -X PUT http://localhost:9200/auditevent_test -H \
'Content-Type: application/json' -d\
'{ "settings": { "index": { "number_of_shards": 1, "number_of_replicas": 0 } } }'
curl -X PUT http://localhost:9200/auditevent_test2 -H \
'Content-Type: application/json' -d\
'{ "settings": { "index": { "number_of_shards": 1, "number_of_replicas": 0 } } }'
curl -X PUT http://localhost:9200/_cluster/settings -H \
'Content-Type: application/json' -d\
'{ "persistent": { "cluster.routing.allocation.disk.threshold_enabled": false } }'
- name: SonarScanner Begin
shell: bash
run: |
dotnet sonarscanner begin \
/o:"thepirat000" \
/k:"Audit.NET" \
/d:sonar.host.url="https://sonarcloud.io" \
/d:sonar.login="${{ env.SONAR_TOKEN }}" \
/d:sonar.cs.vstest.reportsPaths="test/TestResult/**/*.trx" \
/d:sonar.cs.opencover.reportsPaths="test/TestResult/**/*.opencover.xml" \
/d:sonar.exclusions="**/templates/**,**/docs/**,**/documents/**,**/tools/**,**/packages/**,**/Tests/**" \
/d:sonar.coverage.exclusions="**/templates/**,**/Tests/**,**/Audit.WCF/**,**/Audit.WCF.Client/**" \
/v:"${{ env.PROJECT_VERSION }}"
- name: Dotnet Restore
run: dotnet restore ./Audit.NET.sln
- name: Dotnet Build Audit.NET.sln
run: dotnet build ./Audit.NET.sln --no-restore -c release
- name: Check available disk space
run: df -h
- name: Run tests
run: |
dotnet test ./Audit.NET.sln --no-build -c release --logger "console;verbosity=normal" --logger "trx;LogFilePrefix=VSTest" "-m:1" --results-directory "./test/TestResult" \
--filter "TestCategory!=MonoIncompatible"
- name: SonarScanner End
shell: bash
run: |
dotnet sonarscanner end \
/d:sonar.login="${{ env.SONAR_TOKEN }}"
- name: List directory
shell: bash
run: ls -R
- name: Generate Code Coverage Report
run: |
dotnet reportgenerator -reports:${{ github.workspace }}/test/TestResult/**/*.cobertura.xml -targetdir:"${{ github.workspace }}/Tests/coveragereport" -reporttypes:"MarkdownSummary;Html" "-assemblyfilters:+Audit.*;-*UnitTest;-Audit.WCF"
- name: Upload Code Coverage Report artifact
uses: actions/upload-artifact@v4
with:
name: coveragereport
path: ${{ github.workspace }}/Tests/coveragereport
- name: Rename summary coverage file
continue-on-error: true
run: mv -f "${{ github.workspace }}/Tests/coveragereport/Summary.md" "${{ github.workspace }}/CODE_COVERAGE.md"
- name: Commit CODE_COVERAGE.md
continue-on-error: true
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Commit CODE_COVERAGE.md
file_pattern: 'CODE_COVERAGE.md'
- name: Tear down containers
if: always()
run: docker compose -f ./Docker/docker-compose.yml down -v --remove-orphans
- name: Clean up Docker images and containers
if: always()
run: |
docker system prune -af
docker builder prune -af