Skip to content

Commit

Permalink
Github workflow (#44)
Browse files Browse the repository at this point in the history
* Replace AppVeyor build definition with GitHub workflows
* Enable GitHub workflow manual trigger and introduce ability to select environment and package
* Use windows agents to support old .NET Framework
* Update expected dotnet version from 6 to 7
* Update analyzers
* Ignore S6608 rule in tests
* Address IDE0005 analyzer on the build issue: dotnet/aspnetcore#47912
* Use gitversion for automatic Versioning
* Automate pushing tags when publishing packages

---------

Co-authored-by: krzysztofkaczorowski <[email protected]>
Co-authored-by: Krzysztof Kaczorowski <[email protected]>
  • Loading branch information
3 people authored Aug 30, 2023
1 parent 2bcf483 commit 997893a
Show file tree
Hide file tree
Showing 29 changed files with 308 additions and 470 deletions.

This file was deleted.

60 changes: 0 additions & 60 deletions .github/workflows/Objectivity.AutoFixture.XUnit2.AutoMoq.yml

This file was deleted.

This file was deleted.

178 changes: 138 additions & 40 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -1,75 +1,173 @@
name: CI/CD
on:
workflow_dispatch:
push:
branches: [ '*' ]
paths:
- 'src/**'
inputs:
buildAutoMoq:
description: "Build AutoMoq"
required: true
type: boolean
default: true
buildAutoNSubstitute:
description: "Build AutoNSubstitute"
required: true
type: boolean
default: true
buildAutoFakeItEasy:
description: "Build AutoFakeItEasy"
required: true
type: boolean
default: true
environment:
description: "Environment"
type: environment
required: true
default: prod
pull_request:
paths:
- 'src/**'
branches: ["*"]
paths-ignore:
- "**.md"
- "**.png"
types: [opened, synchronize, reopened]

env:
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
version: 0.0.${{ github.run_number }}
configuration: Release
namespace: Objectivity.AutoFixture.XUnit2
Configuration: Release
Namespace: Objectivity.AutoFixture.XUnit2
StrongNameKeyName: key.snk
CoverageDirectory: ${{ github.workspace }}\src\opencover

defaults:
run:
shell: bash
shell: pwsh

jobs:
build:
init:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.MATRIX }}
Version: ${{ steps.gitversion.outputs.MajorMinorPatch }}
steps:
- name: 🎰 prepare strategy matrix
id: set-matrix
run: |
$allModules = @{
AutoMoq=if ('${{inputs.buildAutoMoq}}') { $${{inputs.buildAutoMoq}} } else { $true };
AutoNSubstitute=if ('${{inputs.buildAutoNSubstitute}}') { $${{inputs.buildAutoNSubstitute}} } else { $true };
AutoFakeItEasy=if ('${{inputs.buildAutoFakeItEasy}}') { $${{inputs.buildAutoFakeItEasy}} } else { $true }
}
$matrix = @{
package_module = @(Foreach ($module in ($allModules.GetEnumerator() | Where-Object { $_.Value })) {$module.Name})
}
"MATRIX=$($matrix | ConvertTo-JSON -Compress)" >> $env:GITHUB_OUTPUT
- name: 📥 checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: 🗜️ install GitVersion
uses: gittools/actions/gitversion/setup@v0
with:
versionSpec: "5.x"
- name: 🎱 determine version
id: gitversion
uses: gittools/actions/gitversion/execute@v0
with:
useConfigFile: true
build:
needs: init
runs-on: windows-latest #We are using windows instead of ubuntu becaus it provides support for net472 & net48.
timeout-minutes: 15
env:
Version: ${{ needs.init.outputs.Version }}
strategy:
matrix:
package_module: [AutoMoq, AutoNSubstitute, AutoFakeItEasy]
matrix: ${{ fromJSON(needs.init.outputs.matrix) }}
steps:
- name: 🤘 checkout
- name: 📥 checkout
uses: actions/checkout@v3
- name: 🏭 prepare .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
fetch-depth: 0
- name: 🖊️ materialize signing key
id: write_sign_key_file
uses: timheuer/base64-to-file@v1
with:
fileName: 'private.snk'
encodedString: ${{ secrets.SIGNING_KEY }}
id: signing-key
run: |
$path = [IO.Path]::Combine("${{ github.workspace }}","src","${{ env.StrongNameKeyName }}")
[IO.File]::WriteAllBytes($path, [Convert]::FromBase64String("$env:StrongNameKey"))
"PATH=$path" >> $env:GITHUB_OUTPUT
env:
StrongNameKey: ${{ secrets.SIGNING_KEY }}
- name: 🏗️ build
run: dotnet build ./src/${{ env.namespace }}.${{ matrix.package_module }}.sln -p:Version=${{ env.version }} -p:AssemblyVersion=${{ env.version }}
run: dotnet build ./src/${{ env.Namespace }}.${{ matrix.package_module }}.sln
env:
CI: true
StrongNameKey: ${{ secrets.SIGNING_KEY }}
StrongNameKeyPath: ${{ steps.signing-key.outputs.PATH }}
- name: 🧪 test Core in net7.0 & collect coverage
id: core-code-coverage
run: |
$path = [IO.Path]::Combine("$env:CoverageDirectory","$env:CoverageFileName.xml")
dotnet test ./src/${{ env.Namespace }}.Core.Tests/ --no-build -f $env:TargetFramework -e:CollectCoverage=true -e:CoverletOutputFormat=opencover -e:Exclude="[xunit*]*" -e:CoverletOutput=$path
"FILE=$env:CoverageFileName.$env:TargetFramework.xml" >> $env:GITHUB_OUTPUT
env:
StrongNameKey: true #TODO: consider removing
StrongNameKeyPath: ${{ steps.write_sign_key_file.outputs.filePath }}
- name: 🧪 test net472
run: dotnet test -f net472 --no-build --verbosity normal
- name: 🧪 test net48
run: dotnet test -f net48 --no-build --verbosity normal
- name: 🧪 test net7.0 & collect coverage
run: dotnet test -f net7.0 --no-build --verbosity normal -e:CollectCoverage=true -e:CoverletOutputFormat=opencover -e:Exclude="[xunit*]*" -e:CoverletOutput=$coverletFile
CoverageFileName: ${{ env.Namespace }}.Core
TargetFramework: net7.0
- name: 🧪 test Core in net472
run: dotnet test ./src/${{ env.Namespace }}.Core.Tests/ --no-build -f net472
- name: 🧪 test Core in net48
run: dotnet test ./src/${{ env.Namespace }}.Core.Tests/ --no-build -f net48
- name: 🧪 test ${{ matrix.package_module }} in net7.0 & collect coverage
id: module-code-coverage
run: |
$path = [IO.Path]::Combine("$env:CoverageDirectory","$env:CoverageFileName.xml")
dotnet test ./src/${{ env.Namespace }}.${{ matrix.package_module }}.Tests/ --no-build -f $env:TargetFramework -e:CollectCoverage=true -e:CoverletOutputFormat=opencover -e:Exclude="[xunit*]*" -e:CoverletOutput=$path
"FILE=$env:CoverageFileName.$env:TargetFramework.xml" >> $env:GITHUB_OUTPUT
env:
coverletFile: "${{ github.workspace }}/src/opencover/${{ env.namespace }}.${{ matrix.package_module }}.xml"
CoverageFileName: ${{ env.Namespace }}.${{ matrix.package_module }}
TargetFramework: net7.0
- name: 🧪 test ${{ matrix.package_module }} in net472
run: dotnet test ./src/${{ env.Namespace }}.${{ matrix.package_module }}.Tests/ --no-build -f net472
- name: 🧪 test ${{ matrix.package_module }} in net48
run: dotnet test ./src/${{ env.Namespace }}.${{ matrix.package_module }}.Tests/ --no-build -f net48
- name: 📤 upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
files: "${{ github.workspace }}/src/opencover/${{ env.namespace }}.${{ matrix.package_module }}.xml"
token: ${{ secrets.CODECOV_TOKEN }}
files: ${{ steps.core-code-coverage.outputs.FILE }},${{ steps.module-code-coverage.outputs.FILE }}
directory: ${{ env.CoverageDirectory }}
flags: unittests
- name: 📦 pack
run: dotnet pack ./src/${{ env.namespace }}.${{ matrix.package_module }} --no-restore -p:Version=${{ env.version }} -p:AssemblyVersion=${{ env.version }} -p:AssemblyFileVersion=${{ env.version }} -p:PackageVersion=${{ env.version }}
- name: 🔼 packages
uses: actions/upload-artifact@v2
run: dotnet pack ./src/${{ env.Namespace }}.${{ matrix.package_module }} --no-restore
env:
CI: true
StrongNameKey: ${{ secrets.SIGNING_KEY }}
StrongNameKeyPath: ${{ steps.signing-key.outputs.PATH }}
- name: 🔼 upload packages
uses: actions/upload-artifact@v3
with:
name: bin
path: bin/*.nupkg
name: packages
path: ./src/**/*.nupkg
publish:
runs-on: ubuntu-latest
timeout-minutes: 15
needs: [build]
environment: ${{ inputs.environment }}
if: ${{ inputs.environment != null }}
steps:
- name: 🔽 download packages
uses: actions/download-artifact@v3
with:
name: packages
- name: 📤 push
run: dotnet nuget push **/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source "nuget.org" --skip-duplicate
add-tags:
runs-on: ubuntu-latest
timeout-minutes: 15
needs: [publish, init]
if: ${{ github.ref == 'refs/heads/main' }}
steps:
- name: 🤘 checkout
- name: 📥 checkout
uses: actions/checkout@v3
# TODO: Publish to NuGet
with:
fetch-depth: 0
- name: 🏷️ tag version
run: |
git tag "${{ needs.init.outputs.Version }}"
git push origin "${{ needs.init.outputs.Version }}"
1 change: 1 addition & 0 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mode: ContinuousDelivery
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Objectivity.AutoFixture.XUnit2.AutoMock

[![Build Status](https://ci.appveyor.com/api/projects/status/github/ObjectivityLtd/AutoFixture.XUnit2.AutoMock?branch=master&svg=true)](https://ci.appveyor.com/project/ObjectivityAdminsTeam/autofixture-xunit2-automock) [![Tests Status](https://img.shields.io/appveyor/tests/ObjectivityAdminsTeam/autofixture-xunit2-automock/master.svg)](https://ci.appveyor.com/project/ObjectivityAdminsTeam/autofixture-xunit2-automock) [![codecov](https://codecov.io/gh/ObjectivityLtd/AutoFixture.XUnit2.AutoMock/branch/master/graph/badge.svg)](https://codecov.io/gh/ObjectivityLtd/AutoFixture.XUnit2.AutoMock) [![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT) [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FObjectivityLtd%2FAutoFixture.XUnit2.AutoMock.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FObjectivityLtd%2FAutoFixture.XUnit2.AutoMock?ref=badge_shield)
[![CI/CD](https://github.com/ObjectivityLtd/AutoFixture.XUnit2.AutoMock/actions/workflows/cicd.yml/badge.svg?branch=master)](https://github.com/ObjectivityLtd/AutoFixture.XUnit2.AutoMock/actions/workflows/cicd.yml) [![codecov](https://codecov.io/gh/ObjectivityLtd/AutoFixture.XUnit2.AutoMock/branch/master/graph/badge.svg)](https://codecov.io/gh/ObjectivityLtd/AutoFixture.XUnit2.AutoMock) [![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT) [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FObjectivityLtd%2FAutoFixture.XUnit2.AutoMock.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FObjectivityLtd%2FAutoFixture.XUnit2.AutoMock?ref=badge_shield)

Accelerates preparation of mocked structures for unit tests under [XUnit2](http://xunit.github.io/) by configuring [AutoFixture](https://github.com/AutoFixture/AutoFixture) data generation to use a mocking library of your choice. Gracefully handles recursive structures by omitting recursions.

Expand Down
Loading

0 comments on commit 997893a

Please sign in to comment.