Master GitHub Actions with hands-on labs and exercises. Learn how to automate workflows, run tests, deploy applications, and more using GitHub's powerful automation platform. This repository has everything you need to get started with continuous integration and continuous deployment.
In this lab, you will learn how to build a web application using GitHub Actions. You will create a workflow that builds the application on an Ubuntu runner. Additionally, you’ll use the actions/setup-dotnet
action to set up the .NET Core SDK for building and publishing the web app.
Duration: 15-20 minutes
Before starting this lab, ensure that you have completed the Create ASP.NET Web App lab to have your .NET Core web application ready for this lab.
Copy the content from the starter file:
# This file is intentionally left blank. You will create a workflow by following the instructions provided in the lab.
.github/workflows
and name it aspnet-webapp-build-on-ubuntu-runner.yml
.aspnet-webapp-build-on-ubuntu-runner.yml
file.main
branch.In the aspnet-webapp-build-on-ubuntu-runner.yml
file, define the name of the workflow and the events that will trigger it. Use the following code to trigger the workflow on a push to specific files or manually using workflow_dispatch
:
name: ASP.NET Web App Build on Ubuntu Runner
on:
push:
paths:
- '.github/workflows/aspnet-webapp-build-ubuntu-runner.yml'
- 'src/dotnet/WebApp/**'
workflow_dispatch:
This ensures that the workflow will run when changes are made to the aspnet-webapp-build-ubuntu-runner.yml
file or to the application code under src/dotnet/WebApp/
.
on
section, define the job that will run the build process. This job will run on an ubuntu-latest
runner and will include the necessary steps for building and publishing the application.Add the following steps to the build
job:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4.1.7
- name: Set up .NET Core
uses: actions/setup-dotnet@v4.0.1
with:
dotnet-version: '8.x'
- name: Build code
run: dotnet build --configuration Release
- name: Publish code
run: dotnet publish -c Release --property:PublishDir="$/webapp"
The workflow contains a single job named build
that runs on an ubuntu-latest
runner.
The job has four key steps:
actions/checkout
action to retrieve the latest code from the repository.actions/setup-dotnet
action installs the required version of the .NET SDK (8.x
in this case) to the runner.dotnet build
in Release configuration.dotnet publish
to generate the application’s publish-ready artifact, storing the output in a temporary directory.aspnet-webapp-build-ubuntu-runner.yml
file in your repository.In this lab, you created a GitHub Actions workflow to build an ASP.NET Core Web application using an Ubuntu runner. You used the actions/setup-dotnet
action to install the necessary .NET Core SDK, then built and published the application. Additionally, you learned how the workflow is structured, how it is triggered, and how to monitor the workflow runs in GitHub Actions.