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
0 commit comments