generated from im-open/composite-action-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
65 lines (59 loc) · 2.63 KB
/
action.yml
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
name: create-app-insights-annotation
description: An action to create an annotation in Azure App Insights flagging any event you like.
inputs:
subscriptionId:
description: 'The subscription ID where this annotation will be made. Used to build the App Insights ID.'
required: true
resourceGroupName:
description: 'The name of the Resource Group containing the App Insights resource. Used to build the App Insights ID.'
required: true
appInsightsResourceName:
description: 'The name of the Azure App Insights resource. Used to build the App Insights ID.'
required: true
releaseName:
description: 'The name to give the created release annotation.'
required: true
default: ${{ github.run_id }}
category:
description: 'The category of annotation.'
required: true
default: Deployment
customMetadata:
description: 'Comma-separated list of name-value pairs used to attach custom metadata to the annotation. For example: "ProjectName=My Project,DeployedBy=DA'
required: false
runs:
using: 'composite'
steps:
- name: create-annotation
shell: pwsh
run: |
$subscriptionId = "${{ inputs.subscriptionId }}"
$resourceGroupName = "${{ inputs.resourceGroupName }}"
$appInsightsResourceName = "${{ inputs.appInsightsResourceName }}"
$releaseName = "${{ inputs.releaseName }}"
$rawMetadataInput = "${{ inputs.customMetadata }}"
$metadataIsEmpty = [string]::IsNullOrEmpty($rawMetadataInput);
$properties = @{}
if ($metadataIsEmpty){
Write-Host "Custom Metadata is empty"
}
else {
Write-Host "Custom Metadata is NOT empty"
$nameValuePairs = $rawMetadataInput.Split(',');
Foreach($pair in $nameValuePairs) {
$pairParts = $pair.Split('=')
$properties.Add($pairParts[0], $pairParts[1])
}
}
$aiResourceId = "/subscriptions/$($subscriptionId)/resourceGroups/$($resourceGroupName)/providers/microsoft.insights/components/$($appInsightsResourceName)"
$annotation = @{
Id = [GUID]::NewGuid();
AnnotationName = $releaseName;
EventTime = (Get-Date).ToUniversalTime().GetDateTimeFormats("s")[0];
Category = "${{ inputs.category }}";
Properties = ConvertTo-Json $properties -Compress
}
$body = (ConvertTo-Json $annotation -Compress)
Write-Host "Request Body:"
Write-Host $body
az rest --method put --uri "$($aiResourceId)/Annotations?api-version=2015-05-01" --body "$($body)" --headers "Content-Type=application/json"