Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
snakefoot committed Apr 18, 2018
2 parents e74909e + 20354cc commit effb3df
Show file tree
Hide file tree
Showing 21 changed files with 217 additions and 25 deletions.
194 changes: 194 additions & 0 deletions GenerateReleaseMetadata.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
Param(
[Parameter(Mandatory=$true,HelpMessage="Path to Artifact files (nupkg):")]
[string]
$artifactsPath,
[Parameter(Mandatory=$true,HelpMessage="Path to Source files (changelog):")]
[string]
$sourcePath,
[Parameter(Mandatory=$false,HelpMessage="Path to save metadata:")]
[string]
$outPath
)

class PackageInfo {
[string]$Name
[string]$NuspecVersion
[string]$DllVersion
[string]$MyGetUri

PackageInfo([string]$name, [string]$nuspecVersion, [string]$dllVersion) {
$this.Name = $name
$this.NuspecVersion = $nuspecVersion
$this.DllVersion = $dllVersion

$mygetBasePath = "https://www.myget.org/feed/applicationinsights/package/nuget/{0}/{1}"
$this.MyGetUri = $mygetBasePath -f $name, $nuspecVersion
}
}

class ReleaseInfo {
[string]$ReleaseName
[string]$ReleaseVersion
[string]$NuspecVersion
[string]$FormattedReleaseName
[bool]$IsPreRelease
[string]$CommitId
[string]$ChangeLog
[PackageInfo[]]$Packages
}

Function Get-GitChangeset() {
# if running localy, use git command. for VSTS, probably better to use Build.SourceVersion
# Git command only works if this script executes in the repo's directory
[string]$commit = ""
try {
$commit = $(Build.SourceVersion)
} catch {
try {
$commit = git log -1 --format=%H
} catch {
$commit = "not found"
}
}

Write-Host "Git Commit: $commit"
return [string]$commit
}

function Get-NuspecVersionName ([string]$version) {
# get everything up to word "-build" (ex: "1.2.3-beta1-build1234 returns: "1.2.3-beta1")
# get everything (ex: "1.2.3-beta1 returns: "1.2.3-beta1")
# get everything (ex: "1.2.3 returns: "1.2.3")
$splitVersion = $version.split('-')
if($splitVersion.Length -gt 2 ) {
return $splitVersion[0]+"-"+$splitVersion[1]
} else {
return $version
}
}

function Invoke-UnZip([string]$zipfile, [string]$outpath) {
Write-Verbose "Unzip - source: $zipfile"
Write-Verbose "Unzip - target: $outpath"
Add-Type -assembly "system.io.compression.filesystem"
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
}

function Get-PackageInfoFromNupkg([string]$nupkgPath) {
$unzipPath = $nupkgPath+"_unzip"
$null = Invoke-UnZip $nupkgPath $unzipPath

$nuspecPath = Get-ChildItem -Path $unzipPath -Recurse -Filter *.nuspec | Select-Object -First 1
Write-Verbose ("Found Nuspec: " + $nuspecPath.FullName)
[xml]$nuspec = Get-Content $nuspecPath.FullName
$name = $nuspec.package.metadata.id
$nuspecVersion = $nuspec.package.metadata.version

$dllPath = Get-ChildItem -Path $unzipPath -Recurse -Filter *.dll | Select-Object -First 1
Write-Verbose ("Found Dll: " + $dllPath.FullName)
$dllVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($dllPath.FullName).FileVersion

return [PackageInfo]::new($name, $nuspecVersion, $dllVersion)
}

function Get-ReleaseMetaData ([string]$artifactsPath, [string]$sourcePath) {
$object = [ReleaseInfo]::new()
$object.CommitId = Get-GitChangeset
$object.Packages = $()

Get-ChildItem -Path $artifactsPath -Recurse -Filter *.nupkg -Exclude *.symbols.nupkg |
ForEach-Object { $object.Packages += Get-PackageInfoFromNupkg $_.FullName }

$object.NuspecVersion = $object.Packages[0].NuspecVersion
$object.ReleaseName = Get-NuspecVersionName($object.Packages[0].NuspecVersion)
$object.ReleaseVersion = $object.Packages[0].DllVersion

$object.FormattedReleaseName = "$($object.ReleaseName) ($($object.ReleaseVersion))"

$object.IsPreRelease = [bool]($object.ReleaseName -like "*beta*")

$object.ChangeLog = Get-ChangelogText $sourcePath $object.ReleaseName
return $object
}

Function Get-ChangelogText ([string]$sourcePath, [string]$versionName) {
$sb = [System.Text.StringBuilder]::new()
$saveLines = $false
$readFile = $true

$changelogPath = Get-ChildItem -Path $sourcePath -Recurse -Filter changelog.md | Select-Object -First 1
Write-Verbose "Changelog Found: $changelogPath"
Get-Content -Path $changelogPath.FullName | ForEach-Object {

if($readFile) {

if($saveLines) {
if($_ -like "##*") {
Write-Verbose "STOP at $_"
$readFile = $false
}

if($readFile) {
[void]$sb.AppendLine($_)
}
} else {
if(($_ -like "##*") -and ($_ -match $versionName)) {
$saveLines = $true
Write-Verbose "START at $_"
}
}
}

}
return $sb.ToString()
}

Function Save-ToXml([string]$outPath, [ReleaseInfo]$object) {
$outFilePath = Join-Path $outPath "releaseMetaData.xml"
$xmlWriter = [System.XMl.XmlTextWriter]::new($outFilePath, $Null)
$xmlWriter.Formatting = "Indented"
$xmlWriter.Indentation = 1
$XmlWriter.IndentChar = "`t"

# write the header
$xmlWriter.WriteStartDocument()

# create root node:
$xmlWriter.WriteStartElement("MetaData")

$XmlWriter.WriteElementString("ReleaseName", $object.ReleaseName)
$XmlWriter.WriteElementString("ReleaseVersion", $object.ReleaseVersion)
$XmlWriter.WriteElementString("FormattedReleaseName", $object.FormattedReleaseName)
$XmlWriter.WriteElementString("NuspecVersion", $object.NuspecVersion)
$XmlWriter.WriteElementString("IsPreRelease", $object.IsPreRelease)
$XmlWriter.WriteElementString("CommitId", $object.CommitId)

$XmlWriter.WriteElementString("ChangeLog", $object.ChangeLog)

$XmlWriter.WriteStartElement("Packages")
$object.Packages | ForEach-Object {
$XmlWriter.WriteStartElement("Package")
$XmlWriter.WriteElementString("Name", $_.Name)
$XmlWriter.WriteElementString("NuspecVersion", $_.NuspecVersion)
$XmlWriter.WriteElementString("DllVersion", $_.DllVersion)
$XmlWriter.WriteElementString("MyGetUri", $_.MyGetUri)
$XmlWriter.WriteEndElement()
}
$XmlWriter.WriteEndElement()

# close the root node:
$xmlWriter.WriteEndElement()

# finalize the document:
$xmlWriter.WriteEndDocument()
$xmlWriter.Flush()
$xmlWriter.Close()
}

# 1) GET META DATA FROM ARTIFACTS
$metaData = Get-ReleaseMetaData $artifactsPath $sourcePath
Write-Output $metaData
$metaData.Packages | ForEach-Object { Write-Output $_ }

# 2) SAVE
Save-ToXml $outPath $metaData
2 changes: 1 addition & 1 deletion GlobalStaticVersion.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<SemanticVersionMajor>2</SemanticVersionMajor>
<SemanticVersionMinor>6</SemanticVersionMinor>
<SemanticVersionPatch>0</SemanticVersionPatch>
<PreReleaseMilestone>beta2</PreReleaseMilestone>
<PreReleaseMilestone>beta3</PreReleaseMilestone>
<!--
Date when Semantic Version was changed.
Update for every public release.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@


<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta2" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta3" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion src/EtwCollector/EtwCollector.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<PackageReference Include="Microsoft.Diagnostics.Tracing.EventRegister" Version="1.1.28">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta2" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta3" />
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="1.0.41" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/EventSourceListener/EventSourceListener.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta2" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta3" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion src/Log4NetAppender/Log4NetAppender.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<PackageReference Include="Microsoft.Diagnostics.Tracing.EventRegister" Version="1.1.28">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta2" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta3" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
Expand Down
2 changes: 1 addition & 1 deletion src/NLogTarget/NLogTarget.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<PackageReference Include="Microsoft.Diagnostics.Tracing.EventRegister" Version="1.1.28">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta2" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta3" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
Expand Down
2 changes: 1 addition & 1 deletion src/TraceListener/TraceListener.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<PackageReference Include="Microsoft.Diagnostics.Tracing.EventRegister" Version="1.1.28">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta2" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta3" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.3'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta2" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta3" />
<PackageReference Include="Microbuild.Core" Version="0.2.0">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta2" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta3" />
<PackageReference Include="Microbuild.Core" Version="0.2.0">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta2" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta3" />
<PackageReference Include="Microbuild.Core" Version="0.2.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public void ValidateLoggingIsWorking()
[TestCategory("Log4NetAppender")]
public void TracesAreEnqueuedInChannel()
{
TelemetryConfiguration.Active.InstrumentationKey = this.adapterHelper.InstrumentationKey;
TelemetryConfiguration.Active.TelemetryChannel = this.adapterHelper.Channel;

ApplicationInsightsAppenderTests.InitializeLog4NetAIAdapter(string.Empty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta2" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta3" />
<PackageReference Include="Microbuild.Core" Version="0.2.0">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta2" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta3" />
<PackageReference Include="Microbuild.Core" Version="0.2.0">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion test/NLogTarget.Net45.Tests/NLogTarget.Net45.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta2" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta3" />
<PackageReference Include="Microbuild.Core" Version="0.2.0">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta2" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta3" />
<PackageReference Include="Microbuild.Core" Version="0.2.0">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
Expand Down
11 changes: 3 additions & 8 deletions test/Shared/AdapterHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace Microsoft.ApplicationInsights.Tracing.Tests
using System.Reflection;
using System.Threading;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.VisualStudio.TestTools.UnitTesting;

public class AdapterHelper : IDisposable
Expand All @@ -21,13 +20,15 @@ public class AdapterHelper : IDisposable
#if NET45 || NET46
private static readonly string ApplicationInsightsConfigFilePath =
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ApplicationInsights.config");
#else
private static readonly string ApplicationInsightsConfigFilePath =
Path.Combine(Path.GetDirectoryName(typeof(AdapterHelper).GetTypeInfo().Assembly.Location), "ApplicationInsights.config");
#endif

public AdapterHelper(string instrumentationKey = "F8474271-D231-45B6-8DD4-D344C309AE69")
{
this.InstrumentationKey = instrumentationKey;

#if NET45 || NET46
string configuration = string.Format(
@"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ApplicationInsights xmlns=""http://schemas.microsoft.com/ApplicationInsights/2013/Settings"">
Expand All @@ -36,10 +37,6 @@ public AdapterHelper(string instrumentationKey = "F8474271-D231-45B6-8DD4-D344C3
instrumentationKey);

File.WriteAllText(ApplicationInsightsConfigFilePath, configuration);
#else
TelemetryConfiguration.Active.InstrumentationKey = instrumentationKey;
#endif

this.Channel = new CustomTelemetryChannel();
}

Expand Down Expand Up @@ -85,12 +82,10 @@ private void Dispose(bool dispossing)
{
this.Channel.Dispose();

#if NET45 || NET46
if (File.Exists(ApplicationInsightsConfigFilePath))
{
File.Delete(ApplicationInsightsConfigFilePath);
}
#endif
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/Shared/ApplicationInsightsTraceListenerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public void TraceListenerInitializeTDoesNoThrowWhenInstrumentationKeyIsEmpty()
[TestCategory("TraceListener")]
public void TraceListenerWriteUsedApplicationInsightsConfigInstrumentationKeyWhenUnspecifiedInstrumentationKey()
{
TelemetryConfiguration.Active.InstrumentationKey = this.adapterHelper.InstrumentationKey;

// Changing the channel to Mock channel to verify
// the Telemetry event is assigned with the InstrumentationKey from configuration
TelemetryConfiguration.Active.TelemetryChannel = this.adapterHelper.Channel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta2" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta3" />
<PackageReference Include="Microbuild.Core" Version="0.2.0">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
Expand Down
Loading

0 comments on commit effb3df

Please sign in to comment.