-
-
Notifications
You must be signed in to change notification settings - Fork 2
219 lines (194 loc) · 8.46 KB
/
ci-Ruya.Services.CloudStorage.Azure.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
name: Ruya.Services.CloudStorage.Azure
on:
workflow_dispatch:
inputs:
environment:
type: environment
description: 'Environment'
required: false
rollingDeployment:
type: boolean
description: 'initiate rolling deployment'
default: false
repository_dispatch:
types: [Ruya.Services.CloudStorage.Abstractions]
push:
branches: [master, release-preview, release-qa, develop]
paths:
- '.github/workflows/Ruya.Services.CloudStorage.Azure.yml'
- 'src/Ruya.Services.CloudStorage.Azure/**'
env:
version: '8.0'
productionBranch: 'master'
stagingBranch: 'release-preview'
testingBranch: 'release-qa'
integrationBranch: 'develop'
hasSha: ${{contains(toJson(github.event.client_payload), '"sha"')}}
defaults:
run:
shell: bash
concurrency:
group: ${{github.workflow}}-${{github.ref}}
cancel-in-progress: true
jobs:
build:
env:
DOTNET_NOLOGO: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
buildConfiguration: 'Release'
packageOutputPath: './artifacts/packages'
publishOutputPath: './artifacts/staging'
projectFile: './src/Ruya.Services.CloudStorage.Azure/Ruya.Services.CloudStorage.Azure.csproj'
projectTestFile: './test/Ruya.Services.CloudStorage.Azure.Tests/Ruya.Services.CloudStorage.Azure.Tests.csproj'
repositoryDispatchEventType: 'Ruya.Services.CloudStorage.Azure'
if: contains(toJson(github.event.commits), '[skip ci]') == false
timeout-minutes: 3
runs-on: ubuntu-latest
environment: ${{github.event.inputs.environment}}
outputs:
version: ${{env.version}}
repositoryDispatchEventType: ${{env.repositoryDispatchEventType}}
repository: ${{steps.extract_metadata.outputs.repository}}
branch: ${{steps.extract_metadata.outputs.branch}}
isProduction: ${{steps.extract_metadata_environment.outputs.isProduction}}
isStaging: ${{steps.extract_metadata_environment.outputs.isStaging}}
isTesting: ${{steps.extract_metadata_environment.outputs.isTesting}}
isIntegration: ${{steps.extract_metadata_environment.outputs.isIntegration}}
isDevelopment: ${{steps.extract_metadata_environment.outputs.isDevelopment}}
steps:
- if: env.hasSha=='false'
name: Checkout
uses: actions/checkout@v3
- if: env.hasSha=='true'
name: CheckoutRepositoryDispatch
uses: actions/checkout@v3
with:
ref: ${{github.event.client_payload.branch}}
- name: Extract metadata
id: extract_metadata
shell: pwsh
run: |
if ($env:hasSha -eq $true) {
$branch = "${{github.event.client_payload.branch}}"
} else {
$branch = "$env:GITHUB_REF" -replace 'refs/heads/', ''
};
Add-Content $env:GITHUB_OUTPUT "branch=$branch"
Add-Content $env:GITHUB_OUTPUT "branchsafe=$($branch -replace '/', '-')"
Add-Content $env:GITHUB_OUTPUT "repository=$($env:GITHUB_REPOSITORY -replace '.*/', '')"
Add-Content $env:GITHUB_ENV "version=$env:version.$env:GITHUB_RUN_NUMBER"
- name: Extract metadata environment
id: extract_metadata_environment
shell: pwsh
run: |
$isProduction = 0
$isStaging = 0
$isTesting = 0
$isIntegration = 0
$isDevelopment = 0
$branch = "${{steps.extract_metadata.outputs.branch}}"
if ($branch -eq "${{env.productionBranch}}" -or "${{github.event.inputs.environment}}" -eq "production") {
$isProduction = 1
}
elseif ($branch -eq "${{env.stagingBranch}}" -or "${{github.event.inputs.environment}}" -eq "staging") {
$isStaging = 1
$versionSuffix = "preview"
}
elseif ($branch -eq "${{env.testingBranch}}" -or "${{github.event.inputs.environment}}" -eq "testing") {
$isTesting = 1
$versionSuffix = "qa"
}
elseif ($branch -eq "${{env.integrationBranch}}" -or "${{github.event.inputs.environment}}" -eq "integration") {
$isIntegration = 1
$versionSuffix = "develop"
}
else {
$isDevelopment = 1
$versionSuffix = "dev"
}
if ($versionSuffix) {
$version = "$env:version-$versionSuffix"
} else {
$version = $env:version
}
Add-Content $env:GITHUB_OUTPUT "isProduction=$isProduction"
Add-Content $env:GITHUB_OUTPUT "isStaging=$isStaging"
Add-Content $env:GITHUB_OUTPUT "isTesting=$isTesting"
Add-Content $env:GITHUB_OUTPUT "isIntegration=$isIntegration"
Add-Content $env:GITHUB_OUTPUT "isDevelopment=$isDevelopment"
Add-Content $env:GITHUB_ENV "version=$version"
- name: Add PackageManager
run: |
dotnet nuget add source https://nuget.pkg.github.com/cilerler/index.json -n github -u ${{github.actor}} -p ${{secrets.PAT}} --store-password-in-clear-text
- name: Restore
run: dotnet restore $projectFile -p:Version=$version
- name: Build
run: dotnet build $projectFile --configuration $buildConfiguration -p:Version=$version
- name: Test
run: dotnet test $projectTestFile --configuration $buildConfiguration -p:CollectCoverage=true
continue-on-error: true
- name: Publish
run: dotnet publish $projectFile --configuration $buildConfiguration --no-restore --no-build --output ${{env.publishOutputPath}}
- name: Pack
run: dotnet pack $projectFile --configuration $buildConfiguration --no-restore --no-build --output ${{env.packageOutputPath}}
- name: Publish artifacts
uses: actions/upload-artifact@v3
with:
name: packages
path: ${{env.packageOutputPath}}/*.nupkg
if-no-files-found: error
retention-days: 1
- name: Create tag
if: steps.extract_metadata_environment.outputs.isProduction == false
uses: actions/github-script@v6
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/v${{env.version}}',
sha: context.sha
})
- name: Create Release
if: steps.extract_metadata_environment.outputs.isProduction == true
id: create_release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
tag_name: v${{env.version}}
name: ${{github.workflow}}.${{env.version}}
draft: false
prerelease: false
files: |
${{env.packageOutputPath}}/*.nupkg
body: |
[Changelog](https://github.com/${{github.repository}}/blob/${{steps.extract_metadata.outputs.branch}}/CHANGELOG.md)
- name: Push to GitHub Packages
run: dotnet nuget push '${{env.packageOutputPath}}/*.nupkg' --skip-duplicate --source "github" --api-key ${{secrets.GITHUB_TOKEN}}
- name: Push to Nuget
if: steps.extract_metadata_environment.outputs.isProduction == true
run: dotnet nuget push '${{env.packageOutputPath}}/*.nupkg' --skip-duplicate --source "nuget.org" --api-key ${{secrets.NUGET_API_KEY}}
- name: Publish artifacts (output)
uses: actions/upload-artifact@v3
if: failure()
with:
name: output
path: ./
retention-days: 1
dispatch:
needs: build
if: (contains(toJson(github.event.commits), '[rolling deployment]') || contains(toJson(github.event.client_payload), '"sha"') || github.event.inputs.rollingDeployment == 'true' )
strategy:
matrix:
repo: ['cilerler/ruya','cilerler/burcin']
runs-on: ubuntu-latest
steps:
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v2
with:
token: ${{secrets.PAT}}
repository: ${{matrix.repo}}
event-type: ${{needs.build.outputs.repositoryDispatchEventType}}
client-payload: '{"sha": "${{github.sha}}", "version": "${{needs.build.outputs.version}}", "repository": "${{needs.build.outputs.repository}}", "branch": "${{needs.build.outputs.branch}}", "isProduction": "${{needs.build.outputs.isProduction}}", "isStaging": "${{needs.build.outputs.isStaging}}", "isTesting": "${{needs.build.outputs.isTesting}}", "isIntegration": "${{needs.build.outputs.isIntegration}}", "isDevelopment": "${{needs.build.outputs.isDevelopment}}"}'