CI/CD

This outline describes the Continuous Integration and Continuous Delivery (CI/CD) pipeline implemented for the project, which automates the building, testing, and deployment processes.

Workflow

The CI/CD pipeline is powered by GitHub Actions, a platform for automating workflows in a GitHub repository.

Workflow File

The core of the CI/CD process is defined within the .github/workflows/main.yml file .github/workflows/main.yml. This file outlines the various steps involved in the pipeline, including building the application, running tests, and deploying the application.

Pipeline Stages

The workflow file defines several stages, each representing a distinct phase in the CI/CD process:

  • Build: This stage is responsible for building the application from source code. The dotnet publish command is used to generate the final application output.

  • Test: The test stage executes the application’s unit tests. This ensures the application’s functionality is working as expected and that any changes made haven’t introduced regressions.

  • Deploy: The deploy stage handles the process of deploying the built application to a hosting platform. This stage utilizes Azure DevOps to deploy the application to an Azure Web App.

Triggering the Workflow

The workflow is triggered automatically on every push to the main branch of the repository. This ensures that every code change goes through the entire CI/CD pipeline, guaranteeing that the application remains in a healthy and functional state.

Building the Application

The build stage is responsible for compiling the source code and producing the final application output.

Build Process

The build process is executed using the dotnet publish command. This command takes the project’s source code and generates an output directory containing all necessary files for deploying the application.

Example

  build:
              runs-on: windows-latest
              steps:
                - uses: actions/checkout@v3
                - name: Setup .NET
                  uses: actions/setup-dotnet@v2
                  with:
                    dotnet-version: 6.0.x
                - name: Build
                  run: dotnet publish -c Release -o ${{env.BUILD_ARTIFACT_PATH}}
                - name: Upload build artifacts
                  uses: actions/upload-artifact@v3
                  with:
                    name: pac-man-blazor-app
                    path: ${{env.BUILD_ARTIFACT_PATH}}
          

The code snippet demonstrates the build stage in the workflow file. It uses the actions/setup-dotnet@v2 action to set up the .NET SDK on the runner, and then uses the dotnet publish command to build the application. The output is uploaded as a build artifact for use in subsequent stages.

Testing the Application

The test stage is responsible for running the application’s unit tests. This stage ensures that the application’s functionality is working as expected and that any changes made haven’t introduced regressions.

Test Process

The test process involves running the application’s unit tests using the dotnet test command. This command executes the tests and reports any failures.

Example

  test:
              runs-on: windows-latest
              needs: build
              steps:
                - uses: actions/checkout@v3
                - name: Setup .NET
                  uses: actions/setup-dotnet@v2
                  with:
                    dotnet-version: 6.0.x
                - name: Download build artifact
                  uses: actions/download-artifact@v3
                  with:
                    name: pac-man-blazor-app
                - name: Test
                  run: dotnet test -c Release
          

The code snippet shows the test stage. It downloads the build artifact generated in the build stage, sets up the .NET SDK, and then runs the unit tests using the dotnet test command.

Deploying the Application

The deploy stage handles the process of deploying the built application to a hosting platform. This stage utilizes Azure DevOps to deploy the application to an Azure Web App.

Deploy Process

The deploy process begins by downloading the build artifact from the previous stage. The artifact is then deployed to an Azure Web App using the Azure DevOps REST API. The Azure DevOps pipeline uses the Azure DevOps CLI to interact with the Azure DevOps API.

Example

  deploy:
              runs-on: windows-latest
              needs: test
              steps:
                - uses: actions/checkout@v3
                - name: Setup .NET
                  uses: actions/setup-dotnet@v2
                  with:
                    dotnet-version: 6.0.x
                - name: Download build artifact
                  uses: actions/download-artifact@v3
                  with:
                    name: pac-man-blazor-app
                - name: Login to Azure DevOps
                  uses: azure/login@v1
                  with:
                    creds: ${{ secrets.AZURE_CREDENTIALS }}
                - name: Deploy to Azure Web App
                  uses: azure/webapps-deploy@v2
                  with:
                    app-name: ${{ secrets.AZURE_WEBAPP_NAME }}
                    slot-name: 'Production'
                    publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
                    package: ${{env.BUILD_ARTIFACT_PATH}}
          

This code snippet illustrates the deploy stage. It downloads the build artifact, logs in to Azure DevOps using the azure/login@v1 action, and then deploys the application to the specified Azure Web App using the azure/webapps-deploy@v2 action.

Conclusion

This outline provides a comprehensive overview of the CI/CD pipeline implemented for the project, highlighting its key components and workflows. By automating the build, test, and deployment processes, this pipeline ensures that the application remains in a healthy and functional state, allowing for continuous delivery of new features and bug fixes.