From 0593e3da39e816eb0875b86a74987c1e623693be Mon Sep 17 00:00:00 2001 From: tranvuongduy2003 Date: Thu, 24 Oct 2024 15:31:59 +0700 Subject: [PATCH] set up CI/CD (build stage) with SonarCloud --- .github/workflows/develop_workflows.yml | 89 +++++++++++++++++++ .../workflows/master_eventhubapiserver.yml | 3 - 2 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/develop_workflows.yml diff --git a/.github/workflows/develop_workflows.yml b/.github/workflows/develop_workflows.yml new file mode 100644 index 0000000..3584b4b --- /dev/null +++ b/.github/workflows/develop_workflows.yml @@ -0,0 +1,89 @@ +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 + - 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" + + - 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 + - name: Build and analyze + 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 + + - 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 }} diff --git a/.github/workflows/master_eventhubapiserver.yml b/.github/workflows/master_eventhubapiserver.yml index cd34ff5..27094ba 100644 --- a/.github/workflows/master_eventhubapiserver.yml +++ b/.github/workflows/master_eventhubapiserver.yml @@ -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: