Skip to content

Commit

Permalink
Add support for a single file, add unit-tests and add azure pipelines…
Browse files Browse the repository at this point in the history
… yaml (#2)

* tests

* .

* blob

* 0

* .

* opencover

* readme

* remove zip code
  • Loading branch information
StefH committed May 4, 2020
1 parent 0a00205 commit ca87308
Show file tree
Hide file tree
Showing 21 changed files with 1,836 additions and 16 deletions.
6 changes: 1 addition & 5 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</PropertyGroup>

<PropertyGroup>
<VersionPrefix>0.1.0</VersionPrefix>
<VersionPrefix>0.2.0</VersionPrefix>
<Copyright>Copyright © 2020 Stef Heyenrath</Copyright>
<Authors>Stef Heyenrath</Authors>
<PackageReleaseNotes>See CHANGELOG.md</PackageReleaseNotes>
Expand All @@ -19,10 +19,6 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
<None Include="../../resources/icon.png" Pack="true" PackagePath=""/>
</ItemGroup>

<Choose>
<!-- The environment variable `Prerelease` is set in the azure-pipelines.yml file. -->
<When Condition=" '$(Prerelease)' != '' ">
Expand Down
2 changes: 1 addition & 1 deletion GitHubReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
https://github.com/StefH/GitHubReleaseNotes

GitHubReleaseNotes.exe --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc --version 0.1.0
GitHubReleaseNotes.exe --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc --version 0.2.0
11 changes: 11 additions & 0 deletions Pulumi.Azure.Extensions Solution.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{84
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{01DFE66D-E850-4ADC-A0FC-A3A13B896CDA}"
ProjectSection(SolutionItems) = preProject
azure-pipeline-ci.yml = azure-pipeline-ci.yml
azure-pipelines-nuget.yml = azure-pipelines-nuget.yml
CHANGELOG.md = CHANGELOG.md
Directory.Build.props = Directory.Build.props
GitHubReleaseNotes.txt = GitHubReleaseNotes.txt
Expand All @@ -17,6 +19,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pulumi.Azure.Extensions", "src\Pulumi.Azure.Extensions\Pulumi.Azure.Extensions.csproj", "{C7F2E3E7-05CE-4409-AC94-A0557B5B8C13}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{239006F3-2FBF-4B5F-A369-B86B7FD40CF9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pulumi.Azure.Extensions.Tests", "tests\Pulumi.Azure.Extensions.Tests\Pulumi.Azure.Extensions.Tests.csproj", "{2267C0C9-D8A1-4921-BC04-ADC7A39B73CD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -27,12 +33,17 @@ Global
{C7F2E3E7-05CE-4409-AC94-A0557B5B8C13}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C7F2E3E7-05CE-4409-AC94-A0557B5B8C13}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C7F2E3E7-05CE-4409-AC94-A0557B5B8C13}.Release|Any CPU.Build.0 = Release|Any CPU
{2267C0C9-D8A1-4921-BC04-ADC7A39B73CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2267C0C9-D8A1-4921-BC04-ADC7A39B73CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2267C0C9-D8A1-4921-BC04-ADC7A39B73CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2267C0C9-D8A1-4921-BC04-ADC7A39B73CD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{C7F2E3E7-05CE-4409-AC94-A0557B5B8C13} = {BA564CB5-1908-41F9-A32A-3535BBE0E8C6}
{2267C0C9-D8A1-4921-BC04-ADC7A39B73CD} = {239006F3-2FBF-4B5F-A369-B86B7FD40CF9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FC1E6DF8-EC39-439B-ABF0-EE3786C5C0F6}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Pulumi.Azure.Extensions
[![NuGet](https://buildstats.info/nuget/Pulumi.Azure.Extensions)](https://www.nuget.org/packages/Pulumi.Azure.Extensions)
[![codecov](https://codecov.io/gh/StefH/Pulumi.Azure.Extensions/branch/master/graph/badge.svg)](https://codecov.io/gh/StefH/Pulumi.Azure.Extensions)

Additional extensions for Microsoft Azure resources with [Pulumi Azure](https://github.com/pulumi/pulumi-azure).

Expand Down
69 changes: 69 additions & 0 deletions azure-pipeline-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
pool:
vmImage: 'windows-2019'

variables:
Prerelease: 'ci'
buildId: "1$(Build.BuildId)"
buildProjects: '**/src/**/*.csproj'

steps:
# Print buildId
- script: |
echo "BuildId = $(buildId)"
displayName: 'Print buildId'

# Install Tools (SonarScanner)
- script: |
dotnet tool install --global dotnet-sonarscanner
displayName: Install Tools (SonarScanner)

# Build source, tests and run tests with coverage
- script: |
dotnet test ./tests/Pulumi.Azure.Extensions.Tests/Pulumi.Azure.Extensions.Tests.csproj --configuration Debug --logger trx /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
displayName: 'Build source, tests and run tests with coverage'

# Upload coverage to codecov.io
- script: |
%USERPROFILE%\.nuget\packages\codecov\1.10.0\tools\codecov.exe -f "./tests/Pulumi.Azure.Extensions.Tests/coverage.opencover.xml" -t $(CODECOV_TOKEN)
displayName: Upload coverage to codecov.io

# https://github.com/microsoft/azure-pipelines-tasks/issues/12212
- task: PublishTestResults@2
condition: and(succeeded(), eq(variables['PUBLISH_TESTRESULTS'], 'yes'))
inputs:
testRunner: VSTest
testResultsFiles: '**/*.trx'

# Based on https://whereslou.com/2018/09/versioning-and-publishing-nuget-packages-automatically-using-azure-devops-pipelines/
- task: DotNetCoreCLI@2
displayName: Build Release
inputs:
command: 'build'
arguments: /p:Configuration=Release # https://github.com/MicrosoftDocs/vsts-docs/issues/1976
projects: $(buildProjects)

- task: DotNetCoreCLI@2
displayName: Pack
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
inputs:
command: pack
configuration: 'Release'
packagesToPack: $(buildProjects)
nobuild: true
packDirectory: '$(Build.ArtifactStagingDirectory)/packages'
verbosityPack: 'normal'

- task: PublishBuildArtifacts@1
displayName: Publish Artifacts
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'

# https://github.com/NuGet/Home/issues/8148
- task: DotNetCoreCLI@2
displayName: Push to MyGet
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
inputs:
command: custom
custom: nuget
arguments: push $(Build.ArtifactStagingDirectory)\packages\*.nupkg -n true -s https://www.myget.org/F/pulumi-azure-extensions/api/v3/index.json -k $(MyGetKey)
34 changes: 34 additions & 0 deletions azure-pipelines-nuget.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4

trigger:
- master

pool:
vmImage: 'windows-latest'

variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'

- task: VSBuild@1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'

- task: VSTest@2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
9 changes: 9 additions & 0 deletions src/Pulumi.Azure.Extensions/Pulumi.Azure.Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
<ProjectGuid>{C7F2E3E7-05CE-4409-AC94-A0557B5B8C13}</ProjectGuid>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Utils\TempFolder.cs" />
<Compile Remove="Utils\ZipFileUtilities.cs" />
</ItemGroup>

<ItemGroup>
<None Include="../../resources/icon.png" Pack="true" PackagePath="" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Pulumi.Azure" Version="3.0.0" />
</ItemGroup>
Expand Down
25 changes: 15 additions & 10 deletions src/Pulumi.Azure.Extensions/Storage/BlobCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ namespace Pulumi.Azure.Extensions.Storage
{
public sealed class BlobCollectionArgs : ResourceArgs
{
/// <summary>
/// An absolute path to a folder on the local file system.
/// </summary>
public string Source { get; set; }

/// <summary>
/// The access tier of the storage blob. Possible values are `Archive`, `Cool` and `Hot`.
/// </summary>
Expand All @@ -26,6 +21,11 @@ public sealed class BlobCollectionArgs : ResourceArgs
[Input("parallelism", false, false)]
public Input<int> Parallelism { get; set; }

/// <summary>
/// An absolute path to a folder on the local file system.
/// </summary>
public string Source { get; set; }

/// <summary>
/// Specifies the storage account in which to create the storage container.
/// Changing this forces a new resource to be created.
Expand Down Expand Up @@ -74,7 +74,8 @@ public sealed class BlobCollection : ComponentResource
throw new ArgumentNullException(nameof(args.Source));
}

foreach (var (fileInfo, blobName) in GetAllFiles(args.Source))
var validFiles = GetAllFiles(args.Source).Where(f => f.fileInfo.Length > 0); // https://github.com/pulumi/pulumi-azure/issues/544
foreach (var (fileInfo, blobName) in validFiles)
{
var blobArgs = new BlobArgs
{
Expand All @@ -99,6 +100,12 @@ public sealed class BlobCollection : ComponentResource

private static IEnumerable<(FileInfo fileInfo, string blobName)> GetAllFiles(string source)
{
var fileInfo = new FileInfo(source);
if (fileInfo.Exists)
{
return new (FileInfo fileInfo, string blobName)[] { (fileInfo, fileInfo.Name) };
}

if (Directory.Exists(source))
{
int sourceFolderLength = source.Length + 1;
Expand All @@ -108,12 +115,10 @@ private static IEnumerable<(FileInfo fileInfo, string blobName)> GetAllFiles(str
(
new FileInfo(path),
path.Remove(0, sourceFolderLength).Replace(Path.PathSeparator, '/') // Make the blobName Azure Storage compatible
))
.Where(file => file.Item1.Length > 0) // https://github.com/pulumi/pulumi-azure/issues/544
;
));
}

throw new NotSupportedException("The source provided must be a folder.");
throw new NotSupportedException("The source provided must be an existing file or folder.");
}
}
}
120 changes: 120 additions & 0 deletions src/Pulumi.Azure.Extensions/Utils/TempFolder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
using System;
using System.IO;

namespace Pulumi.Azure.Extensions.Utils
{
public sealed class TempFolder : IDisposable
{
private readonly bool _isTemp;

public string Path { get; }

public TempFolder(string path, bool isTemp)
{
_isTemp = isTemp;

if (isTemp)
{
Path = System.IO.Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid().ToString()); ;
Clear(true);
Create(true);
}
else
{
Path = path;
}
}

private void Create(bool isTemp)
{
if (!isTemp)
{
return;
}

try
{
if (!Directory.Exists(Path))
{
Directory.CreateDirectory(Path);
}
}
catch (IOException)
{
}
}

private void Clear(bool isTemp)
{
if (!isTemp)
{
return;
}

try
{
if (Directory.Exists(Path))
{
Directory.Delete(Path, true);
}
}
catch (IOException)
{
}
}

/// <summary>
/// An indicator whether this object is being actively disposed or not.
/// </summary>
private bool _disposed;

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Releases managed resources upon dispose.
/// </summary>
/// <remarks>
/// All managed resources must be released in this
/// method, so after disposing this object no other
/// object is being referenced by it anymore.
/// </remarks>
private void ReleaseManagedResources()
{
Clear(_isTemp);
}

/// <summary>
/// Releases unmanaged resources upon dispose.
/// </summary>
/// <remarks>
/// All unmanaged resources must be released in this
/// method, so after disposing this object no other
/// object is beeing referenced by it anymore.
/// </remarks>
private void ReleaseUnmanagedResources()
{
}

private void Dispose(bool disposing)
{
if (!_disposed)
{
/* Release unmanaged resources */
ReleaseUnmanagedResources();

if (disposing)
{
/* Release managed resources */
ReleaseManagedResources();
}

/* Set indicator that this object is disposed */
_disposed = true;
}
}
}
}
Loading

0 comments on commit ca87308

Please sign in to comment.