Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub actions #35

Merged
merged 13 commits into from
May 27, 2024
53 changes: 53 additions & 0 deletions .github/workflows/buildtest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: buildtest
run-name: build and test

on:
workflow_dispatch: # Allow running the workflow manually from the GitHub UI
push:
branches:
- '*' # Run the workflow when pushing to all branches

jobs:
build:
strategy:
matrix:
configuration: [Debug, Release]

runs-on: windows-latest # For a list of available runner types, refer to
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on

env:
Project_Path: ValueInjecter\ValueInjecter.csproj
Test_Project_Path: Tests\Tests.csproj

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

# Install the .NET Core workload
- name: Install .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v2

#dotnet build .\ValueInjecter\ValueInjecter.csproj
- name: build
run: dotnet build ${{ env.Project_Path }} /p:Configuration=${{ env.Configuration }}
env:
Configuration: ${{ matrix.configuration }}

# Execute all unit tests in the solution
- name: Execute unit tests
run: dotnet test ${{ env.Test_Project_Path }}

# Restore the application to populate the obj folder with RuntimeIdentifiers
- name: Restore the application
run: msbuild ${{ env.Project_Path }} /t:Restore /p:Configuration=${{ env.Configuration }}
env:
Configuration: ${{ matrix.configuration }}
93 changes: 93 additions & 0 deletions .github/workflows/publish-nuget.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json

name: publish
on:
workflow_dispatch: # Allow running the workflow manually from the GitHub UI
push:
branches:
- '*' # Run the workflow when pushing to all branches
pull_request:
branches:
- '*' # Run the workflow for all pull requests
release:
types:
- published # Run the workflow when a new GitHub release is published

env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true
NuGetDirectory: ${{ github.workspace}}/nuget

defaults:
run:
shell: pwsh

jobs:
create_nuget:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Get all history to allow automatic versioning using MinVer

# Install the .NET SDK indicated in the global.json file
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

- name: Restore NuGet packages
run: dotnet restore ./ValueInjecter/ValueInjecter.csproj

# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v2

- name: Build libs
run: msbuild .\ValueInjecter\ValueInjecter.csproj /p:Configuration=Release

# Create the NuGet package in the folder from the environment variable NuGetDirectory
- run: dotnet pack .\ValueInjecter\ValueInjecter.csproj --configuration Release --output ${{ env.NuGetDirectory }}

# Publish the NuGet package as an artifact, so they can be used in the following jobs
- uses: actions/upload-artifact@v4
with:
name: nuget
if-no-files-found: error
path: ${{ env.NuGetDirectory }}/*.nupkg

run_test:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
- name: Run tests
run: dotnet test .\Tests\Tests.csproj --configuration Release

deploy:
# Publish only when creating a GitHub Release
# https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository
# You can update this logic if you want to manage releases differently
if: github.event_name == 'release'
runs-on: windows-latest
needs: [ run_test ]
steps:
# Download the NuGet package created in the previous job
- uses: actions/download-artifact@v4
with:
name: nuget
path: ${{ env.NuGetDirectory }}

# Install the .NET SDK indicated in the global.json file
- name: Setup .NET Core
uses: actions/setup-dotnet@v4

# Publish all NuGet packages to NuGet.org
# Use --skip-duplicate to prevent errors if a package with the same version already exists.
# If you retry a failed workflow, already published packages will be skipped without error.
- name: Publish NuGet package
run: |
foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) {
dotnet nuget push $file --api-key "${{ secrets.NUGET_API_KEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[![buildtest](https://github.com/omuleanu/ValueInjecter/actions/workflows/buildtest.yml/badge.svg)](https://github.com/omuleanu/ValueInjecter/actions/workflows/buildtest.yml) ![NuGet Downloads](https://img.shields.io/nuget/dt/ValueInjecter)

Get it via nuget **[ValueInjecter](https://www.nuget.org/packages/ValueInjecter/)**

ValueInjecter automatically maps and copies property values from one object to another.

This is very useful when working with Entity Framework (EF) proxy objects.

#### Usage
```
var customerInput = Mapper.Map<CustomerInput>(customer);
Expand Down
6 changes: 6 additions & 0 deletions ValueInjecter/Injections/IValueInjection.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
namespace Omu.ValueInjecter.Injections
{
/// <summary>
/// value injection
/// </summary>
public interface IValueInjection
{
/// <summary>
/// map source object properties to target object properties
/// </summary>
object Map(object source, object target);
}
}
11 changes: 10 additions & 1 deletion ValueInjecter/Injections/KnownSourceInjection.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
namespace Omu.ValueInjecter.Injections
{
/// <summary>
/// <inheritdoc/>
/// </summary>
public abstract class KnownSourceInjection<TSource> : IValueInjection
{
/// <summary>
/// <inheritdoc/>
/// </summary>
public object Map(object source, object target)
{
Inject((TSource) source, target);
return target;
}


/// <summary>
/// map TSource object to object target
/// </summary>
protected abstract void Inject(TSource source, object target);
}
}
7 changes: 6 additions & 1 deletion ValueInjecter/Injections/ValueInjection.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
namespace Omu.ValueInjecter.Injections
{
{
/// <inheritdoc/>
public abstract class ValueInjection : IValueInjection
{
/// <inheritdoc/>
public object Map(object source, object target)
{
Inject(source, target);
return target;
}

/// <summary>
/// Map source object to target object
/// </summary>
protected abstract void Inject(object source, object target);
}
}
2 changes: 1 addition & 1 deletion ValueInjecter/ValueInjecter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<AssemblyVersion>3.2.0.0</AssemblyVersion>
<FileVersion>3.2.0.0</FileVersion>
<Version>3.2</Version>
<Version>3.2.1</Version>
<PackageLicenseUrl>https://github.com/omuleanu/ValueInjecter/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/omuleanu/ValueInjecter</PackageProjectUrl>
<RepositoryUrl></RepositoryUrl>
Expand Down
Loading