package-command #310
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.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 && !contains(github.event.client_payload.pull_request.head.ref , 'dependabot/') && !contains(github.event.client_payload.pullRequestBranchName , 'dependabot/') }} | |
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 |