Skip to content

Commit

Permalink
chore: add pr validation
Browse files Browse the repository at this point in the history
  • Loading branch information
willianantunes committed Sep 15, 2024
1 parent 735ec7e commit c67603a
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
35 changes: 35 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Validate PR

on:
pull_request:
branches:
- main
paths:
- 'src/**'
- 'tests/**'
- '*.sln'
- 'Dockerfile'

env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
PR_SOURCE_BRANCH: ${{ github.head_ref }}
PR_TARGET_BRANCH: ${{ github.base_ref }}
GITHUB_PR_NUMBER: ${{github.event.pull_request.number}}
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '8'
- name: Install dotnet-sonarscanner
run: |
dotnet tool install --global dotnet-sonarscanner
- name: Check if the project is well formatted
run: |
./scripts/start-check-formatting.sh
- name: Build the project, run all tests, and publish the test results
run: |
./scripts/start-sonarcloud.sh
33 changes: 33 additions & 0 deletions scripts/start-sonarcloud.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

set -eu -o pipefail

# You should start the scanner prior building your project and running your tests
if [ -n "${PR_SOURCE_BRANCH:-}" ]; then
dotnet sonarscanner begin \
/d:sonar.login="$SONAR_TOKEN" \
/k:"juntossomosmais_AspNetCore.RestFramework" \
/o:"juntossomosmais" \
/d:sonar.host.url="https://sonarcloud.io" \
/d:sonar.cs.opencover.reportsPaths="**/*/coverage.opencover.xml" \
/d:sonar.cs.vstest.reportsPaths="**/*/*.trx" \
/d:sonar.pullrequest.base="$PR_TARGET_BRANCH" \
/d:sonar.pullrequest.branch="$PR_SOURCE_BRANCH" \
/d:sonar.pullrequest.key="$GITHUB_PR_NUMBER"
else
dotnet sonarscanner begin \
/d:sonar.login="$SONAR_TOKEN" \
/v:"$PROJECT_VERSION" \
/k:"juntossomosmais_AspNetCore.RestFramework" \
/o:"juntossomosmais" \
/d:sonar.host.url="https://sonarcloud.io" \
/d:sonar.cs.opencover.reportsPaths="**/*/coverage.opencover.xml" \
/d:sonar.cs.vstest.reportsPaths="**/*/*.trx" \
/d:sonar.branch.name="$SOURCE_BRANCH_NAME"
fi

# Now we can run our tests as usual
./scripts/start-tests.sh

# Now we can collect the results 👍
dotnet sonarscanner end /d:sonar.login="$SONAR_TOKEN"
2 changes: 1 addition & 1 deletion scripts/start-tests.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -e

Expand Down

0 comments on commit c67603a

Please sign in to comment.