Skip to content

Commit e60dc33

Browse files
authored
Merge branch 'master' into dev
2 parents 4ef13c2 + 0942f68 commit e60dc33

4 files changed

Lines changed: 107 additions & 13 deletions

File tree

.github/workflows/dotnet.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This workflow will build a .NET project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
3+
4+
name: dotnet
5+
6+
on:
7+
workflow_dispatch:
8+
push:
9+
branches: [ "dev" ]
10+
pull_request:
11+
branches: [ "master" ]
12+
13+
jobs:
14+
build:
15+
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
- name: Setup .NET
21+
uses: actions/setup-dotnet@v4
22+
with:
23+
dotnet-version: 9.0.x
24+
- name: Restore dependencies
25+
run: dotnet restore
26+
- name: Build
27+
run: dotnet build --no-restore
28+
- name: Test
29+
run: dotnet test --no-build --verbosity normal
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
2+
# More GitHub Actions for Azure: https://github.com/Azure/actions
3+
4+
name: Deploy to alwaysazure
5+
6+
on:
7+
push:
8+
branches:
9+
- master
10+
workflow_dispatch:
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read #This is required for actions/checkout
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Set up .NET Core
22+
uses: actions/setup-dotnet@v4
23+
with:
24+
dotnet-version: '9.x'
25+
26+
- name: Build with dotnet
27+
run: dotnet build --configuration Release
28+
29+
- name: dotnet publish
30+
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp
31+
32+
- name: Upload artifact for deployment job
33+
uses: actions/upload-artifact@v4
34+
with:
35+
name: .net-app
36+
path: ${{env.DOTNET_ROOT}}/myapp
37+
38+
deploy:
39+
runs-on: ubuntu-latest
40+
needs: build
41+
environment:
42+
name: 'test'
43+
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
44+
45+
steps:
46+
- name: Download artifact from build job
47+
uses: actions/download-artifact@v4
48+
with:
49+
name: .net-app
50+
51+
- name: Deploy to Azure Web App
52+
id: deploy-to-webapp
53+
uses: azure/webapps-deploy@v3
54+
with:
55+
app-name: 'alwaysazure'
56+
slot-name: 'test'
57+
package: .
58+
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_A0188C5895614E539E8122CE8618FB82 }}

Program.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,39 @@
44
var builder = WebApplication.CreateBuilder(args);
55

66
IConfiguration _configuration = new ConfigurationBuilder()
7+
78
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
89
.AddEnvironmentVariables()
910
.Build();
1011

11-
var clientId = _configuration["ClientId"] ?? throw new ArgumentNullException("ClientId");
12-
var clientSecret = _configuration["ClientSecret"] ?? throw new ArgumentNullException("ClientSecret");
13-
var tenantId = _configuration["TenantId"] ?? throw new ArgumentNullException("TenantId");
12+
13+
var clientId = _configuration["ClientId"];
14+
var clientSecret = _configuration["ClientSecret"];
15+
var tenantId = _configuration["TenantId"];
1416
var subscriptionId = _configuration["SubscriptionId"];
1517

1618
IConfidentialClientApplication authapp = ConfidentialClientApplicationBuilder.Create(clientId)
17-
.WithClientSecret(clientSecret)
18-
.WithAuthority(new Uri($"https://login.microsoftonline.com/{tenantId}"))
19-
.Build();
19+
.WithClientSecret(clientSecret)
20+
.WithAuthority(new Uri($"https://login.microsoftonline.com/{tenantId}"))
21+
.Build();
2022

2123
string[] scopes = ["https://management.azure.com/.default"];
22-
var authResult = await authapp.AcquireTokenForClient(scopes).ExecuteAsync();
24+
var authResult = authapp.AcquireTokenForClient(scopes).ExecuteAsync();
2325

2426

2527
builder.Services.AddHttpClient("AzureServices", httpClient =>
2628
{
2729
httpClient.BaseAddress = new Uri($"https://management.azure.com/subscriptions/{subscriptionId}/");
28-
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authResult.AccessToken);
30+
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authResult.Result.AccessToken);
2931
});
3032

3133
// Add services to the container.
3234
builder.Services.AddControllersWithViews();
3335

36+
// Add configuration
37+
builder.Configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
38+
.AddEnvironmentVariables();
39+
3440
// Register the HTTP client
3541
builder.Services.AddHttpClient();
3642

@@ -43,7 +49,6 @@
4349
options.Cookie.HttpOnly = true;
4450
options.Cookie.IsEssential = true;
4551
});
46-
4752
var app = builder.Build();
4853

4954
// Configure the HTTP request pipeline.
@@ -60,7 +65,7 @@
6065
app.UseAuthorization();
6166

6267
app.MapControllerRoute(
63-
name: "default",
64-
pattern: "{controller=Home}/{action=Index}/{id?}");
68+
name: "default",
69+
pattern: "{controller=Home}/{action=Index}/{id?}");
6570

66-
await app.RunAsync();
71+
app.Run();

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
# AzureIntegration
1+
# Build Process (dotnet 9.0)
2+
3+
![](https://github.com/sayedimac/AzureIntegration/workflows/dotnet/badge.svg)

0 commit comments

Comments
 (0)