Skip to content

Commit

Permalink
set up CI/CD (build stage) with SonarCloud
Browse files Browse the repository at this point in the history
  • Loading branch information
tranvuongduy2003 committed Oct 24, 2024
1 parent a8be447 commit 220abb1
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 3 deletions.
101 changes: 101 additions & 0 deletions .github/workflows/develop_workflows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
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 }}
3 changes: 0 additions & 3 deletions .github/workflows/master_eventhubapiserver.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Build and deploy ASP.Net Core app to Azure Web App - EventHubAPIServer

on:
Expand Down

0 comments on commit 220abb1

Please sign in to comment.