Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: atualizando os dois pipelines, report test e ghcr #28

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 57 additions & 28 deletions .github/workflows/pull-request-sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,89 @@ on:
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:

defaults:
run:
working-directory: src


# defaults:
# run:
# working-directory: src

env:
imageName: cachorro.api
dotnetVersion: 7.x
csprojFolder: ./src/DEPLOY.Cachorro.Api/DEPLOY.Cachorro.Api.csproj

jobs:
build:
name: Analyze by SonarCloud
runs-on: windows-latest
build-and-sonar:
runs-on: ubuntu-latest
steps:
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'zulu' # Alternative distribution options are available.
- uses: actions/checkout@v3
distribution: 'zulu'

- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.dotnetVersion }}

- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v3
with:
path: .\.sonar\scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner

- name: Install SonarCloud scanner
#if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
shell: powershell
if: ${{ steps.cache-sonar-scanner.outputs.cache-hit != 'true' }}
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
mkdir -p .sonar/scanner
dotnet tool update dotnet-sonarscanner --tool-path .sonar/scanner

- name: Install dotnet-coverage
shell: powershell
- name: Install SonarCloud scanner
run: |
dotnet tool install --global dotnet-sonarscanner
dotnet tool install --global dotnet-coverage

dotnet tool install --global dotnet-reportgenerator-globaltool

- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"felipementel_DEPLOY.Cachorro.Api" /o:"felipementel" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml /d:sonar.exclusions="**/Migrations/**"
dotnet run --project DEPLOY.Cachorro.Api/DEPLOY.Cachorro.Api.csproj --no-incremental
dotnet-coverage collect "dotnet test" -f xml -o "coverage.xml"
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
dotnet-sonarscanner begin /k:"felipementel_DEPLOY.Cachorro.Api" /o:"felipementel" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml /d:sonar.exclusions="**/Migrations/**"
dotnet restore ${{ env.csprojFolder }}
dotnet build ${{ env.csprojFolder }} --no-incremental
dotnet-coverage collect 'dotnet test ./src/' -f xml -o 'coverage.xml'
dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"

- name: ReportGenerator
uses: danielpalme/[email protected]
with:
reports: 'coverage.xml'
targetdir: 'coveragereport'
reporttypes: 'HtmlInline;Cobertura'
assemblyfilters: '+*'
classfilters: '+*'
filefilters: '+*'
verbosity: 'Verbose'
title: 'Canal DEPLOY API Cachorro'
tag: '${{ github.run_number }}_${{ github.run_id }}'
toolpath: 'reportgeneratortool'

- name: Upload coverage report artifact
uses: actions/[email protected]
with:
name: CoverageReport
path: coveragereport
51 changes: 49 additions & 2 deletions .github/workflows/push-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Docker Hub
on:
push:
paths:
- "src/**"
- 'src/**'
branches:
- main
workflow_dispatch:
Expand All @@ -21,7 +21,7 @@ jobs:
uses: actions/setup-java@v3
with:
java-version: 17
distribution: "zulu"
distribution: 'zulu'

- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -70,6 +70,26 @@ jobs:
dotnet-coverage collect 'dotnet test ./src/' -f xml -o 'coverage.xml'
dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"

- name: ReportGenerator
uses: danielpalme/[email protected]
with:
reports: 'coverage.xml'
targetdir: 'coveragereport'
reporttypes: 'HtmlInline;Cobertura'
assemblyfilters: '+*'
classfilters: '+*'
filefilters: '+*'
verbosity: 'Verbose'
title: 'Canal DEPLOY API Cachorro'
tag: '${{ github.run_number }}_${{ github.run_id }}'
toolpath: 'reportgeneratortool'

- name: Upload coverage report artifact
uses: actions/[email protected]
with:
name: CoverageReport
path: coveragereport

docker:
name: Push image to Registry
needs: build-and-sonar
Expand Down Expand Up @@ -100,13 +120,28 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GH_TOKEN }}

- name: Get-Version from csproj
id: get-version
shell: bash
run: |
version=$(sed -n 's/.*<Version>\(.*\)<\/Version>.*/\1/p' ./src/DEPLOY.Cachorro.Api/DEPLOY.Cachorro.Api.csproj)
echo "tag=$version" >> "$GITHUB_OUTPUT"

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: |
felipementel/$imageName
ghcr.io/felipementel/deploy.$imageName

- name: Build and push docker
uses: docker/build-push-action@v5
with:
Expand All @@ -116,3 +151,15 @@ jobs:
tags: |
felipementel/${{ env.imageName }}:latest
felipementel/${{ env.imageName }}:${{ steps.get-version.outputs.tag }}

- name: Build and push ghci
uses: docker/build-push-action@v5
with:
context: ./src/
file: ./src/DEPLOY.Cachorro.Api/Dockerfile
push: true
tags: |
ghcr.io/felipementel/deploy.${{ env.imageName }}:latest
ghcr.io/felipementel/deploy.${{ env.imageName }}:${{ steps.get-version.outputs.tag }}
labels: |
${{ steps.meta.outputs.labels }}
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,25 @@ dotnet test
1.1 A partir da pasta src execute o comando:

```
dotnet test --collect:"XPlat Code Coverage" --logger "console;verbosity=detailed" --results-directory .\DEPLOY.Cachorro.Api.Tests\TestResults\XPlatCodeCoverage\
dotnet test --collect:"XPlat Code Coverage" --logger "console;verbosity=detailed" --results-directory ..\TestResults\XPlatCodeCoverage\
```

e depois execute:

```
reportgenerator -reports:.\DEPLOY.Cachorro.Api.Tests\TestResults\XPlatCodeCoverage\**\coverage.cobertura.xml -targetdir:./DEPLOY.Cachorro.Api.Tests/TestResults/XPlatCodeCoverage/CoverageReport -reporttypes:"Html;SonarQube;JsonSummary;Badges" -verbosity:Verbose -title:Cachorro.API -tag:canal-deploy
reportgenerator -reports:..\TestResults\XPlatCodeCoverage\**\coverage.cobertura.xml -targetdir:..\TestResults\XPlatCodeCoverage\CoverageReport -reporttypes:"Html;SonarQube;JsonSummary;Badges" -classfilters:"-*.Migrations.*" -verbosity:Verbose -title:Cachorro.API -tag:canal-deploy
```

ou

```
$var = (Get-Date).ToString("yyyyMMdd-HHmmss"); dotnet-coverage collect "dotnet test" -f xml -o ".\DEPLOY.Cachorro.Api.Tests\TestResults\DotnetCoverageCollect\$var\coverage.cobertura.xml"
$var = (Get-Date).ToString("yyyyMMdd-HHmmss"); dotnet-coverage collect "dotnet test" -f xml -o "..\TestResults\DotnetCoverageCollect\$var\coverage.cobertura.xml"
```

e depois execute:

```
reportgenerator -reports:.\DEPLOY.Cachorro.Api.Tests\TestResults\DotnetCoverageCollect\**\coverage.cobertura.xml -targetdir:./DEPLOY.Cachorro.Api.Tests/TestResults/DotnetCoverageCollect/CoverageReport -reporttypes:"Html;SonarQube;JsonSummary;Badges" -verbosity:Verbose -title:Cachorro.API -tag:canal-deploy
reportgenerator -reports:..\TestResults\DotnetCoverageCollect\**\coverage.cobertura.xml -targetdir:..\TestResults\DotnetCoverageCollect\CoverageReport -reporttypes:"Html;SonarQube;JsonSummary;Badges" -verbosity:Verbose -title:Cachorro.API -tag:canal-deploy
```

1.2 A partir da pasta src execute o comando:
Expand Down Expand Up @@ -182,12 +182,22 @@ https://learn.microsoft.com/en-us/dotnet/core/compatibility/containers/8.0/app-u
https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-7.0&tabs=windows

```

### Github

```
https://docs.github.com/en/actions

```

```
https://github.com/danielpalme/ReportGenerator
```

```
https://github.com/marketplace/actions/reportgenerator
```

```
https://github.com/marketplace/actions/reportgenerator
```
Expand Down
Loading