-
Notifications
You must be signed in to change notification settings - Fork 3k
145 lines (135 loc) · 8.1 KB
/
package-command.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
name: Package Command
env:
APPINSIGHTS: "${{ vars.APPINSIGHTS }}"
DEFAULTPACKAGEVERSION: "${{ vars.DEFAULTPACKAGEVERSION }}"
BLOB_CONN_STRING: "${{ secrets.BLOB_CONN_STRING }}"
BASE_FOLDER_PATH: "${{ vars.BASEFOLDERPATH }}"
BRANCH_NAME: "${{ github.event.client_payload.pull_request.head.ref && github.event.client_payload.pull_request.head.ref || github.event.client_payload.pullRequestBranchName }}"
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 }}"
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
PAT_TOKEN: ${{ secrets.PAT }}
on:
repository_dispatch:
types: [package-command, Package-command, PACKAGE-command]
jobs:
solutionNameDetails:
if: ${{ !github.event.pull_request.head.repo.fork }}
uses: ./.github/workflows/getSolutionName.yaml
secrets: inherit
# BELOW JOB WILL CHECK IF WE NEED TO SKIP PACKAGE CREATION OR NOT
checkSkipPackagingDetails:
if: ${{ needs.solutionNameDetails.outputs.solutionName != '' && !github.event.pull_request.head.repo.fork }}
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.run_id }}"
PULL_REQUEST_NUMBER: "${{ github.event.client_payload.pull_request.number && github.event.client_payload.pull_request.number || github.event.client_payload.pullRequestNumber }}"
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 }}
token: ${{ env.PAT_TOKEN }}
- 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.client_payload.pull_request.number && github.event.client_payload.pull_request.number || github.event.client_payload.pullRequestNumber }}"
$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.run_id }}"
PULL_REQUEST_NUMBER: "${{ github.event.client_payload.pull_request.number && github.event.client_payload.pull_request.number || github.event.client_payload.pullRequestNumber }}"
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 }}"
- name: Push changes to Existing PR
run: |
git config --global user.email "noreply@github.com"
git config --global user.name "Github Bot"
git add -A
git commit -m '[skip ci] Github Bot Added package to Pull Request!'
git push