-
Notifications
You must be signed in to change notification settings - Fork 3k
308 lines (290 loc) · 16.8 KB
/
package-on-merge.yaml
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# THIS WORKFLOW WILL GET TRIGGERED WHEN PR IS MERGED IN MASTER
name: Package Command On Merge Of PR
env:
APPINSIGHTS: "${{ vars.APPINSIGHTS }}"
DEFAULTPACKAGEVERSION: "${{ vars.DEFAULTPACKAGEVERSION }}"
BLOB_CONN_STRING: "${{ secrets.BLOB_CONN_STRING }}"
BASE_FOLDER_PATH: "${{ vars.BASEFOLDERPATH }}"
BRANCH_NAME: "${{ github.event.pull_request.head.ref }}"
ADO_TOKEN: "${{ secrets.ADO_TOKEN }}"
ADO_BASE_URL: "${{ vars.ADO_BASE_URL }}"
ADO_AREAPATH: "${{ vars.ADO_AREAPATH }}"
ADO_TEAMPROJECT: "${{ vars.ADO_TEAMPROJECT }}"
ADO_PARENT_LINK: "${{ vars.ADO_PARENT_LINK }}"
on:
pull_request:
branches:
- master
paths:
- Solutions/**
types:
- closed
jobs:
checkAutomatedPR:
if: ${{ github.event.pull_request.merged && !github.event.pull_request.head.repo.fork }}
uses: ./.github/workflows/checkAutomatedPR.yaml
solutionNameDetails:
if: ${{ github.event.pull_request.merged && !github.event.pull_request.head.repo.fork }}
needs: checkAutomatedPR
uses: ./.github/workflows/getSolutionName.yaml
secrets: inherit
checkSkipPackagingDetails:
if: ${{ github.event.pull_request.merged && !github.event.pull_request.head.repo.fork && needs.solutionNameDetails.outputs.solutionName != '' }}
uses: ./.github/workflows/checkSkipPackagingInfo.yaml
secrets: inherit
needs: solutionNameDetails
with:
solutionName: "${{ needs.solutionNameDetails.outputs.solutionName }}"
neworexistingsolution:
needs: [solutionNameDetails, checkSkipPackagingDetails]
uses: ./.github/workflows/neworexistingsolution.yaml
if: ${{ needs.solutionNameDetails.outputs.solutionName != '' && needs.checkSkipPackagingDetails.outputs.isPackagingRequired == 'True' }}
with:
solutionName: "${{ needs.solutionNameDetails.outputs.solutionName }}"
secrets: inherit
createpackage:
runs-on: ubuntu-latest
permissions:
contents: read
needs: [solutionNameDetails, neworexistingsolution]
env:
RUNID: "${{ github.event.client_payload.github.runId }}"
PULL_REQUEST_NUMBER: "${{ github.event.pull_request.number }}"
SOLUTION_NAME: "${{ needs.solutionNameDetails.outputs.solutionName }}"
SOLUTION_SUPPORTED_BY: "${{ needs.neworexistingsolution.outputs.solutionSupportedBy }}"
SOLUTION_OFFER_ID: "${{ needs.neworexistingsolution.outputs.solutionOfferId }}"
IS_NEW_SOLUTION: "${{ needs.neworexistingsolution.outputs.isNewSolution }}"
outputs:
isCreatePackage: ${{ steps.step1.outputs.isCreatePackage }}
packageCreationPath: "${{ steps.step1.outputs.packageCreationPath }}"
packageVersion: "${{ steps.step1.outputs.packageVersion }}"
blobName: "${{ steps.step1.outputs.blobName }}"
dataFileLink: "${{ steps.step1.outputs.dataFileLink }}"
dataFolderPath: "${{ steps.step1.outputs.dataFolderPath }}"
solutionBaseFolderPath: "${{ steps.step1.outputs.solutionBaseFolderPath }}"
dataInputFileName: "${{ steps.step1.outputs.dataInputFileName }}"
steps:
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab
with:
fetch-depth: 2
ref: ${{ env.BRANCH_NAME }}
- shell: pwsh
id: step1
name: Check & Initiate Package Creation Process
run: |
$instrumentationKey = "${{ env.APPINSIGHTS }}"
$defaultPackageVersion = "${{ vars.defaultPackageVersion }}"
$solutionSupportedBy = "${{ env.SOLUTION_SUPPORTED_BY }}"
$solutionOfferId = "${{ env.SOLUTION_OFFER_ID }}"
$runId = "${{ env.RUNID }}"
$solutionName = "${{ needs.solutionNameDetails.outputs.solutionName }}"
$pullRequestNumber = "${{ github.event.pull_request.number }}"
$isNewSolution = "${{ env.IS_NEW_SOLUTION }}"
Write-Host "RunId = $runId, defaultPackageVersion = $defaultPackageVersion, solutionOfferId = $solutionOfferId, SOLUTION_NAME = $solutionName, PULL_REQUEST_NUMBER = $pullRequestNumber, isNewSolution = $isNewSolution"
. ./Tools/Create-Azure-Sentinel-Solution/common/LogAppInsights.ps1
try
{
$customProperties = @{ 'RunId'="$runId"; 'PullRequestNumber'="$pullRequestNumber"; 'EventName'="Create Package"; 'IsNewSolution'='$isNewSolution';'SolutionOfferId'='$solutionOfferId';'SolutionSupportedBy'='$solutionSupportedBy';'SolutionName'='$solutionName'; }
Send-AppInsightsEventTelemetry -InstrumentationKey $instrumentationKey -EventName "Create Package" -CustomProperties $customProperties
if ($solutionName -eq '' -or $null -eq $solutionName)
{
Write-Output "::warning:: Package-Creation : Skipping as Solution name is blank."
Send-AppInsightsTraceTelemetry -InstrumentationKey $instrumentationKey -Message "Execution for create-package started and received blank solutionName for Job Run Id : $runId" -Severity Information -CustomProperties $customProperties
}
else
{
Send-AppInsightsTraceTelemetry -InstrumentationKey $instrumentationKey -Message "Execution for create-package started for Solution Name : $solutionName, Job Run Id : $runId" -Severity Information -CustomProperties $customProperties
$baseFolderPath = "/home/runner/work/Azure-Sentinel/Azure-Sentinel/"
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module powershell-yaml
./.script/package-automation/package-generator.ps1 $solutionName $pullRequestNumber $runId $instrumentationKey $defaultPackageVersion $solutionOfferId $baseFolderPath $isNewSolution
}
}
catch
{
Send-AppInsightsExceptionTelemetry -InstrumentationKey $instrumentationKey -Exception $_.Exception -CustomProperties @{ 'RunId'="$runId"; 'SolutionName'="$solutionName"; 'PullRequestNumber'="$pullRequestNumber"; 'ErrorDetails'="CreatePackage : Error occured in catch block: $_"; 'EventName'="Create Package"; 'SolutionOfferId'="$solutionOfferId"; }
exit 1
}
- name: Upload Artifacts
id: uploadPackageArtifacts
uses: actions/upload-artifact@e0057a5b76f2fdad976135e8dd7b691e632b9056
env:
BLOBNAME: "${{ steps.step1.outputs.blobName }}"
PACKAGE_CREATION_PATH: "${{ steps.step1.outputs.packageCreationPath }}"
DATA_FOLDER_PATH: "${{ steps.step1.outputs.dataFolderPath }}"
DATA_INPUT_FILE_NAME: "${{ steps.step1.outputs.dataInputFileName }}"
SOLUTION_NAME: "${{ needs.solutionNameDetails.outputs.solutionName }}"
SOLUTION_SUPPORTED_BY: "${{ needs.neworexistingsolution.outputs.solutionSupportedBy }}"
RUNID: "${{ github.event.client_payload.github.runId }}"
PULL_REQUEST_NUMBER: "${{ github.event.pull_request.number }}"
IS_CREATE_PACKAGE: ${{ steps.step1.outputs.isCreatePackage }}
if: ${{ success() && (steps.step1.outcome == 'success' && env.IS_CREATE_PACKAGE && env.PACKAGE_CREATION_PATH != '' && env.BLOBNAME != '') }}
with:
name: "${{ env.BLOBNAME }}"
path: "${{ env.PACKAGE_CREATION_PATH }}"
- name: Upload Data File Artifacts
id: uploadDataFileArtifact
uses: actions/upload-artifact@e0057a5b76f2fdad976135e8dd7b691e632b9056
env:
DATA_FOLDER_PATH: "${{ steps.step1.outputs.dataFolderPath }}"
DATA_INPUT_FILE_NAME: "${{ steps.step1.outputs.dataInputFileName }}"
if: ${{ success() && (steps.step1.outcome == 'success' && env.DATA_FOLDER_PATH != '' && env.DATA_INPUT_FILE_NAME != '') }}
with:
name: "${{ env.DATA_INPUT_FILE_NAME }}"
path: "${{ env.DATA_FOLDER_PATH }}"
- shell: pwsh
id: uploadartifacts
name: uploadartifactsEvent
run: |
$solutionSupportedBy = "${{ env.SOLUTION_SUPPORTED_BY }}"
$runId = "${{ github.event.client_payload.github.runId }}"
$solutionName = "${{ env.SOLUTION_NAME }}"
$pullRequestNumber = "${{ env.PULL_REQUEST_NUMBER }}"
$instrumentationKey = "${{ env.APPINSIGHTS }}"
. ./Tools/Create-Azure-Sentinel-Solution/common/LogAppInsights.ps1
$customProperties = @{ 'RunId'="$runId"; 'SolutionName'="$solutionName"; 'PullRequestNumber'="$pullRequestNumber"; 'EventName'="Upload Artifacts"; }
Send-AppInsightsEventTelemetry -InstrumentationKey $instrumentationKey -EventName "Upload Artifacts" -CustomProperties $customProperties
Send-AppInsightsTraceTelemetry -InstrumentationKey $instrumentationKey -Message "Execution for Uploaded Artifacts for Solution Name : $solutionName, Job Run Id : $runId" -Severity Information -CustomProperties $customProperties
createNewPR:
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
needs: [solutionNameDetails, neworexistingsolution, createpackage]
env:
BLOBNAME: "${{ needs.createpackage.outputs.blobName }}"
IS_CREATE_PACKAGE: ${{ needs.createpackage.outputs.isCreatePackage }}
PACKAGE_CREATION_PATH: "${{ needs.createpackage.outputs.packageCreationPath }}"
DATA_FOLDER_PATH: "${{ needs.createpackage.outputs.dataFolderPath }}"
DATA_INPUT_FILE_NAME: "${{ needs.createpackage.outputs.dataInputFileName }}"
SOLUTION_NAME: "${{ needs.solutionNameDetails.outputs.solutionName }}"
PULL_REQUEST_NUMBER: "${{ github.event.pull_request.number }}"
SOLUTION_SUPPORTED_BY: "${{ needs.neworexistingsolution.outputs.solutionSupportedBy }}"
ACTOR: "${{ github.actor }}"
ASSIGNEES: "${{ github.event.client_payload.github.actor }}"
CURRENT_BRANCH_NAME: "${{ github.event.pull_request.head.ref }}"
RUNID: "${{ github.event.client_payload.github.runId }}"
APPINSIGHTS: "${{ vars.APPINSIGHTS }}"
outputs:
newPRNumber: ${{ steps.create-new-pr.outputs.pull-request-number }}
steps:
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab
- uses: actions/download-artifact@e9ef242655d12993efdcda9058dee2db83a2cb9b
with:
name : "${{ env.BLOBNAME }}"
path: "${{ env.PACKAGE_CREATION_PATH }}"
- uses: actions/download-artifact@e9ef242655d12993efdcda9058dee2db83a2cb9b
with:
name: "${{ env.DATA_INPUT_FILE_NAME }}"
path: "${{ env.DATA_FOLDER_PATH }}"
- name: create-new-pr
id: create-new-pr
if: ${{ success() && (env.IS_CREATE_PACKAGE && env.PACKAGE_CREATION_PATH != '' && env.BLOBNAME != '') }}
uses: peter-evans/create-pull-request@5b4a9f6a9e2af26e5f02351490b90d01eb8ec1e5
with:
committer: GitHub <noreply@github.com>
assignees: "${{ env.ASSIGNEES }}"
signoff: false
branch: "${{ env.CURRENT_BRANCH_NAME }}-automated-pr"
base: master
delete-branch: false
title: '[GitHub Bot] 🤖 Package Created For ${{ env.SOLUTION_NAME }} Solution'
body: |
Automation have successfully generated package for solution '${{ env.SOLUTION_NAME }}' based on Pull request #${{ env.PULL_REQUEST_NUMBER }}.
- shell: pwsh
id: createPREvents
name: createPREvents
run: |
. ./Tools/Create-Azure-Sentinel-Solution/common/LogAppInsights.ps1
$runId = "${{ env.RUNID }}"
$solutionName = "${{ env.SOLUTION_NAME }}"
$pullRequestNumber = "${{ env.PULL_REQUEST_NUMBER }}"
$instrumentationKey = "${{ env.APPINSIGHTS }}"
$previousStepSuccessValue = "${{ steps.create-new-pr.outcome }}"
try
{
$customProperties = @{ 'RunId'="$runId"; 'SolutionName'="$solutionName"; 'PullRequestNumber'="$pullRequestNumber"; 'EventName'="Create New PR"; 'create-new-pr-output'="$previousStepSuccessValue" }
Send-AppInsightsTraceTelemetry -InstrumentationKey $instrumentationKey -Message "Execution for create new pull request started for Solution Name : $solutionName, Job Run Id : $runId" -Severity Information -CustomProperties $customProperties
Send-AppInsightsEventTelemetry -InstrumentationKey $instrumentationKey -EventName "Create New PR" -CustomProperties $customProperties
}
catch
{
$customProperties = @{ 'RunId'="$runId"; 'SolutionName'="$solutionName"; 'PullRequestNumber'="$pullRequestNumber"; 'EventName'="Create New PR Events"; 'create-new-pr-output'="failed" }
Send-AppInsightsExceptionTelemetry -InstrumentationKey $instrumentationKey -Exception $_.Exception -CustomProperties $customProperties
exit 1
}
addCommentOnNewPRCreation:
needs: [solutionNameDetails, createNewPR]
if: ${{ success() && needs.createNewPR.outputs.newPRNumber != '' }}
uses: ./.github/workflows/addComment.yaml
with:
message: "@${{ github.event.client_payload.github.actor }} The requested package for the '${{ needs.solutionNameDetails.outputs.solutionName }}' solution has been generated based on Pull request #${{ github.event.client_payload.pull_request.number }}"
prNumber: "${{ needs.createNewPR.outputs.newPRNumber }}"
release-project:
name: Publish-Artifacts
runs-on: ubuntu-latest
permissions:
contents: read
needs: [createpackage, createNewPR]
env:
BLOBNAME: "${{ needs.createpackage.outputs.blobName }}"
IS_CREATE_PACKAGE: ${{ needs.createpackage.outputs.isCreatePackage }}
PACKAGE_CREATION_PATH: "${{ needs.createpackage.outputs.packageCreationPath }}"
PULL_REQUEST_NUMBER: "${{ github.event.pull_request.number }}"
RUNID: "${{ github.event.client_payload.github.runId }}"
APPINSIGHTS: "${{ vars.APPINSIGHTS }}"
SOLUTION_NAME: "${{ needs.solutionNameDetails.outputs.solutionName }}"
if: ${{ needs.createpackage.outputs.isCreatePackage && needs.createpackage.outputs.packageCreationPath != '' }}
steps:
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab
- name: Download artifacts
id: downloadArtifacts
uses: actions/download-artifact@e9ef242655d12993efdcda9058dee2db83a2cb9b
with:
name: "${{ env.BLOBNAME }}"
path: "${{ env.PACKAGE_CREATION_PATH }}"
- shell: pwsh
run: |
$runId = "${{ env.RUNID }}"
$solutionName = "${{ env.SOLUTION_NAME }}"
$pullRequestNumber = "${{ env.PULL_REQUEST_NUMBER }}"
$blobName = "${{ env.BLOBNAME }}"
$isCreatePackage = "${{ env.IS_CREATE_PACKAGE }}"
$packageCreationPath = "${{ env.PACKAGE_CREATION_PATH }}"
$instrumentationKey = "${{ env.APPINSIGHTS }}"
. ./Tools/Create-Azure-Sentinel-Solution/common/LogAppInsights.ps1
$customProperties = @{ 'RunId'="$runId"; 'SolutionName'="$solutionName"; 'PullRequestNumber'="$pullRequestNumber"; 'EventName'="Download artifacts"; 'BlobName'="$blobName"; 'isCreatePackage'="$isCreatePackage"; 'PackageCreationPath'="$packageCreationPath"; }
Send-AppInsightsEventTelemetry -InstrumentationKey $instrumentationKey -EventName "Download artifacts" -CustomProperties $customProperties
Send-AppInsightsTraceTelemetry -InstrumentationKey $instrumentationKey -Message "Execution for download artifacts started for Solution Name : $solutionName, Job Run Id : $runId" -Severity Information -CustomProperties $customProperties
- uses: fixpoint/azblob-upload-artifact@41eaaaa8fa50a5ba144d1d106c0e4ca11ca60c08
id: uploadBlobStorage
if: ${{ success() && steps.downloadArtifacts.outcome == 'success' }}
env:
blobName: "${{ env.BLOBNAME }}"
packageCreationPath: "${{ env.PACKAGE_CREATION_PATH }}"
with:
connection-string: "${{ env.BLOB_CONN_STRING }}"
name: "${{ env.BLOBNAME }}"
path: "${{ env.PACKAGE_CREATION_PATH }}"
create-ado:
runs-on: ubuntu-latest
needs: [solutionNameDetails, neworexistingsolution, createpackage, createNewPR, addCommentOnNewPRCreation, release-project]
if: ${{ always() && contains(join(needs.*.result, ','), 'failure') }}
# if: ${{ always() && contains(needs.*.result, 'failure') }}
steps:
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab
- shell: pwsh
name: Create ADO Record
run: |
$adoToken = "${{ env.ADO_TOKEN }}"
$adoBaseUrl = "${{ env.ADO_BASE_URL}}"
$adoAreaPath = "${{ env.ADO_AREAPATH}}"
$adoTeamProject = "${{ env.ADO_TEAMPROJECT}}"
$prNumber = "${{ github.event.pull_request.number }}"
$prTitle = "${{ github.event.client_payload.pull_request.title}}"
$dataFileLink = "${{ needs.createNewPR.outputs.dataFileLink }}"
$adoParentLink = "${{ env.ADO_PARENT_LINK }}"
$instrumentationKey = "${{ env.APPINSIGHTS }}"
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module powershell-yaml
./.script/package-automation/createADOItem.ps1 $adoToken $adoBaseUrl $adoAreaPath $adoTeamProject $prNumber $prTitle $dataFileLink $adoParentLink $instrumentationKey