What is GitHub?

Here, we discuss the key GitHub features you use on a daily basis to manage and contribute to software projects.

The GitHub Flow

In addition to providing a platform for collaborative software development, GitHub also offers a prescribed workflow designed to optimize use of its various features. While this unit offers a cursory overview of important platform components, it is recommended that you first review Understanding the GitHub flow .

Issues

Issues are where most of the communication between a project’s consumers and development team occurs. An issue can be created to discuss a broad set of topics, including bug reports, feature requests, documentation clarifications, and more. Once an issue has been created, it can be assigned to owners, labels, projects, and milestones. You can also associate issues with pull requests and other GitHub items to provide future traceability.

A GitHub issuegithub issues

To learn more about GitHub Issues, see Mastering Issues .

Notifications

As a collaborative platform, GitHub offers notifications for virtually every event that takes place within a given workflow. These notifications can be finely tuned to meet your preferences. For example, you can subscribe to all issue creations and edits on a project, or you can just receive notifications for issues in which you are mentioned. You can also decide whether you receive notifications via email, web & mobile, or both. To keep track of all of your notifications across different projects, use the GitHub Notifications dashboard .

GitHub Notifications dashboard

github-notifications

To learn more about GitHub notifications, see Configuring notifications .

Branches

Branches are the preferred way to create changes in the GitHub flow . They provide isolation so that multiple people may simultaneously work on the same code in a controlled way. This model enables stability among critical branches, such as master, while allowing complete freedom for developers to commit any changes they need to meet their goals. Once the code from a branch is ready to become part of the master branch, it may be merged via pull request.

GitHub flow with a feature branch

To learn more about GitHub branches, see About branches .

more about best web hosting reddit

Commits

A commit is a change to one or more files on a branch. Every time a commit is created, it is assigned a unique ID and tracked, along with the time and contributor. This provides a clear audit trail for anyone reviewing the history of a file or linked item, such as an issue or pull request.

GitHub commits to a master branch

To learn more about GitHub commits, see Committing and reviewing changes to your project .

Pull Requests

A pull request is the mechanism used to signal that the commits from one branch are ready to be merged into another branch. During creation, the developer will often request one or more reviewers who are in a position to verify the code and approve the merge. These reviewers have the opportunity to comment on changes, add their own, or use the pull request itself for further discussion. Once the changes have been approved (if approval is required in the project), then the pull request’s source branch (the compare branch) may be merged in to the base branch.

GitHub pull request

To learn more about GitHub pull requests, see About pull requests .

GitHub Pages

GitHub Pages is a hosting engine that’s built right into your GitHub account. By following a few conventions, and enabling the feature, you can build your own static site generated from HTML and markdown code pulled directly from your repository.

 

Azure Cloud Perform code coverage testing

Much like the tool you use for unit testing, the tool you use for code coverage depends on the programming language and application framework you use.

When you target .NET Core applications to run on Linux, coverlet is a popular option. Coverlet is a cross-platform, code-coverage library for .NET Core. Before we add code coverage to the pipeline, let’s check in with the team.

How is code coverage done in .NET Core?

The way you collect code coverage depends on what programming language and frameworks you’re using, as well as what code coverage tools are available.

Mara and Andy do some investigation around code coverage for .NET Core applications. Here’s what they find:

  • Visual Studio on Windows provides a way to perform code coverage.
  • However, because the team is building on Linux, they can use coverlet , a cross-platform code coverage library for .NET Core.The unit test project requires the coverlet.msbuild NuGet package.
  • Code coverage results are written to an XML file so that they can be processed by another tool. Azure Pipelines supports Cobertura and JaCoCo coverage result formats.Mara and Andy decide to try Cobertura.
  • To convert Cobertura coverage results to a format that’s human-readable, they can use a tool called ReportGenerator .
  • ReportGenerator provides a number of formats, including HTML. The HTML formats create detailed reports for each class in a .NET project.Specifically, there’s an HTML format called HtmlInline_AzurePipelines, which provides a visual appearance that matches Azure Pipelines.

How can I manage .NET Core tools?

A .NET Core tool such as ReportGenerator is a special NuGet package that contains a console application. You can manage a .NET Core tool as a global tool or as a local tool.

A global tool is installed in a centralized location and can be called from any directory. One version of a global tool is used for all directories on the machine.

A local tool is a more isolated copy of a .NET Core tool that’s scoped to a specific directory. Scope enables different directories to contain different versions of the same tool.

You use a manifest file to manage local tools for a given directory. This file is in JSON format and is typically named dotnet-tools.json. A manifest file enables you to describe the specific tool versions that you need to build or run your application.

When you include the manifest file in source control along with your application sources, developers and build systems can run the dotnet tool restore command to install all of the tools listed in the manifest file. When you need a newer version of a local tool, you simply update the version in the manifest file.

To keep things more isolated, in this module you work with local tools. You create a tool manifest that includes the ReportGenerator tool. You also modify your build pipeline to install the ReportGenerator tool to convert code coverage results to a human-readable format.

Run code coverage locally

Before Mara and Andy write any pipeline code, they decide to try things manually to verify the process. Follow along with their process:

  1. In Visual Studio Code, open the integrated terminal.
  2. Run the following dotnet new command to create a local tool manifest file.

 

dotnet new tool-manifest

The command creates a file named .config/dotnet-tools.json.

3. Run the following dotnet tool install command to install ReportGenerator:

dotnet tool install dotnet-reportgenerator-globaltool

This command installs the latest version of ReportGenerator and adds an entry to the tool manifest file.

Run the following dotnet add package command to add the coverlet.msbuild package to the Tailspin.SpaceGame.Web.Tests project:

dotnet add Tailspin.SpaceGame.Web.Tests package coverlet.msbuild
  • 5. Run the following dotnet test command to run your unit tests and collect code coverage:
dotnet test --no-build \
  --configuration Release \
  /p:CollectCoverage=true \
  /p:CoverletOutputFormat=cobertura \
  /p:CoverletOutput=./TestResults/Coverage/

If the command fails, try running it like this:

 

  • MSYS2_ARG_CONV_EXCL="*" dotnet test --no-build \
      --configuration Release \
      /p:CollectCoverage=true \
      /p:CoverletOutputFormat=cobertura \
      /p:CoverletOutput=./TestResults/Coverage/
    

    This command resembles the one you ran previously. The /p: flags tell coverlet which code coverage format to use and where to place the results.

6. Run the following dotnet tool run command to use ReportGenerator to convert the Cobertura file to HTML:

 

dotnet tool run reportgenerator \
  -reports:./Tailspin.SpaceGame.Web.Tests/TestResults/Coverage/coverage.cobertura.xml \
  -targetdir:./CodeCoverage \
  -reporttypes:HtmlInline_AzurePipelines

A number of HTML files appear in the CodeCoverage folder at the root of the project.

  • In Visual Studio Code, expand the CodeCoverage folder, right-click index.htm, and then select Reveal in Explorer (Reveal in Finder on macOS or Open Containing Folder on Linux).
  • In Windows Explorer (Finder on macOS), double-click index.htm to open it in a web browser.You see the coverage report summary.azure-cloud-coverage-report-summary
  • Scroll to the bottom of the page to see a coverage breakdown by class type.
  • Select the link to TailSpin.SpaceGame.Web.LocalDocumentDBRepository`1 to view further details.Notice that the GetItemsAsync method is covered by unit tests, but the CountItemsAsync method has no coverage.azure-cloud-classThis makes sense, because the FetchOnlyRequestedGameRegion test method calls the GetItemsAsync method but does not call the CountItemsAsync method. (To review the test code, see the DocumentDBRepository_GetItemsAsyncShould.cs file.)

Create a branch

Now that you can build a code coverage report locally, you’re ready to add tasks to your build best cheap web hosting pipeline, which performs the same tasks.

In this part, you create a branch named code-coverage, based on the unit-tests branch, to hold your work. In practice, you would ordinarily create this branch from the master branch.

  1. In Visual Studio Code, open the integrated terminal.
  2. In the terminal, run the following git checkout command to create a branch named code-coverage:
git checkout -b code-coverage

Commit your changes and push the branch to GitHub

Here you push your changes to GitHub and see the pipeline run. Recall that you’re currently in the code-coverage branch.

Although not required, here you add and commit each file separately so that each change is associated with a descriptive commit message.

  1. In Visual Studio Code, go to the terminal.
  2. Add and commit the Tailspin.SpaceGame.Web.Tests.csproj file, which now contains a reference to the coverlet.msbuild package:
    Bash

 

  • git add Tailspin.SpaceGame.Web.Tests/Tailspin.SpaceGame.Web.Tests.csproj
    git commit -m "Add coverlet.msbuild package"
    
  • Add and commit the tool manifest file, dotnet-tools.json:
  • git add .config/dotnet-tools.json
    git commit -m "Add code coverage"
    
  • Add and commit azure-pipelines.yml, which contains your updated build configuration:
  • git add azure-pipelines.yml
    git commit -m "Add code coverage"
    
  • Push the code-coverage branch to GitHub.

 

  1. git push origin code-coverage
    

Watch Azure Pipelines run the tests

Here you see the tests run in the pipeline and then visualize the results from Azure Test Plans.

  1. In Azure Pipelines, trace the build through each of the steps.
  2. When the build finishes, navigate back to the summary page and select the Code Coverage tab.You view the same results that you did when you ran the tests locally.

azure-cloud-report-pipeline

As an optional step, you can explore the results from Azure Pipelines.

Add the dashboard widget

In the previous part, you added the Test Results Trend widget to your dashboard, which lets others quickly review test result trends over time.

Here you add a second widget that summarizes code coverage.

  1. In a new browser tab, go to marketplace.visualstudio.com .
  2. On the Azure DevOps tab, search for code coverage.
  3. Select Code Coverage Widgets (published by Shane Davis).
  4. Select Get it free.
  5. In the drop-down list, select your Azure DevOps organization.
  6. Select Install.
  7. Go back to Azure DevOps.
  8. Go to Overview > Dashboards.
  9. Select Edit.
  10. Search for Code Coverage, and then select Code Coverage.
  11. Drag Code Coverage to the canvas.
  12. Select the gear icon to configure the widget.
  13. Keep all the default settings, except for:
    • Width: Enter 2.
    • Build definition: Select your pipeline.
    • Coverage measurement: Enter Lines.
  14. Select Save.
  15. Select Done Editing.

The widget shows the percentage of code your unit tests cover.

cloud-dashboard-widget

You now have code coverage set up in your pipeline. Although your existing code coverage is low, you have a baseline that you can improve over time.

Later, you can configure coverlet to check to see whether your tests provide a minimum threshold of coverage. Your threshold might be 30 percent, 50 percent, or 80 percent coverage, depending on your requirements. The build will fail if less than this amount is covered by your tests.

Remove code coverage files

Recall that when you ran Reportgenerator earlier, a number of HTML files appeared in the CodeCoverage folder at the root of the project.

These HTML files are not intended to be included in source control, and you no longer need them. Although the project’s .gitignore file is already set up to ignore anything in the CodeCoverage directory, it’s a good idea to delete these files so that they’re not added to your Git repository in future modules.

Azure DevOp Pipelines- Add a testing widget to your Dashboard

Andy and Mara are excited to show Amita the progress they’ve made. They’ve already set up a dashboard. Now they can monitor pull requests and visualize the health of their builds.

In this unit, you add a widget to your dashboard to help visualize your test runs over time.

Amita takes a look and is excited.

Amita: This is great progress. Thank you! Not to sound ungrateful, but is there any way I can see just a brief overview of the test results over time?

Mara: Yes! Microsoft Azure DevOps lets you add widgets to your dashboards. It only takes a few minutes. Let me show you.

 

Add the widget to the dashboard

  1. In your Azure DevOps project, select Overview, and then select Dashboards.
    Note If you ran the template to create the Azure DevOps project, you won't see the dashboard widgets you set up in previous modules.
  2. Select Edit.
  3. In the Add Widget pane, search for Test Results Trend.
  4. Drag Test Results Trend to the canvas.
  5. Select the gear icon to configure the widget.a. Under Build pipeline, select your pipeline.b. Keep the other default settings.
  6. Select Save.
  7. Select Done Editing.

Although the website builders widget displays only one test run, you now have a way to visualize and track test runs over time. Here’s an example that shows a few successful test runs.

Azure DevOp widget

If you begin to see test failures, you can click a point on the graph to navigate directly to that build.