Azure-Sentinel/.azure-pipelines/callGithubWorkflow.yaml

109 строки
3.9 KiB
YAML

jobs:
- job: "CallGithubWorkflow"
pool:
vmImage: 'ubuntu-latest'
variables:
- group: autopackaging
# NAME OF THE JOB THAT DEPENDS
dependsOn:
- SolutionValidations
- JsonFileValidation
- KqlValidations
- logoValidator
- NonAsciiValidations
- PlaybooksValidations
- sampleDataValidator
- WorkbooksTemplateValidations
- WorkbooksValidations
- ContentValidations
- DataConnectorValidations
- DetectionsValidations
- DetectionTemplateSchemaValidation
- DocumentsLinkValidation
- YamlFileValidation
condition: |
and
(
ne(variables['SYSTEM.PULLREQUEST.ISFORK'], 'true'),
ne(variables['Build.SourceBranch'], 'refs/heads/master'),
ne(variables['System.PullRequest.SourceBranch'], 'master'),
eq(variables['System.PullRequest.TargetBranch'], 'master'),
eq(dependencies.SolutionValidations.result, 'Succeeded'),
eq(dependencies.JsonFileValidation.result, 'Succeeded'),
eq(dependencies.KqlValidations.result, 'Succeeded'),
eq(dependencies.logoValidator.result, 'Succeeded'),
eq(dependencies.NonAsciiValidations.result, 'Succeeded'),
eq(dependencies.PlaybooksValidations.result, 'Succeeded'),
eq(dependencies.sampleDataValidator.result, 'Succeeded'),
eq(dependencies.WorkbooksTemplateValidations.result, 'Succeeded'),
eq(dependencies.WorkbooksValidations.result, 'Succeeded'),
eq(dependencies.ContentValidations.result, 'Succeeded'),
eq(dependencies.DataConnectorValidations.result, 'Succeeded'),
eq(dependencies.DetectionsValidations.result, 'Succeeded'),
eq(dependencies.DetectionTemplateSchemaValidation.result, 'Succeeded'),
eq(dependencies.DocumentsLinkValidation.result, 'Succeeded'),
eq(dependencies.YamlFileValidation.result, 'Succeeded')
)
steps:
- checkout: none
- pwsh: |
try
{
$branchName = "$(System.PullRequest.SourceBranch)"
$targetBranch = "$(System.PullRequest.TargetBranch)"
$pullRequestNumber = "$(System.PullRequest.PullRequestNumber)"
$isAutoGeneratedOrDependabotPR = [bool]($branchName -match "dependabot/|-automated-pr")
Write-Host "BranchName is $branchName, pullRequestNumber $pullRequestNumber, isAutoGeneratedOrDependabotPR $isAutoGeneratedOrDependabotPR"
# NOT MAIN/MASTER OR AUTOMATED BRANCH
if ($branchName -ne 'master' -and $isAutoGeneratedOrDependabotPR -eq $false -and $targetBranch -eq 'master')
{
# INVOKE GITHUB WORKFLOW
$header = @{
"Accept" = "application/vnd.github+json"
}
$githubToken = "$($env:GITHUB_TOKEN_VALUE)"
$token = $githubToken | ConvertTo-SecureString -AsPlainText -Force
$pullRequestNumberInt = [int]$pullRequestNumber
$client_payload = @{
"pullRequestBranchName" = "$branchName"
"pullRequestNumber" = $pullRequestNumberInt
}
$BodyJson = @{
"event_type" = "package-command"
"client_payload" = $client_payload
}
$jsonBody = $BodyJson | ConvertTo-Json
Write-Host "jsonBody $jsonBody"
$Parameters = @{
Method = "POST"
Uri = "https://api.github.com/repos/Azure/Azure-Sentinel/dispatches"
Headers = $header
ContentType = "application/json"
Body = $jsonBody
Authentication = "Bearer"
Token = $token
}
$result = Invoke-RestMethod @Parameters
Write-Host $result
}
else
{
Write-Host "Skipping Github Workflow from execution as current branch is a Master branch/Automated PR/Dependabot or target branch is not master."
}
}
catch
{
Write-Host "Error occured in callGithubWorkflow $_"
}
displayName: 'Call Github Workflow'
env:
GITHUB_TOKEN_VALUE: $(githubTokenValue)
continueOnError: true