-
Notifications
You must be signed in to change notification settings - Fork 5
130 lines (110 loc) · 5.5 KB
/
azure-dev.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
on:
workflow_dispatch:
push:
branches:
- main
- 'feature/*'
pull_request:
branches:
- main
# https://learn.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-portal%2Clinux#set-up-azure-login-with-openid-connect-authentication
permissions:
id-token: write
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login to Azure
# if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
uses: azure/login@v1
with:
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
client-id: ${{ vars.AZURE_CLIENT_ID }}
# - name: Install Azure Developer CLI
# if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
# uses: Azure/[email protected]
- name: Install Azure Developer CLI (nightly build)
# if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
shell: pwsh
run: |
Invoke-RestMethod 'https://aka.ms/install-azd.ps1' -OutFile ./install-azd.ps1
./install-azd.ps1 -Version daily
- name: Login to Azure Developer CLI
# if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
shell: pwsh
run: |
azd auth login `
--tenant-id "${{ vars.AZURE_TENANT_ID }}" `
--client-id "${{ vars.AZURE_CLIENT_ID }}" `
--federated-credential-provider "${{ vars.AZD_PIPELINE_PROVIDER }}"
- name: Setup environment
# if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
shell: pwsh
run: |
# Create config.json under .azure
New-Item -Type Directory .azure
$config = @{ version = 1; defaultEnvironment = "${{ vars.AZURE_ENV_NAME }}" }
$config | ConvertTo-Json -Depth 100 | Out-File -Path ./.azure/config.json -Force
# Create config.json under .azure/${{ vars.AZURE_ENV_NAME }}
New-Item -Type Directory .azure/${{ vars.AZURE_ENV_NAME }}
$config = @{ services = @{ app = @{ config = @{ exposedServices = @( "webapp" ) } } } }
$config | ConvertTo-Json -Depth 100 | Out-File -Path ./.azure/${{ vars.AZURE_ENV_NAME }}/config.json -Force
# Create .env under .azure/${{ vars.AZURE_ENV_NAME }}
$dotenv = @()
$dotenv += "AZD_PIPELINE_PROVIDER=`"${{ vars.AZD_PIPELINE_PROVIDER }}`""
$dotenv += "AZURE_CONTAINER_APPS_ENVIRONMENT_DEFAULT_DOMAIN=`"${{ vars.AZURE_CONTAINER_APPS_ENVIRONMENT_DEFAULT_DOMAIN }}`""
$dotenv += "AZURE_CONTAINER_APPS_ENVIRONMENT_ID=`"${{ vars.AZURE_CONTAINER_APPS_ENVIRONMENT_ID }}`""
$dotenv += "AZURE_CONTAINER_REGISTRY_ENDPOINT=`"${{ vars.AZURE_CONTAINER_REGISTRY_ENDPOINT }}`""
$dotenv += "AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_ID=`"${{ vars.AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_ID }}`""
$dotenv += "AZURE_ENV_NAME=`"${{ vars.AZURE_ENV_NAME }}`""
$dotenv += "AZURE_LOCATION=`"${{ vars.AZURE_LOCATION }}`""
$dotenv += "AZURE_PIPELINE_CLIENT_ID=`"${{ vars.AZURE_PIPELINE_CLIENT_ID }}`""
$dotenv += "AZURE_SUBSCRIPTION_ID=`"${{ vars.AZURE_SUBSCRIPTION_ID }}`""
$dotenv += "MANAGED_IDENTITY_CLIENT_ID=`"${{ vars.MANAGED_IDENTITY_CLIENT_ID }}`""
$dotenv += "SERVICE_BINDING_QUEUE_ENDPOINT=`"${{ vars.SERVICE_BINDING_QUEUE_ENDPOINT }}`""
$dotenv += "SERVICE_BINDING_TABLE_ENDPOINT=`"${{ vars.SERVICE_BINDING_TABLE_ENDPOINT }}`""
$dotenv | Out-File -Path ./.azure/${{ vars.AZURE_ENV_NAME }}/.env -Force
- name: Update appsettings.json
# if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
shell: pwsh
run: |
$resourceName = az resource list -g rg-${{ vars.AZURE_ENV_NAME }} --query "[?type=='Microsoft.CognitiveServices/accounts'].name" -o tsv
$endpoint = az cognitiveservices account show -g rg-${{ vars.AZURE_ENV_NAME }} -n $resourceName --query "properties.endpoint" -o tsv
$apiKey = az cognitiveservices account keys list -g rg-${{ vars.AZURE_ENV_NAME }} -n $resourceName --query "key1" -o tsv
$deploymentId = az cognitiveservices account deployment list -g rg-${{ vars.AZURE_ENV_NAME }} -n $resourceName --query "[].name" -o tsv
$openAI = @{ Endpoint = $endpoint; ApiKey = $apiKey; DeploymentId = $deploymentId; }
Copy-Item -Path ./AspireYouTubeSummariser.AppHost/appsettings.Development.sample.json `
-Destination ./AspireYouTubeSummariser.AppHost/appsettings.Development.json -Force
$appsettings = Get-Content -Path ./AspireYouTubeSummariser.AppHost/appsettings.Development.json | ConvertFrom-Json
$appsettings.OpenAI = $openAI
$appsettings | ConvertTo-Json -Depth 100 | Out-File -Path ./AspireYouTubeSummariser.AppHost/appsettings.Development.json -Force
- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.x
- name: Install Aspire workload
shell: pwsh
run: |
dotnet workload update
dotnet workload install aspire
- name: Restore NuGet packages
shell: bash
run: |
dotnet restore
- name: Build solution
shell: bash
run: |
dotnet build
- name: Test solution
shell: bash
run: |
dotnet test
- name: Deploy to Azure Container Apps
# if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
shell: pwsh
run: |
azd deploy