Skip to content

Commit

Permalink
migrating build scripts from Home repo (#2073)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyMothra authored Sep 25, 2020
1 parent a9d1ceb commit 507a2d7
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .scripts/release_GenerateReleaseMetadata.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Param(
)

# SUMMARY
# This script will inventory the nuget packages output by a build and create a metadata file.
# This script will inventory the nuget packages output by a build and create a metadata file (releaseMetaData.xml).
# This metadata file must be published with the NUPKGs when archived.
# This metadata file is used by the release infrastructure and informs it on how to publish NUPKGs.
# This script is included in Gated builds for troubleshooting.
Expand Down
70 changes: 70 additions & 0 deletions .scripts/release_MetaDataToCTI.ps1
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
102 changes: 102 additions & 0 deletions .scripts/release_MetaDataToReleaseNotes.ps1
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."
}

0 comments on commit 507a2d7

Please sign in to comment.