Skip to content

Commit

Permalink
Merge branch 'main' into feature/deployment-jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
martinsmith1968 committed Aug 22, 2024
2 parents 74139c9 + 44dbe53 commit f5105c9
Show file tree
Hide file tree
Showing 46 changed files with 5,405 additions and 950 deletions.
18 changes: 15 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ csharp_style_expression_bodied_accessors = true:none
csharp_style_pattern_matching_over_is_with_cast_check = true : suggestion
csharp_style_pattern_matching_over_as_with_null_check = true : suggestion
csharp_style_inlined_variable_declaration = true : suggestion
csharp_style_throw_expression = true : suggestion
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true : suggestion

# Newline settings
Expand All @@ -97,7 +97,7 @@ csharp_indent_labels = flush
csharp_indent_switch_labels = true
csharp_new_line_between_query_expression_clauses = true
csharp_prefer_braces = true:silent
csharp_prefer_simple_default_expression = true : suggestion
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_deconstructed_variable_declaration = true : suggestion
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true
Expand All @@ -114,11 +114,13 @@ csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_style_pattern_local_over_anonymous_function = true : suggestion
csharp_prefer_simple_using_statement = true:suggestion
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_namespace_declarations = file_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent
csharp_style_prefer_primary_constructors = true:suggestion
csharp_style_prefer_null_check_over_type_check = true:suggestion


# XML and Config style settings:
Expand Down Expand Up @@ -196,3 +198,13 @@ dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion
dotnet_style_namespace_match_folder = true:suggestion
121 changes: 96 additions & 25 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
name: CI Build
run-name: CIBuild_${{ github.event_name }}_${{ github.ref_name }}_${{ github.run_number }}${{ github.run_attempt }}
run-name: CIBuild_${{ github.event_name }}_${{ github.ref_name }}_${{ github.run_number }}.${{ github.run_attempt }}

env:
PKG_MAJOR_VERSION: '1.1'
PROJECT_NAME: 'DNX.Extensions'
DOTNET_VERSION: 6.0.x
PKG_MAJOR_VERSION: 1.2
PROJECT_NAME: DNX.Extensions
DOTNET_VERSION: 8.0.x
NUGET_VERSION: 5.x
BUILD_CONFIG: Release
BUILD_PLATFORM: Any CPU
PACK_PARAMETERS: ''
COVERAGE_WARNING_THRESHOLD: 60
COVERAGE_ERROR_THRESHOLD: 80
NUGET_OUTPUT_FOLDER: nupkgs
BRANCH_PREFIX_RELEASE_CANDIDATE: rc/
BRANCH_PREFIX_PUBLISH_CANDIDATE: beta/

on:
push:
branches:
- main
- 'feature/**'
- 'task/**'
- 'spike/**'
- rc/**
- feature/**
- task/**
- spike/**

pull_request:
branches:
Expand All @@ -26,6 +31,8 @@ on:
workflow_dispatch:

jobs:
##########################################################
## Pipeline Configuration and Setup
setup:
name: Setup Pipeline

Expand All @@ -39,7 +46,7 @@ jobs:
- name: Set Package Suffix
id: package_suffix
run: |
branch='${{ github.ref }}'
branch="${{ github.ref }}"
package_suffix=''
if [ "$branch" != "refs/heads/main" ]
Expand All @@ -49,6 +56,32 @@ jobs:
echo "package_suffix=${package_suffix}" >> $GITHUB_ENV
- name: Determing GitHub Releasing
id: should_release
run: |
should_release=false
release_is_draft=false
release_is_prerelease=false
if [ "${{ github.ref }}" == 'refs/heads/main' ]
then
should_release=true
elif [[ "${{ github.ref }}" == refs/heads/${{ env.BRANCH_PREFIX_RELEASE_CANDIDATE }}* ]]
then
should_release=true
release_is_draft=true
if [ "${{ github.event_name }}" == "pull_request" ]
then
release_is_draft=false
release_is_prerelease=true
fi
fi
echo "should_release=${should_release}" >> $GITHUB_ENV
echo "release_is_draft=${release_is_draft}" >> $GITHUB_ENV
echo "release_is_prerelease=${release_is_prerelease}" >> $GITHUB_ENV
- name: Determine package publishing
id: should_publish
run: |
Expand All @@ -57,7 +90,10 @@ jobs:
if [ "${{ github.event_name }}" == "pull_request" ]
then
should_publish=true
elif [ "${{ github.ref }}" == 'refs/heads/main' ]
elif [ "${{ github.ref }}" == "refs/heads/main" ]
then
should_publish=true
elif [[ "${{ github.ref }}" == refs/heads/${{ env.BRANCH_PREFIX_PUBLISH_CANDIDATE }}* ]]
then
should_publish=true
fi
Expand All @@ -76,14 +112,21 @@ jobs:
id: package_version
run: echo "package_version=${{ env.assembly_version }}${{ env.package_suffix }}" >> $GITHUB_ENV

- name: Show Configuration
id: show_configuration
run: env | sort

outputs:
assembly_version: ${{ env.assembly_version }}
product_version: ${{ env.product_version }}
package_version: ${{ env.package_version }}
should_publish: ${{ env.should_publish }}
should_release: ${{ env.should_release }}
release_is_draft: ${{ env.release_is_draft }}
release_is_prerelease: ${{ env.release_is_prerelease }}

##########################################################
## Bulid DotNet projects
## Build DotNet projects
build:
name: Build .NET

Expand All @@ -93,24 +136,36 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install .NET SDK
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Restore NuGet packages
run: dotnet restore

- name: Build
run: dotnet build --configuration ${{ env.BUILD_CONFIG }} /p:"Platform=${{ env.BUILD_PLATFORM }}" /p:"Version=${{ needs.setup.outputs.product_version }}" /p:"AssemblyVersion=${{ needs.setup.outputs.assembly_version }}" --no-restore
run: dotnet build --no-restore --configuration ${{ env.BUILD_CONFIG }} /p:"Platform=${{ env.BUILD_PLATFORM }}" /p:"Version=${{ needs.setup.outputs.product_version }}" /p:"AssemblyVersion=${{ needs.setup.outputs.assembly_version }}"

- name: Test
run: dotnet test --configuration ${{ env.BUILD_CONFIG }} --no-restore --no-build --verbosity normal --collect:"XPlat Code Coverage"
run: dotnet test --no-restore --no-build --configuration ${{ env.BUILD_CONFIG }} --verbosity normal --collect:"XPlat Code Coverage" --logger:trx;LogFileName=TestOutput.trx

- name: Test Results Summary
uses: bibipkins/[email protected]
if: success() || failure()
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-title: 'Unit Test Results'
results-path: "**/*.trx"
coverage-type: cobertura
#coverage-path: "**/coverage.cobertura.xml"
#coverage-threshold: ${{ env.COVERAGE_WARNING_THRESHOLD }}

- name: Code Coverage Report
uses: irongut/[email protected]
if: success() || failure()
with:
filename: "**/coverage.cobertura.xml"
badge: true
Expand All @@ -120,7 +175,10 @@ jobs:
hide_complexity: false
indicators: true
output: both
thresholds: '60 80'
thresholds: '${{ env.COVERAGE_ERROR_THRESHOLD }} ${{ env.COVERAGE_WARNING_THRESHOLD }}'

- name: Output Code Coverage
run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY

- name: Pull Request - Add Coverage Comment
uses: marocchino/sticky-pull-request-comment@v2
Expand All @@ -133,14 +191,14 @@ jobs:
run: dotnet pack --configuration ${{ env.BUILD_CONFIG }} /p:"Platform=${{ env.BUILD_PLATFORM }}" /p:"PackageVersion=${{ needs.setup.outputs.package_version }}" --no-restore --output "${{ env.NUGET_OUTPUT_FOLDER }}"

- name: Upload Build Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: build_output
path: "**/${{ env.PROJECT_NAME }}/bin/${{ env.BUILD_CONFIG }}/**"
if-no-files-found: error

- name: Upload NuGet Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: nuget_output
path: "${{ env.NUGET_OUTPUT_FOLDER }}/**"
Expand All @@ -150,19 +208,26 @@ jobs:
## Generate a Release and Tag in git
release:
name: Create GitHub Release
if: github.ref == 'refs/heads/main' && success()
if: needs.setup.outputs.should_release == 'true'

needs: [setup, build]
needs:
- setup
- build

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- uses: actions/download-artifact@v4
with:
name: nuget_output
path: nuget

- name: Build Changelog
id: build_changelog
uses: mikepenz/release-changelog-builder-action@v3.4.0
uses: mikepenz/release-changelog-builder-action@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -172,9 +237,13 @@ jobs:
tag: v${{ needs.setup.outputs.assembly_version }}
name: Release ${{ needs.setup.outputs.assembly_version }}
body: ${{ steps.build_changelog.outputs.changelog }}
draft: ${{ needs.setup.outputs.release_is_draft }}
prerelease: ${{ needs.setup.outputs.release_is_prerelease }}
removeArtifacts: true
artifacts: '**/*.nupkg'

- name: Tag git
uses: pkgdeps/git-tag-action@v2.0.5
uses: pkgdeps/git-tag-action@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
github_repo: ${{ github.repository }}
Expand All @@ -188,20 +257,22 @@ jobs:
name: Publish to NuGet
if: needs.setup.outputs.should_publish == 'true'

needs: [setup, build, release]
needs:
- setup
- build

runs-on: ubuntu-latest

steps:
- name: Install NuGet
uses: NuGet/setup-nuget@v1.1.1
uses: NuGet/setup-nuget@v2
with:
nuget-api-key: ${{ secrets.NUGET_API_KEY }}
nuget-version: ${{ env.NUGET_VERSION }}

- name: Download NuGet Output
id: download_nuget
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: nuget_output
path: ${{ env.NUGET_OUTPUT_FOLDER }}
Expand Down
45 changes: 45 additions & 0 deletions src/DNX.Extensions/Arrays/ArrayExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;

#pragma warning disable 1591

namespace DNX.Extensions.Arrays;

/// <summary>
/// Array Extensions
/// </summary>
public static class ArrayExtensions
{
public static bool IsNullOrEmpty(this Array input)
{
return input == null || input.Length == 0;
}

public static T[] PadLeft<T>(this T[] input, int length)
{
var paddedArray = new T[length];
var startIdx = length - input.Length;
if (length >= input.Length)
{
Array.Copy(input, 0, paddedArray, startIdx, input.Length);
}
else
{
Array.Copy(input, Math.Abs(startIdx), paddedArray, 0, length);
}

return paddedArray;
}

public static T[] ShiftLeft<T>(this T[] input)
{
if (input == null)
{
return new T[0];
}

var shiftedArray = new T[input.Length];
Array.Copy(input, 1, shiftedArray, 0, input.Length - 1);

return shiftedArray;
}
}
32 changes: 32 additions & 0 deletions src/DNX.Extensions/Arrays/ByteArrayExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Text;

namespace DNX.Extensions.Arrays;

/// <summary>
/// Byte Array Extensions
/// </summary>
public static class ByteArrayExtensions
{
//private static string Base62CodingSpace = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

/// <summary>
/// Converts A byte array into an ASCII string
/// </summary>
/// <param name="input">The byte[] to turn into the string</param>
public static string GetAsciiString(this byte[] input)
{
return Encoding.ASCII.GetString(input);
}

/// <summary>
/// Converts A byte array into an hex string
/// </summary>
/// <param name="input">The byte[] to turn into the string</param>
public static string ToHexString(this byte[] input)
{
var hex = new StringBuilder(input.Length * 2);
foreach (var b in input)
hex.AppendFormat("{0:x2}", b);
return hex.ToString();
}
}
Loading

0 comments on commit f5105c9

Please sign in to comment.