Skip to content

set up CI/CD (build stage) with SonarCloud #3

set up CI/CD (build stage) with SonarCloud

set up CI/CD (build stage) with SonarCloud #3

name: Development CI/CD Workflows
on:
push:
branches:
- develop
workflow_dispatch:
jobs:
build:
name: Build and analyze
runs-on: windows-latest
steps:
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: "zulu" # Alternative distribution options are available.
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v4
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
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
continue-on-error: false
- name: Set up SonarScanner
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"tranvuongduy2003_EventHub" /o:"tranvuongduy2003" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
continue-on-error: false
- name: Set up .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.x"
- name: Store dependencies
run: dotnet restore src/EventHub.Presentation/EventHub.Presentation.csproj
continue-on-error: false
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
dotnet build src/EventHub.Presentation/EventHub.Presentation.csproj -c Release -o ./build
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
dotnet publish src/EventHub.Presentation/EventHub.Presentation.csproj -c Release -o ./publish
continue-on-error: false
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v4
with:
name: .net-app
path: ./publish
# deploy:
# runs-on: windows-latest
# needs: build
# environment:
# name: "Production"
# url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
# steps:
# - name: Download artifact from build job
# uses: actions/download-artifact@v4
# with:
# name: .net-app
# - name: Deploy to Azure Web App
# id: deploy-to-webapp
# uses: azure/webapps-deploy@v3
# with:
# app-name: "EventHubAPIServer"
# slot-name: "Production"
# package: .
# publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_2E162A0AE3134EF8992B4DD6656A4E66 }}