From a4e4c98d947a52640664b906acc1bf0a13c53925 Mon Sep 17 00:00:00 2001 From: Raghav Rastogi <51928619+raghav2404@users.noreply.github.com> Date: Fri, 13 Dec 2024 04:10:30 +0530 Subject: [PATCH] Update dotnet.yml --- .github/workflows/dotnet.yml | 49 +++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 217f7cb..59ed11d 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -1,28 +1,47 @@ -# This workflow will build a .NET project -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net - -name: .NET +name: .NET MVC CI/CD Pipeline on: push: - branches: [ "main" ] + branches: + - main # Trigger on push to 'main' branch pull_request: - branches: [ "main" ] + branches: + - main # Trigger on pull request to 'main' branch jobs: - build: - + build-and-deploy: runs-on: ubuntu-latest + env: + DOTNET_VERSION: 8.0 + PUBLISH_DIR: ./publish + CONNECTION_STRING: ${{ secrets.SQL_CONNECTION_STRING }} # Add this to GitHub Secrets + steps: - - uses: actions/checkout@v4 - - name: Setup .NET - uses: actions/setup-dotnet@v4 + # Step 1: Check out code + - name: Checkout code + uses: actions/checkout@v3 + + # Step 2: Set up .NET + - name: Setup .NET Core SDK + uses: actions/setup-dotnet@v3 with: - dotnet-version: 8.0.x + dotnet-version: ${{ env.DOTNET_VERSION }} + + # Step 3: Restore dependencies - name: Restore dependencies run: dotnet restore - - name: Build - run: dotnet build --no-restore - - name: Test + + # Step 4: Build the solution + - name: Build the solution + run: dotnet build --configuration Release + + # Step 5: Run tests (optional) + - name: Run tests run: dotnet test --no-build --verbosity normal + + # Step 6: Publish the application + - name: Publish application + run: dotnet publish --configuration Release --output ${{ env.PUBLISH_DIR }} + +