♻️ CI/CD #195
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI/CD | |
on: | |
pull_request: | |
paths: | |
- 'src/**' | |
- 'GitVersion.yml' | |
- '.github/workflows/cicd.yml' | |
- '.github/actions/materialize-signing-key/**' | |
types: [opened, synchronize, reopened] | |
push: | |
branches: | |
- 'master' | |
paths: | |
- 'src/**' | |
- 'GitVersion.yml' | |
- '.github/workflows/cicd.yml' | |
- '.github/actions/materialize-signing-key/**' | |
workflow_dispatch: | |
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 | |
env: | |
DOTNET_NOLOGO: true | |
DOTNET_CLI_TELEMETRY_OPTOUT: true | |
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages | |
Configuration: Release | |
Namespace: Objectivity.AutoFixture.XUnit2 | |
defaults: | |
run: | |
shell: pwsh | |
jobs: | |
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 = @(Foreach ($module in ($allModules.GetEnumerator() | Where-Object { $_.Value })) {$module.Name}) | |
if ($matrix.count -gt 0) { $matrix = @("Core") + $matrix } | |
"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-and-test: | |
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: ${{ fromJSON(needs.init.outputs.matrix) }} | |
target-framework: [net472, net48] # What to do with net7.0? | |
include: | |
- target-framework: net48 | |
collect-code-coverage: true | |
if: ${{ needs.init.outputs.matrix != '' }} | |
steps: | |
- name: 📥 checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: 🖊️ materialize signing key | |
id: signing-key | |
uses: ./.github/actions/materialize-signing-key | |
with: | |
signing-key-value: ${{ secrets.SIGNING_KEY }} | |
- name: 💾 cache nuget packages | |
uses: actions/cache@v3 | |
with: | |
path: ${{ env.NUGET_PACKAGES }} | |
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} | |
restore-keys: | | |
${{ runner.os }}-nuget- | |
- name: 🏗️ build | |
run: dotnet build ./src/${{ env.Namespace }}.${{ matrix.package-module }}.sln -f ${{ matrix.target-framework }} | |
env: | |
CI: true | |
StrongNameKey: ${{ secrets.SIGNING_KEY }} | |
StrongNameKeyPath: ${{ steps.signing-key.outputs.file-path }} | |
- name: 🧪 test ${{ matrix.package-module }} in ${{ matrix.target-framework }} | |
if: ${{ matrix.collect-code-coverage != true }} | |
run: dotnet test ./src/${{ env.Namespace }}.${{ matrix.package-module }}.Tests/ --no-build -f ${{ matrix.target-framework }} | |
- name: 🧪 test ${{ matrix.package-module }} in ${{ matrix.target-framework }} & collect coverage | |
if: ${{ matrix.collect-code-coverage == true }} | |
uses: ./.github/actions/test-module | |
with: | |
codecov-token: ${{ secrets.CODECOV_TOKEN }} | |
module-name: ${{ matrix.package-module }} | |
module-namespace: ${{ env.Namespace }} | |
target-framework: ${{ matrix.target-framework }} | |
pack: | |
needs: [init, build-and-test] | |
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: ${{ fromJSON(needs.init.outputs.matrix) }} | |
if: ${{ needs.init.outputs.matrix != '' }} | |
steps: | |
- name: 📥 checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: 🖊️ materialize signing key | |
id: signing-key | |
uses: ./.github/actions/materialize-signing-key | |
with: | |
signing-key-value: ${{ secrets.SIGNING_KEY }} | |
- name: 💾 cache nuget packages | |
uses: actions/cache@v3 | |
with: | |
path: ${{ env.NUGET_PACKAGES }} | |
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} | |
restore-keys: | | |
${{ runner.os }}-nuget- | |
- name: 📦 pack | |
if: ${{ startsWith(matrix.package-module, 'Auto' ) }} | |
run: dotnet pack ./src/${{ env.Namespace }}.${{ matrix.package-module }} | |
env: | |
CI: true | |
StrongNameKey: ${{ secrets.SIGNING_KEY }} | |
StrongNameKeyPath: ${{ steps.signing-key.outputs.file-path }} | |
- name: 🔼 upload packages | |
if: ${{ startsWith(matrix.package-module, 'Auto' ) }} | |
uses: actions/upload-artifact@v3 | |
with: | |
name: packages | |
path: | | |
./src/**/*.nupkg | |
./src/**/*.snupkg | |
publish: | |
runs-on: ubuntu-latest | |
timeout-minutes: 15 | |
needs: [pack] | |
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] | |
# Allow tagging only on the master branch | |
if: ${{ github.ref_name == 'master' }} | |
steps: | |
- name: 📥 checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: 🏷️ tag version | |
run: | | |
git tag "${{ needs.init.outputs.Version }}" | |
git push origin "${{ needs.init.outputs.Version }}" |