-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrating build scripts from Home repo (#2073)
- Loading branch information
1 parent
a9d1ceb
commit 507a2d7
Showing
3 changed files
with
173 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
Param( | ||
[Parameter(Mandatory=$true,HelpMessage="Path to releaseMetaData.xml")] | ||
[string] | ||
$metadataPath | ||
) | ||
|
||
# SUMMARY | ||
# This script will parse a metadata file (releaseMetaData.xml) and generate and generate an email to send to our testing team. | ||
# The metadata can be used to construct paths to the newly uploaded nuget packages in myget. | ||
|
||
# DEVELOPER notes | ||
# In the release definition, set metadataPath = "$(SYSTEM.ARTIFACTSDIRECTORY)"; | ||
# This is a Work In Progress: I haven't been able to find a build task that can send emails. | ||
# Instead, have to settle for generating the email template. | ||
|
||
|
||
function Send-CtiEmail([string]$emailBody) { | ||
#TODO | ||
} | ||
|
||
|
||
if($metadataPath -notlike "releaseMetaData.xml") { | ||
Write-Verbose "'releaseMetaData.xml' not part of MetaDataPath: $metadataPath" | ||
Write-Verbose "Searching..." | ||
#assume this is Artifact Directory and find the required file | ||
$items = Get-ChildItem -Path $metadataPath -Recurse -Filter "releaseMetaData.xml" | ||
$items | ForEach-Object { Write-Verbose "Found: $($_.FullName)" } | ||
$metadataPath = $items[0].FullName | ||
} | ||
Write-Verbose "MetaDataPath: $metadataPath" | ||
[xml]$metaData = Get-Content $metadataPath | ||
|
||
# build email | ||
# $sb = [System.Text.StringBuilder]::new(); | ||
# [void]$sb.AppendFormat("CTI Test of {0} {1}", "Application Insights SDKs", $metaData.MetaData.ReleaseName); | ||
# [void]$sb.AppendLine("<br/>"); | ||
# [void]$sb.AppendLine("<br/>Requesting a CTI Test of the following SDKs:"); | ||
# [void]$sb.AppendLine("<br/>"); | ||
# [void]$sb.AppendLine("<br/><ul>"); | ||
# foreach( $package in $metaData.MetaData.Packages.Package) { | ||
# [void]$sb.AppendLine([string]::Format("<li>{0} {1}</li>", $package.Name, $package.MyGetUri)); | ||
# } | ||
# [void]$sb.AppendLine("</ul><br/>"); | ||
# [void]$sb.AppendLine("<br/>"); | ||
# [void]$sb.AppendFormat("<br/>If there are any issues, please reach out to {0}", "_NAME_"); | ||
# $emailBody = $sb.ToString() | ||
|
||
# Write-Output $emailBody | ||
|
||
# Send-CtiEmail $emailBody | ||
|
||
|
||
|
||
|
||
# build email text | ||
$sb = [System.Text.StringBuilder]::new(); | ||
[void]$sb.AppendFormat("CTI Test of {0} {1}", "Application Insights SDKs", $metaData.MetaData.ReleaseName); | ||
[void]$sb.AppendLine(""); | ||
[void]$sb.AppendLine("Requesting a CTI Test of the following SDKs:"); | ||
[void]$sb.AppendLine(""); | ||
[void]$sb.AppendLine(""); | ||
foreach( $package in $metaData.MetaData.Packages.Package) { | ||
[void]$sb.AppendLine([string]::Format("{0} {1}", $package.Name, $package.MyGetUri)); | ||
} | ||
[void]$sb.AppendLine(""); | ||
[void]$sb.AppendLine(""); | ||
[void]$sb.AppendFormat("If there are any issues, please reach out to {0}", "_NAME_"); | ||
$emailBody = $sb.ToString() | ||
|
||
Write-Output $emailBody |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
Param( | ||
[Parameter(Mandatory=$true,HelpMessage="Path to releaseMetaData.xml")] | ||
[string] | ||
$metadataPath, | ||
|
||
[Parameter(Mandatory=$true,HelpMessage="Github Repo Name")] | ||
[string] | ||
$gitHubRepository, | ||
|
||
[Parameter(Mandatory=$true,HelpMessage="Github Username with Write permissions")] | ||
[string] | ||
$gitHubUsername, | ||
|
||
[Parameter(Mandatory=$true,HelpMessage="Github User's personal api token (https://github.com/blog/1509-personal-api-tokens)")] | ||
[string] | ||
$gitHubApiKey | ||
) | ||
|
||
# SUMMARY | ||
# This script will parse a metadata file (releaseMetaData.xml) and generate the release notes. | ||
# The metadata contains a copy of the relevant changelog as well as the commit id. | ||
# The commit id is required to create a release tag in github. | ||
|
||
# DEVELOPER notes | ||
# In the release definition, set metadataPath = "$(SYSTEM.ARTIFACTSDIRECTORY)"; | ||
|
||
|
||
function Push-Github { | ||
#https://developer.github.com/v3/repos/releases/#create-a-release | ||
Param ( | ||
[string]$tagName, | ||
[string]$releaseName, | ||
# The Commit SHA for corresponding to this release | ||
[string]$commitId, | ||
# The notes to accompany this release, uses the commit message in this case | ||
[string]$releaseNotes, | ||
# The github username | ||
[string]$gitHubUsername, | ||
# The github repository name | ||
[string]$gitHubRepository, | ||
# The github API key (https://github.com/blog/1509-personal-api-tokens) | ||
[string]$gitHubApiKey, | ||
# Set to true to mark this as a pre-release version | ||
[bool]$preRelease = $TRUE, | ||
# Set to true to mark this as a draft release (not visible to users) | ||
[bool]$draft = $FALSE | ||
) | ||
|
||
$releaseData = @{ | ||
tag_name = $tagName; | ||
target_commitish = $commitId; | ||
name = $releaseName; | ||
body = $releaseNotes; | ||
draft = $draft; | ||
prerelease = $preRelease; | ||
} | ||
|
||
$authPair = "$($gitHubUsername):$($gitHubApiKey)" | ||
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($authPair)); | ||
$basicAuthValue = "Basic $encodedCreds" | ||
|
||
$releaseCmd = @{ | ||
Uri = "https://api.github.com/repos/$gitHubRepository/releases"; | ||
Method = 'POST'; | ||
Headers = @{ | ||
Authorization = $basicAuthValue | ||
} | ||
ContentType = 'application/json'; | ||
Body = (ConvertTo-Json $releaseData -Compress) | ||
} | ||
|
||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 | ||
Invoke-RestMethod @releaseCmd | ||
} | ||
|
||
|
||
|
||
if($metadataPath -notlike "releaseMetaData.xml") { | ||
Write-Verbose "'releaseMetaData.xml' not part of MetaDataPath: $metadataPath" | ||
Write-Verbose "Searching..." | ||
#assume this is Artifact Directory and find the required file | ||
$items = Get-ChildItem -Path $metadataPath -Recurse -Filter "releaseMetaData.xml" | ||
$items | ForEach-Object { Write-Verbose "Found: $($_.FullName)" } | ||
$metadataPath = $items[0].FullName | ||
} | ||
Write-Verbose "MetaDataPath: $metadataPath" | ||
|
||
if (Test-Path $metadataPath) { | ||
|
||
[xml]$metaData = Get-Content $metadataPath | ||
|
||
$commitId = $metaData.MetaData.CommitId; | ||
$tagName = $metaData.MetaData.ReleaseName; | ||
$releaseName = $metaData.MetaData.FormattedReleaseName; | ||
$releaseNotes = $metaData.MetaData.ChangeLog; | ||
$isPreRelease = [System.Convert]::ToBoolean($metaData.MetaData.isPreRelease); | ||
|
||
Push-Github -tagName $tagName -releaseName $releaseName -commitId $commitId -releaseNotes $releaseNotes -gitHubUsername $gitHubUsername -gitHubRepository $gitHubRepository -gitHubApiKey $gitHubApiKey -preRelease $isPreRelease; | ||
|
||
} else { | ||
Write-Error "MetaData Not Found." | ||
} |