Skip to content

Commit

Permalink
Add ASP.NET Web App Build on Ubuntu Runner starter and solution files…
Browse files Browse the repository at this point in the history
…; update lab instructions for creating a new Web App
  • Loading branch information
prasadhonrao committed Dec 1, 2024
1 parent f53d7a7 commit fc276e1
Show file tree
Hide file tree
Showing 14 changed files with 242 additions and 108 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ASP.NET Web App Build
name: ASP.NET Web App Build Ubuntu Runner

on:
push:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: ASP.NET Web App Build Window Runner
on:
push:
paths:
- '.github/workflows/aspnet-webapp-build-windows-runner copy.yml'
- '.github/workflows/aspnet-webapp-build-windows-runner.yml'
- 'src/dotnet/WebApp/**'
workflow_dispatch:

Expand Down
33 changes: 33 additions & 0 deletions labs/aspnet-webapp/build-ubuntu-runner-solution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## ASP.NET Web App Build on Ubuntu Runner Solution

```yaml
name: ASP.NET Web App Build on Ubuntu Runner

on:
push:
paths:
- '.github/workflows/aspnet-webapp-build.yml'
- 'src/dotnet/WebApp/**'
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./src/dotnet/WebApp
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="${{runner.temp}}/webapp"
```
5 changes: 5 additions & 0 deletions labs/aspnet-webapp/build-ubuntu-runner-starter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# ASP.NET Web App Build on Ubuntu Runner Starter File

```yaml
# This file is intentionally left blank. You will create a workflow by following the instructions provided in the lab.
```
119 changes: 119 additions & 0 deletions labs/aspnet-webapp/build-ubuntu-runner.lab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# ASP.NET Web App Build with Ubuntu Runner Lab

## Introduction

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
---

## Prerequisites

Before starting this lab, ensure that you have completed the [Create ASP.NET Web App](./create-aspnet-webapp.md) lab to have your .NET Core web application ready for this lab.

---

## Instructions

Ah, I see! You're asking to use the same format from the **"YAML Syntax Starter File"** instructions for **Step 1** in the lab you mentioned earlier. Here's the updated version of **Step 1** in the format you've requested:

---

### Step 1: Create a YAML Workflow Using the Starter File

1. Refer to the [**ASP.NET Web App Build on Ubuntu Runner Starter File**](./build-ubuntu-runner-starter.md).
2. Copy the content from the starter file:

```yaml
# This file is intentionally left blank. You will create a workflow by following the instructions provided in the lab.
```

3. In your repository, create a new file under `.github/workflows` and name it `aspnet-webapp-build-on-ubuntu-runner.yml`.
4. Paste the copied content into the new `aspnet-webapp-build-on-ubuntu-runner.yml` file.
5. Commit the changes and push the workflow file to the `main` branch.

---

### Step 2: Define the Workflow Name and Event Triggers

1. 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`:

```yaml
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/`.

---

### Step 3: Add the Build Job

1. Below the `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.
2. Add the following steps to the `build` job:

```yaml
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="${{runner.temp}}/webapp"
```

---

### Step 4: Understanding the Workflow

1. The workflow contains a single job named `build` that runs on an `ubuntu-latest` runner.

2. The job has four key steps:
- **Checkout code**: This step uses the `actions/checkout` action to retrieve the latest code from the repository.
- **Set up .NET Core**: The `actions/setup-dotnet` action installs the required version of the .NET SDK (`8.x` in this case) to the runner.
- **Build code**: This step compiles the application using `dotnet build` in **Release** configuration.
- **Publish code**: This step runs `dotnet publish` to generate the application's publish-ready artifacts, storing the output in a temporary directory.

---

### Step 5: Commit and Push the Workflow File

1. Save and commit the changes to the `aspnet-webapp-build-ubuntu-runner.yml` file in your repository.
2. Push the changes to the repository.

---

### Step 6: View the Workflow Runs

1. Go to the **Actions** tab in your GitHub repository.
2. You should see the latest workflow run triggered by the push you just made.
3. Click on the latest workflow run to view the details.

---

### Step 7: Review the Logs

1. Click on the **build** job within the workflow run to expand it.
2. Review the logs for each step to ensure the build and publish process ran successfully.

---

## Summary

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.
80 changes: 80 additions & 0 deletions labs/aspnet-webapp/create-aspnet-webapp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Create ASP.NET Web App

## Introduction

In this lab, you will create a .NET Core Web application using the command line. This app will be used for future labs.

> **Duration**: 10-20 minutes
---

## Instructions

### Step 1: Open Command Prompt and Create Project Directory

1. Open a command prompt or terminal window.
2. Create a new directory for the project by running the following command:

```bash
mkdir WebApp
```

3. Navigate into the newly created directory:

```bash
cd WebApp
```

---

### Step 2: Create a New .NET Core Web Application

1. In the command prompt, create a new .NET Core Web application by running:

```bash
dotnet new webapp
```

This will generate a basic ASP.NET Core Web application.

---

### Step 3: Run the Application

1. After the application is created, run it using the following command:

```bash
dotnet run
```

2. The application will start and listen on a local port. You should see output indicating that the application is running.

---

### Step 4: Open the Application in a Browser

1. Open a web browser of your choice.
2. Navigate to the URL `https://localhost:5001` to view the application.

> **Note**: The port number may vary. If you see a different port number in the output from `dotnet run`, use that number instead.
3. You should see the default .NET Core Web application in your browser.

---

### Step 5: Stop the Application

1. Once you're done viewing the application, stop it by pressing `Ctrl+C` in the command prompt. This will terminate the application.

---

### Step 6: Commit the Source Code to the Repository

1. Open your repository where you want to save the project.
2. Commit the source code of the application. For this lab, you can save the source code in a `src/dotnet` directory.

---

## Summary

In this lab, you successfully created a .NET Core Web application using the command line. You also ran the application locally in your browser. This application will be used in future labs.
38 changes: 0 additions & 38 deletions labs/create-webapp.md

This file was deleted.

2 changes: 1 addition & 1 deletion labs/webapp-build-upload-artifacts.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ In this lab, you will learn how to build a web application using GitHub Actions.
## Prerequisites

Create a new Web App by following the instructions in the [Create a Web App](./create-webapp.md) lab.
Create a new Web App by following the instructions in the [Create a Web App](./create-aspnet-webapp.md) lab.

## Instructions

Expand Down
2 changes: 1 addition & 1 deletion labs/webapp-build-upload-download-artifacts-multiple-os.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ In this lab, you will learn how to create a GitHub Actions workflow that uploads
## Prerequisites

Create a new Web App by following the instructions in the [Create a Web App](./create-webapp.md) lab.
Create a new Web App by following the instructions in the [Create a Web App](./create-aspnet-webapp.md) lab.

## Instructions

Expand Down
2 changes: 1 addition & 1 deletion labs/webapp-build-upload-download-artifacts.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ In this lab, you will learn how to upload and download artifacts in GitHub Actio
## Prerequisites

Create a new Web App by following the instructions in the [Create a Web App](./create-webapp.md) lab.
Create a new Web App by following the instructions in the [Create a Web App](./create-aspnet-webapp.md) lab.

## Instructions

Expand Down
65 changes: 0 additions & 65 deletions labs/webapp-build.md

This file was deleted.

0 comments on commit fc276e1

Please sign in to comment.