Skip to content

Commit 443924f

Browse files
authored
Merge pull request #58 from stesee/AspNetHelloWorld
Asp net hello world
2 parents b186007 + f70c0d9 commit 443924f

File tree

18 files changed

+396
-104
lines changed

18 files changed

+396
-104
lines changed

.github/workflows/codeql.yml

Lines changed: 0 additions & 72 deletions
This file was deleted.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: .NET Build and Deploy
2+
3+
on:
4+
push:
5+
branches: [ "AspNetHelloWorld", "main" ]
6+
7+
jobs:
8+
build-and-test:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Setup .NET
15+
uses: actions/setup-dotnet@v4
16+
with:
17+
dotnet-version: 8.0.x
18+
19+
- name: Restore dependencies
20+
run: dotnet restore
21+
22+
- name: Build
23+
run: dotnet build --no-restore --configuration Release
24+
25+
- name: Test
26+
run: dotnet test --no-build --verbosity normal --configuration Release
27+
28+
deploy-webdeploy:
29+
runs-on: windows-latest # WebDeploy typically works better on Windows runners
30+
needs: build-and-test
31+
if: github.ref == 'refs/heads/AspNetHelloWorld' || github.ref == 'refs/heads/main'
32+
33+
steps:
34+
- uses: actions/checkout@v4
35+
36+
- name: Setup .NET
37+
uses: actions/setup-dotnet@v4
38+
with:
39+
dotnet-version: 8.0.x
40+
41+
- name: Restore dependencies
42+
run: dotnet restore
43+
44+
- name: Build Web App
45+
run: dotnet build --no-restore --configuration Release GithubActionsHelloWordWeb/GithubActionsHelloWordWeb.csproj
46+
47+
- name: Publish Web App
48+
run: dotnet publish GithubActionsHelloWordWeb/GithubActionsHelloWordWeb.csproj --configuration Release --output ./publish --no-build
49+
# To do the same on your dev machine, run:
50+
# dotnet publish GithubActionsHelloWordWeb/GithubActionsHelloWordWeb.csproj --configuration Release --output ./publish
51+
52+
- name: Deploy via WebDeploy
53+
run: |
54+
# If you have a publish profile file, create it from secret
55+
mkdir -p GithubActionsHelloWordWeb/Properties/PublishProfiles
56+
echo '${{ secrets.WEBDEPLOY_PUBLISH_PROFILE }}' > GithubActionsHelloWordWeb/Properties/PublishProfiles/WebDeploy.pubxml
57+
dotnet publish GithubActionsHelloWordWeb/GithubActionsHelloWordWeb.csproj /p:PublishProfile=WebDeploy --configuration Release
58+
# To deploy from your dev machine with publish profile:
59+
# Place the .pubxml file in Properties/PublishProfiles/ folder
60+
# dotnet publish GithubActionsHelloWordWeb/GithubActionsHelloWordWeb.csproj /p:PublishProfile=WebDeploy --configuration Release

.github/workflows/greetings.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
**/.dockerignore
2+
**/.env
3+
**/.git
4+
**/.gitignore
5+
**/.project
6+
**/.settings
7+
**/.toolstarget
8+
**/.vs
9+
**/.vscode
10+
**/.idea
11+
**/*.*proj.user
12+
**/*.dbmdl
13+
**/*.jfm
14+
**/azds.yaml
15+
**/bin
16+
**/charts
17+
**/docker-compose*
18+
**/Dockerfile*
19+
**/node_modules
20+
**/npm-debug.log
21+
**/obj
22+
**/secrets.dev.yaml
23+
**/values.dev.yaml
24+
LICENSE
25+
README.md
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
2+
WORKDIR /app
3+
EXPOSE 8080
4+
EXPOSE 8081
5+
6+
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
7+
ARG BUILD_CONFIGURATION=Release
8+
WORKDIR /src
9+
COPY ["GithubActionsHelloWordWeb/GithubActionsHelloWordWeb.csproj", "GithubActionsHelloWordWeb/"]
10+
RUN dotnet restore "GithubActionsHelloWordWeb/GithubActionsHelloWordWeb.csproj"
11+
COPY . .
12+
WORKDIR "/src/GithubActionsHelloWordWeb"
13+
RUN dotnet build "GithubActionsHelloWordWeb.csproj" -c $BUILD_CONFIGURATION -o /app/build
14+
15+
FROM build AS publish
16+
ARG BUILD_CONFIGURATION=Release
17+
RUN dotnet publish "GithubActionsHelloWordWeb.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
18+
19+
FROM base AS final
20+
WORKDIR /app
21+
COPY --from=publish /app/publish .
22+
ENTRYPOINT ["dotnet", "GithubActionsHelloWordWeb.dll"]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0" />
11+
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.6" />
12+
</ItemGroup>
13+
14+
</Project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Microsoft.AspNetCore.Http.HttpResults;
2+
using Microsoft.AspNetCore.OpenApi;
3+
4+
var builder = WebApplication.CreateBuilder(args);
5+
6+
// Add services to the container.
7+
builder.Services.AddEndpointsApiExplorer();
8+
builder.Services.AddSwaggerGen(); // This requires Swashbuckle.AspNetCore NuGet package
9+
10+
var app = builder.Build();
11+
12+
// Configure the HTTP request pipeline.
13+
if (app.Environment.IsDevelopment())
14+
{
15+
app.UseSwagger();
16+
app.UseSwaggerUI();
17+
}
18+
19+
app.UseHttpsRedirection();
20+
21+
app.MapGet("/", () => "Hello World from ASP.NET Core!")
22+
.WithName("GetHello")
23+
.WithOpenApi();
24+
25+
app.MapGet("/api/hello", () => new { Message = "Hello from API!", Timestamp = DateTime.UtcNow })
26+
.WithName("GetHelloApi")
27+
.WithOpenApi();
28+
29+
app.Run();
30+
31+
// Make the Program class public for testing
32+
public partial class Program
33+
{ }
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"profiles": {
3+
"GithubActionsHelloWordWeb": {
4+
"commandName": "Project",
5+
"launchBrowser": true,
6+
"environmentVariables": {
7+
"ASPNETCORE_ENVIRONMENT": "Development"
8+
},
9+
"applicationUrl": "https://localhost:56240;http://localhost:56241"
10+
}
11+
}
12+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# GithubActionsHelloWordWeb
2+
3+
ASP.NET Core minimal API web application that demonstrates:
4+
5+
- Simple "Hello World" endpoint at `/`
6+
- JSON API endpoint at `/api/hello` that returns a message and timestamp
7+
- Swagger/OpenAPI documentation available in development mode
8+
- Full test coverage with integration tests
9+
10+
## Running the Application
11+
12+
```bash
13+
cd GithubActionsHelloWordWeb
14+
dotnet run
15+
```
16+
17+
The application will start on `https://localhost:5001` (or check console output for the exact URL).
18+
19+
## Available Endpoints
20+
21+
- `GET /` - Returns a simple "Hello World from ASP.NET Core!" message
22+
- `GET /api/hello` - Returns a JSON object with a message and current timestamp
23+
- `GET /swagger` - Swagger UI (development mode only)
24+
25+
## Running Tests
26+
27+
```bash
28+
cd GithubActionsHelloWordWebTests
29+
dotnet test
30+
```
31+
32+
## Deployment
33+
34+
This project includes GitHub Actions workflow for automatic deployment using WebDeploy to Azure.
35+
36+
### Setup Required:
37+
38+
1. Create an Azure Web App
39+
2. Download the publish profile from Azure Portal
40+
3. Add the publish profile content as a secret named `AZURE_WEBAPP_PUBLISH_PROFILE` in your GitHub repository
41+
4. Update the `app-name` in the GitHub Actions workflow file (`.github/workflows/dotnet-web-deploy.yml`)
42+
43+
The deployment will automatically trigger on pushes to `AspNetHelloWorld` or `main` branches.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}

0 commit comments

Comments
 (0)