-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (139 loc) · 6.1 KB
/
Copy pathbuild.yml
File metadata and controls
152 lines (139 loc) · 6.1 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: samplefunctionapi_ci
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.301
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore --configuration Release
- name: Test
run: dotnet test --no-build --verbosity normal
#- name: Install Swagger DLLs
# run: dotnet tool install --version 5.6.2 Swashbuckle.AspNetCore.Cli
#- name: Swagger
# run: dotnet swagger tofile --output swagger.json SampleFunctionAPI/bin/Release/netcoreapp3.1/SampleFunctionAPI.dll v1
#- name: Run Spectral
# uses: stoplightio/spectral-action@v0.7.0
# with:
# file_glob: './swagger.json'
- name: Publish
run: dotnet publish --no-build -c Release -o dotnetcorefuncapp
- name: Zip
uses: thedoctor0/zip-release@master
with:
filename: dotnetcorefuncapp.zip
directory: 'dotnetcorefuncapp'
- name: Display structure of downloaded files
run: ls -R
- name: Publish Build Artifacts
uses: actions/upload-artifact@v2
with:
name: dotnetcorefuncapp
path: '**/dotnetcorefuncapp.zip'
- name: Publish Policy Artifacts
uses: actions/upload-artifact@v2
with:
name: dotnetcorefuncapppolicies
path: '**/BackendServicePolicy.xml'
deploy_to_DEV:
name: Deploy DEV
runs-on: ubuntu-latest
environment:
name: DEV
needs: [build]
steps:
- name: download samplefuncapi build
uses: actions/download-artifact@v2
with:
name: dotnetcorefuncapp
- name: download samplefuncapi policies
uses: actions/download-artifact@v2
with:
name: dotnetcorefuncapppolicies
- name: Display structure of downloaded files
run: ls -R
# deploying without slots
- name: 'Run Azure Functions Action'
uses: Azure/functions-action@v1
id: fa
with:
app-name: samplefunctionapi-bc01
package: './dotnetcorefuncapp/dotnetcorefuncapp.zip'
publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }}
# az ad sp create-for-rbac --name "github-AzureSponsorship-3e2bea16-63ed-4349-9b9c-fe2f91f8e3d4" --sdk-auth --role contributor --scopes /subscriptions/3e2bea16-63ed-4349-9b9c-fe2f91f8e3d4
- name: Login via Az module
uses: azure/login@v1
with:
creds: ${{secrets.AZURE_CREDENTIALS}}
enable-AzPSSession: true
# APIM - Create the Versioned API before running the deployment
- name: Run Azure PowerShell script
uses: azure/powershell@v1
with:
inlineScript: |
$ApiMgmtContext = New-AzApiManagementContext -ResourceGroupName "Samples" -ServiceName "samplebc"
$Tags = 'key', 'function', 'auto'
New-AzApiManagementNamedValue -Context $ApiMgmtContext -NamedValueId "samplefunctionapi-bc01-key" -Name "samplefunctionapi-bc01-key" -Value "${{secrets.SAMPLEFUNCTIONAPI_BC01_KEY}}" -Secret -Tag $Tags
$credential = New-AzApiManagementBackendCredential -Header @{"x-functions-key" = @("{{samplefunctionapi-bc01-key}}")}
New-AzApiManagementBackend -Context $ApiMgmtContext -BackendId samplefunctionapi-bc01 -ResourceId https://management.azure.com/subscriptions/3e2bea16-63ed-4349-9b9c-fe2f91f8e3d4/resourceGroups/Samples/providers/Microsoft.Web/sites/samplefunctionapi-bc01 -Url 'https://samplefunctionapi-bc01.azurewebsites.net' -Protocol http -Credential $credential -Description "samplefunctionapi-bc01"
Set-AzApiManagementPolicy -Context $ApiMgmtContext -ApiId "sample-function-api" -PolicyFilePath './APIMPolicy/BackendServicePolicy.xml'
$newRevision = ${{ github.run_number }}
$revision = New-AzApiManagementApiRevision -Context $ApiMgmtContext -ApiId "sample-function-api" -ApiRevision "$newRevision" -ServiceUrl https://samplefunctionapi-bc01.azurewebsites.net
Import-AzApiManagementApi -Context $ApiMgmtContext -SpecificationFormat OpenApi -SpecificationUrl https://samplefunctionapi-bc01.azurewebsites.net/api/swagger/json -ApiId "sample-function-api" -ApiRevision $revision.APIRevision -Path samplefuncapi -ServiceUrl https://samplefunctionapi-bc01.azurewebsites.net
azPSVersion: '4.7.0'
deploy_to_DEV_afterTesting:
name: Deploy DEV After Testing
runs-on: ubuntu-latest
environment:
name: DEV
needs: [deploy_to_DEV]
steps:
- name: download samplefuncapi build
uses: actions/download-artifact@v2
with:
name: dotnetcorefuncapp
- name: download samplefuncapi policies
uses: actions/download-artifact@v2
with:
name: dotnetcorefuncapppolicies
- name: Display structure of downloaded files
run: ls -R
# Swap Slot (not using slots)
#- name: 'Run Azure Functions Action'
# uses: Azure/functions-action@v1
# id: fa
# with:
# app-name: samplefunctionapi-bc01
# package: './dotnetcorefuncapp/dotnetcorefuncapp.zip'
# publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }}
# az ad sp create-for-rbac --name "github-AzureSponsorship-3e2bea16-63ed-4349-9b9c-fe2f91f8e3d4" --sdk-auth --role contributor --scopes /subscriptions/3e2bea16-63ed-4349-9b9c-fe2f91f8e3d4
- name: Login via Az module
uses: azure/login@v1
with:
creds: ${{secrets.AZURE_CREDENTIALS}}
enable-AzPSSession: true
# APIM - Create the Versioned API before running the deployment
- name: Run Azure PowerShell script
uses: azure/powershell@v1
with:
inlineScript: |
$ApiMgmtContext = New-AzApiManagementContext -ResourceGroupName "Samples" -ServiceName "samplebc"
$newRevision = ${{ github.run_number }}
$newApiManagementApiReleaseParams = @{
Context = $ApiMgmtContext
ApiId = "sample-function-api"
ApiRevision = $newRevision
}
New-AzApiManagementApiRelease @newApiManagementApiReleaseParams
azPSVersion: '4.7.0'