-
Notifications
You must be signed in to change notification settings - Fork 18
148 lines (125 loc) · 4.32 KB
/
deploy.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: Deploy
on:
push:
branches: ["main"]
tags: ["v[0-9]+.[0-9]+.[0-9]+"]
workflow_dispatch:
schedule:
- cron: "0 0 * * *"
env:
PRODUCTION_URL: https://nugettools.azurewebsites.net
jobs:
build:
runs-on: windows-latest
outputs:
versions-changed: ${{ steps.check-versions.outputs.versions-changed }}
steps:
- name: Check out
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up .NET Core
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x
- name: Build
run: .\build.ps1
- name: Zip publish directory
run: Compress-Archive -Path .\src\Knapcode.NuGetTools.Website\bin\Release\net472\publish\* -DestinationPath .\src\Knapcode.NuGetTools.Website\bin\website.zip
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v3
with:
name: website
path: .\src\Knapcode.NuGetTools.Website\bin\website.zip
- name: Check for new versions
id: check-versions
run: |
$report = dotnet run --project .\src\Knapcode.NuGetTools.PackageDownloader -- check-versions .\src\Knapcode.NuGetTools.Website\packages ${{ env.PRODUCTION_URL }}
$report
$notMatching = $report | ? { !$_.StartsWith("Matching") }
Write-Output "versions-changed=$(($notMatching.Length -ne 0).ToString().ToLowerInvariant())" >> $Env:GITHUB_OUTPUT
deploy-to-dev:
concurrency:
group: deploy-to-dev
permissions:
id-token: write
contents: read
runs-on: windows-latest
needs: build
environment:
name: DEV
url: ${{ steps.deploy.outputs.webapp-url }}
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: website
path: .
- name: Log in to Azure
uses: azure/login@v1
with:
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
client-id: ${{ secrets.AZURE_CLIENT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Deploy
id: deploy
uses: azure/webapps-deploy@v2
with:
app-name: NuGetToolsDev
package: .\website.zip
deploy-to-prod:
concurrency:
group: deploy-to-prod
permissions:
id-token: write
contents: read
runs-on: windows-latest
needs: build
environment:
name: PROD
url: ${{ steps.set-environment-url.outputs.url }}
env:
RESOURCE_GROUP: Knapcode.NuGetTools
WEBAPP_NAME: NuGetTools
SLOT_NAME: staging
steps:
- name: Check out
uses: actions/checkout@v3
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: website
path: .
- name: Log in to Azure
uses: azure/login@v1
with:
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
client-id: ${{ secrets.AZURE_CLIENT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Deploy
id: deploy
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.WEBAPP_NAME }}
slot-name: ${{ env.SLOT_NAME }}
package: .\website.zip
- name: Copy packages for tests
run: |
Expand-Archive -Path .\website.zip -DestinationPath .\website
Copy-Item .\website\packages .\src\Knapcode.NuGetTools.Website -Recurse
- name: Run integration tests
run: dotnet test --logger "console;verbosity=normal" --filter "FullyQualifiedName~Knapcode.NuGetTools.Website.Tests.IntegrationTest"
env:
NUGETTOOLS_BASE_URL: ${{ steps.deploy.outputs.webapp-url }}
- name: Swap slots
if: ${{ needs.build.outputs.versions-changed == 'true' || github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/v') }}
id: swap-slots
run: az webapp deployment slot swap -s ${{ env.SLOT_NAME }} -n ${{ env.WEBAPP_NAME }} -g ${{ env.RESOURCE_GROUP }}
- name: Set environment URL
id: set-environment-url
run: |
if ("${{ steps.swap-slots.outcome }}" -eq "success") {
Write-Output "url=${{ env.PRODUCTION_URL }}" >> $Env:GITHUB_OUTPUT
} else {
Write-Output "url=${{ steps.deploy.outputs.webapp-url }}" >> $Env:GITHUB_OUTPUT
}