-
Notifications
You must be signed in to change notification settings - Fork 55
122 lines (107 loc) · 4.15 KB
/
ci-cd.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
name: CI/CD Pipeline
on: [ push, pull_request, workflow_dispatch ]
env:
AZURE_WEBAPP_NAME: devBetter
AZURE_GROUP_NAME: DevBetterGroup
AZURE_WEBAPP_PACKAGE_PATH: '.'
jobs:
ci:
name: Continuous Integration
strategy:
matrix:
os: [ ubuntu-latest, windows-latest ]
runs-on: ${{ matrix.os }}
outputs:
is_push_to_default_branch: ${{ steps.conditionals_handler.outputs.is_push_to_default_branch }}
os: ${{ matrix.os }}
run_number: ${{ github.run_number }}
steps:
- name: Data gatherer
id: data_gatherer
shell: pwsh
run: |
# Get default branch
$repo = "${{ github.repository }}"
$defaultBranch = Invoke-RestMethod -Method GET -Uri https://api.github.com/repos/$repo | Select-Object -ExpandProperty default_branch
Write-Output "::set-output name=default_branch::$(echo $defaultBranch)"
- name: Conditionals handler
id: conditionals_handler
shell: pwsh
run: |
$defaultBranch = "${{ steps.data_gatherer.outputs.default_branch }}"
$githubRef = "${{ github.ref }}"
$githubEventName = "${{ github.event_name }}"
$currentBranch = $githubRef -replace 'refs/heads/', ''
$isDefaultBranch = 'false'
$isPush = 'false'
$isPushToDefaultBranch = 'false'
if ( $currentBranch -eq $defaultBranch ) {
$isDefaultBranch = 'true'
}
if ( $githubEventName -eq 'push' ) {
$isPush = 'true'
}
if ( $currentBranch -eq $defaultBranch -and $githubEventName -eq 'push' ) {
$isPushToDefaultBranch = 'true'
}
Write-Output "::set-output name=is_default_branch::$(echo $isDefaultBranch)"
Write-Output "::set-output name=is_push::$(echo $isPush)"
Write-Output "::set-output name=is_push_to_default_branch::$(echo $isPushToDefaultBranch)"
- name: Setup .NET Core
id: setup_dotnet_core
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
include-prerelease: true
- name: Checkout repository
id: checkout_repo
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Build solution
id: build_solution
shell: pwsh
run: |
dotnet build ./DevBetterWeb.sln --configuration Release --output Artifacts
- name: Run unit tests
id: run_unit_tests
shell: pwsh
run: |
dotnet test ./DevBetterWeb.sln --filter FullyQualifiedName!~Vimeo.Tests --configuration Release --no-build --output Artifacts
- name: Publish WebApp
id: publish_webapp
shell: pwsh
run: |
dotnet publish ./src/DevBetterWeb.Web/DevBetterWeb.Web.csproj --configuration Release --self-contained -r win-x86 --output ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/WebApp
- name: Upload build artifacts
id: upload_build_artifacts
uses: actions/upload-artifact@v4
with:
name: Build artifacts-${{ matrix.os }}-${{ github.run_number }}
path: Artifacts/
- name: Upload publish artifacts
id: upload_publish_artifacts
uses: actions/upload-artifact@v4
with:
name: Publish artifacts-${{ matrix.os }}-${{ github.run_number }}
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/WebApp/
cd:
if: needs.ci.outputs.is_push_to_default_branch == 'true'
name: Continuous Deployment
needs: ci
runs-on: windows-latest
steps:
- name: Download publish artifacts
id: dl_publish_artifacts
uses: actions/download-artifact@v4
with:
name: Publish artifacts-${{ needs.ci.outputs.os }}-${{ needs.ci.outputs.run_number }}
path: WebApp/
- name: Azure webapp deploy with Publish Profile
id: azure_webapp_deploy_with_publish_profile
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZUREWEBAPPPUBLISHPROFILE }}
package: '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/WebApp'