Skip to content

Commit

Permalink
Experimental commit for release action testing
Browse files Browse the repository at this point in the history
  • Loading branch information
sandreas committed Feb 1, 2022
1 parent 2881318 commit 31d6b31
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Release
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
env:
GITHUB_USER: 'sandreas'
PROJECT_NAME: 'Sandreas.Files'
PROJECT_PATH: 'Sandreas/Sandreas.csproj'
DOTNET_VERSION: '6.0.100'
DOTNET_FRAMEWORK: 'net6.0'
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Get version
id: version
uses: battila7/get-version-action@v2

- name: Extract release notes
run: |
git log --pretty=format:'%d %s' ${GITHUB_REF} | perl -pe 's| \(.*tag: v(\d+.\d+.\d+(-preview\d{3})?)(, .*?)*\)|\n## \1\n|g' > RELEASE-NOTES
- name: Build
run: dotnet build --configuration Release /p:Version=${{ steps.version.outputs.version-without-v }}

- name: Test
run: dotnet test --configuration Release /p:Version=${{ steps.version.outputs.version-without-v }} --no-build

- name: Pack
run: dotnet pack --configuration Release --include-symbols /p:Version=${{ steps.version.outputs.version-without-v }} --no-build --output .

- name: Push
run: dotnet nuget push ${PROJECT_NAME}.${VERSION}.nupkg --source https://nuget.pkg.github.com/${GITHUB_USER}/index.json --api-key ${GITHUB_TOKEN}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*/obj/
*/bin/
*/var/
!*/var/*.gitkeep
*/dist/
*.DotSettings.user
.idea/
16 changes: 16 additions & 0 deletions DotnetLibFiles.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sandreas", "Sandreas\Sandreas.csproj", "{C2865AE4-66C2-4B48-B119-CBA5FCEF0BB9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C2865AE4-66C2-4B48-B119-CBA5FCEF0BB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C2865AE4-66C2-4B48-B119-CBA5FCEF0BB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2865AE4-66C2-4B48-B119-CBA5FCEF0BB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2865AE4-66C2-4B48-B119-CBA5FCEF0BB9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
99 changes: 99 additions & 0 deletions Sandreas/Files/FileWalker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System.Collections;
using System.IO.Abstractions;

namespace Sandreas.Files;

public class FileWalker : IEnumerable<string>
{
private readonly FileSystem _fs;
private string _path = "";
private Func<string, Exception, FileWalkerBehaviour> _exceptionHandler;
private FileWalkerOptions _options = FileWalkerOptions.Default;

public FileWalker(FileSystem fs, Func<string, Exception, FileWalkerBehaviour>? exceptionHandler = null)
{
_fs = fs;
_exceptionHandler = exceptionHandler ?? ((_, _) => FileWalkerBehaviour.Default);
}

public bool IsDir(IFileInfo f)
{
return f.Attributes.HasFlag(FileAttributes.Directory);
}

public FileWalker Walk(string path)
{
_options &= ~FileWalkerOptions.Recursive;
_path = path;
return this;
}

public FileWalker WalkRecursive(string path)
{
_options |= FileWalkerOptions.Recursive;
_path = path;
return this;
}

public IEnumerable<IFileInfo> SelectFileInfo()
{
return SelectWithFileSystem((p, fs) => fs.FileInfo.FromFileName(p));
}
public IEnumerable<TReturn> SelectWithFileSystem<TReturn> (Func<string, IFileSystem, TReturn> func)
{
return this.Select(p => func(p,_fs));
}

public FileWalker Catch(Func<string, Exception, FileWalkerBehaviour> exceptionHandler)
{
_exceptionHandler = exceptionHandler;
return this;
}

IEnumerator<string> IEnumerable<string>.GetEnumerator()
{
var e = GetEnumerator();
while (e.MoveNext())
{
yield return (string)(e.Current ?? "");
}
}

public IEnumerator GetEnumerator()
{
var currentPath = _path;
var pending = new Stack<string>();
pending.Push(currentPath);
while (pending.Count != 0)
{
currentPath = pending.Pop();
IEnumerable<string> tmp;

try
{
tmp = _fs.Directory.EnumerateFiles(currentPath);
}
catch (Exception e)
{
if (_exceptionHandler(currentPath, e) == FileWalkerBehaviour.BreakOnException)
{
break;
}
continue;
}

yield return currentPath;

var dirs = _fs.Directory.EnumerateDirectories(currentPath).ToArray();
if (_options.HasFlag(FileWalkerOptions.Recursive))
{
dirs.AsParallel().ForAll(pending.Push);
}

foreach (var item in tmp.Concat(dirs))
{
yield return item;
}
}
}
}
8 changes: 8 additions & 0 deletions Sandreas/Files/FileWalkerBehaviour.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Sandreas.Files;

[Flags]
public enum FileWalkerBehaviour
{
Default = 0,
BreakOnException = 1 << 0
}
9 changes: 9 additions & 0 deletions Sandreas/Files/FileWalkerOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Sandreas.Files;


[Flags]
public enum FileWalkerOptions
{
Default = 1 << 0,
Recursive = 1 << 1,
}
23 changes: 23 additions & 0 deletions Sandreas/Sandreas.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>Sandreas.Files</PackageId>
<Authors>sandreas</Authors>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<RepositoryUrl>https://github.com/sandreas/DotnetLibFiles.git</RepositoryUrl>
<PackageProjectUrl>https://github.com/sandreas/DotnetLibFiles.git</PackageProjectUrl>
<PackageTags>files</PackageTags>
<Description>
This library contains helper classes for working with files
</Description>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.IO.Abstractions" Version="16.1.5" />
</ItemGroup>



</Project>
4 changes: 4 additions & 0 deletions Sandreas/build-pack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
dotnet pack --configuration Release --include-symbols

# dotnet nuget push *.nupkg -s https://api.nuget.org/v3/index.json -k "${NUGET_API_KEY}"

0 comments on commit 31d6b31

Please sign in to comment.