Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<UserSecretsId>bc5587e8-3503-4e1a-816c-1e219e4047f6</UserSecretsId>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public async Task<IActionResult> PostAsync()
case "ping":
return Ok();
case "workflow_run":
this.logger.LogInformation("Received GitHub event workflow_run");
return await ProcessWorkflowRunEventAsync();
default:
this.logger.LogWarning("Received GitHub event {EventName} which is not supported", eventName);
Expand Down Expand Up @@ -72,13 +71,17 @@ private async Task<IActionResult> ProcessWorkflowRunEventAsync()

if (!VerifySignature(body, this.settings.GitHubWebhookSecret, signature))
{
this.logger.LogWarning("Received GitHub event with invalid signature");
this.logger.LogWarning("Received GitHub event {Event} with invalid signature", "workflow_run");
return Unauthorized();
}

var eventMessage = JsonDocument.Parse(body).RootElement;

if (eventMessage.GetProperty("action").GetString() == "completed")
string action = eventMessage.GetProperty("action").GetString();

this.logger.LogInformation("Received GitHub event {Event}.{Action}", "workflow_run", action);

if (action == "completed")
{
var queueMessage = new GitHubRunCompleteMessage
{
Expand All @@ -87,6 +90,8 @@ private async Task<IActionResult> ProcessWorkflowRunEventAsync()
RunId = eventMessage.GetProperty("workflow_run").GetProperty("id").GetInt64(),
};

this.logger.LogInformation("Enqueuing GitHubRunCompleteMessage for {Owner}/{Repository} run {RunId}", queueMessage.Owner, queueMessage.Repository, queueMessage.RunId);

await this.queueClient.SendMessageAsync(JsonSerializer.Serialize(queueMessage));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"FormatterName": "simple",
"FormatterOptions": {
"SingleLine": true,
"IncludeScopes": true,
"IncludeScopes": false,
"TimestampFormat": "HH:mm:ss ",
"UseUtcTimestamp": true,
"JsonWriterOptions": {
Expand All @@ -18,6 +18,7 @@
"BlobStorageAccountUri": "https://pipelinelogstest.blob.core.windows.net",
"CosmosAccountUri": "https://pipelinewitnesstest.documents.azure.com",
"GitHubWebhookSecret": "https://pipelinewitnesstest.vault.azure.net/secrets/github-webhook-validation-secret",
"GitHubAccessToken": null,
"BuildDefinitionLoopPeriod": "00:01:00",
"BuildDefinitionWorkerEnabled": true,
"BuildCompleteWorkerCount": 1,
Expand Down
45 changes: 45 additions & 0 deletions tools/pipeline-witness/Deploy-App.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<#
.SYNOPSIS
Builds and deploys the dotnet app.
#>
param(
[Parameter(Mandatory)]
[validateSet('staging', 'test')]
[string]$Target
)

$repoRoot = Resolve-Path "$PSScriptRoot/../.."
. "$repoRoot/eng/common/scripts/Helpers/CommandInvocation-Helpers.ps1"

Push-Location $PSScriptRoot
try {
$subscriptionName = $Target -eq 'test' ? 'Azure SDK Developer Playground' : 'Azure SDK Engineering System'
$parametersFile = "./infrastructure/bicep/parameters.$Target.json"

$parameters = (Get-Content -Path $parametersFile -Raw | ConvertFrom-Json).parameters
$resourceGroupName = $parameters.appResourceGroupName.value
$resourceName = $parameters.webAppName.value

Write-Host "Deploying web app to:`n" + `
" Subscription: $subscriptionName`n" + `
" Resource Group: $resourceGroupName`n" + `
" Resource: $resourceName`n"

$artifactsPath = "$repoRoot/artifacts"
$publishPath = "$artifactsPath/bin/Azure.Sdk.Tools.PipelineWitness.Tests/Release/net7.0/publish"

Invoke-LoggedCommand "dotnet publish --configuration Release"

Compress-Archive -Path "$publishPath/*" -DestinationPath "$artifactsPath/pipeline-witness.zip" -Force
if($?) {
Write-Host "pipeline-witness.zip created"
} else {
Write-Error "Failed to create pipeline-witness.zip"
exit 1
}

Invoke-LoggedCommand "az webapp deploy --src-path '$artifactsPath/pipeline-witness.zip' --subscription '$subscriptionName' --resource-group '$resourceGroupName' --name '$resourceName'"
}
finally {
Pop-Location
}
22 changes: 10 additions & 12 deletions tools/pipeline-witness/infrastructure/deploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ param(
[switch]$removeRoleAssignments
)

function Invoke([string]$command) {
Write-Host "> $command"
Invoke-Expression $command
}
$repoRoot = Resolve-Path "$PSScriptRoot/../../.."
. "$repoRoot/eng/common/scripts/Helpers/CommandInvocation-Helpers.ps1"

function RemoveStorageRoleAssignments($subscriptionId, $resourceGroup, $resourceName) {
$scope = "/subscriptions/$subscriptionId/resourceGroups/$resourceGroup/providers/Microsoft.Storage/storageAccounts/$resourceName"

Write-Host "Removing role assignments from $resourceGroup/$resourceName"
$existingAssignments = az role assignment list --scope $scope --output json | ConvertFrom-Json
$existingAssignments = Invoke-LoggedCommand "az role assignment list --scope $scope --output json" | ConvertFrom-Json

if ($existingAssignments.Count -eq 0) {
Write-Host " No role assignments found"
Expand All @@ -28,13 +26,13 @@ function RemoveStorageRoleAssignments($subscriptionId, $resourceGroup, $resource

foreach ($assignment in $existingAssignments) {
Write-Host " Removing role assignment for '$($assignment.principalName)' in role '$($assignment.roleDefinitionName)'"
Invoke "az role assignment delete --assignee '$($assignment.principalId)' --role '$($assignment.roleDefinitionId)' --scope '$scope' --yes"
Invoke-LoggedCommand "az role assignment delete --assignee '$($assignment.principalId)' --role '$($assignment.roleDefinitionId)' --scope '$scope' --yes"
}
}

function RemoveCosmosRoleAssignments($subscriptionId, $resourceGroup, $resourceName) {
Write-Host "Removing cosmos role assignments from $resourceGroup/$resourceName"
$existingAssignments = az cosmosdb sql role assignment list --account-name $resourceName --resource-group $resourceGroup --output json | ConvertFrom-Json
$existingAssignments = Invoke-LoggedCommand "az cosmosdb sql role assignment list --account-name $resourceName --resource-group $resourceGroup --output json" | ConvertFrom-Json

if ($existingAssignments.Count -eq 0) {
Write-Host " No role assignments found"
Expand All @@ -43,7 +41,7 @@ function RemoveCosmosRoleAssignments($subscriptionId, $resourceGroup, $resourceN

foreach ($assignment in $existingAssignments) {
Write-Host " Removing cosmos role assignment $($assignment.name)"
Invoke "az cosmosdb sql role assignment delete --account-name '$cosmosAccountName' --resource-group '$appResourceGroupName' --role-assignment-id '$($assignment.id)' --yes"
Invoke-LoggedCommand "az cosmosdb sql role assignment delete --account-name '$cosmosAccountName' --resource-group '$appResourceGroupName' --role-assignment-id '$($assignment.id)' --yes"
}
}

Expand All @@ -61,8 +59,8 @@ try {
$logsResourceGroupName = $parameters.logsResourceGroupName.value
$logsStorageAccountName = $parameters.logsStorageAccountName.value

Invoke "az account set --subscription '$subscriptionName'"
$subscriptionId = az account show --query id -o tsv
Invoke-LoggedCommand "az account set --subscription '$subscriptionName'"
$subscriptionId = Invoke "az account show --query id -o tsv"

./Merge-KustoScripts.ps1 -OutputPath "./artifacts/merged.kql"
if ($?) {
Expand All @@ -85,12 +83,12 @@ try {
RemoveCosmosRoleAssignments $subscriptionId $appResourceGroupName $cosmosAccountName
}

Invoke "az deployment sub create --template-file './bicep/main.bicep' --parameters '$parametersFile' --location '$location' --name '$deploymentName' --output none"
Invoke-LoggedCommand "az deployment sub create --template-file './bicep/main.bicep' --parameters '$parametersFile' --location '$location' --name '$deploymentName' --output none"
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to deploy resource groups"
exit 1
}
}
finally {
Pop-Location
}
}