Skip to content

Commit

Permalink
Split build into build-and-test and pack
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrzajac committed Oct 19, 2023
1 parent 5e74308 commit 5cefebc
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 29 deletions.
35 changes: 15 additions & 20 deletions .github/actions/test-module/action.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,42 @@
name: Test module
description: Run tests against specified module
inputs:
module-name:
description: Name of the module
required: true
module-namespace:
description: Name of the module namespace
required: true
codecov-token:
description: Value of Codecov token used to upload code coverage results
required: true
coverage-directory:
description: Path to code coverage directory where results are being stored
required: false
default: ${{ github.workspace }}\src\opencover
module-name:
description: Name of the module
required: true
module-namespace:
description: Name of the module namespace
required: true
target-framework:
description: Framework version to run tests against
required: true
outputs:
file-path:
description: Signing key file path
value: ${{ steps.signing-key.outputs.PATH }}
runs:
using: composite
steps:
- name: 🧪 test ${{ matrix.package_module }} in net7.0 & collect coverage
id: module-code-coverage
- name: 🧪 test ${{ inputs.module-name }} in ${{ inputs.target-framework }} & collect coverage
id: test-and-collect-code-coverage
run: |
$path = [IO.Path]::Combine("$env:CoverageDirectory","$env:ModuleFullName.xml")
dotnet test ./src/$env:ModuleFullName.Tests/ --no-build -f $env:TargetFramework -e:CollectCoverage=true -e:CoverletOutputFormat=opencover -e:Exclude="[xunit*]*" -e:CoverletOutput=$path
"FILE=$env:ModuleFullName.$env:TargetFramework.xml" >> $env:GITHUB_OUTPUT
$path = [IO.Path]::Combine("${{ inputs.coverage-directory }}","$env:ModuleFullName.xml")
dotnet test ./src/$env:ModuleFullName.Tests/ --no-build -f ${{ inputs.target-framework }} -e:CollectCoverage=true -e:CoverletOutputFormat=opencover -e:Exclude="[xunit*]*" -e:CoverletOutput=$path
"FILE=$env:ModuleFullName.${{ inputs.target-framework }}.xml" >> $env:GITHUB_OUTPUT
shell: pwsh
env:
CoverageDirectory: ${{ inputs.coverage-directory }}
ModuleFullName: ${{ inputs.module-namespace }}.${{ inputs.module-name }}
TargetFramework: net7.0
- name: 🧪 test ${{ matrix.package_module }} in net472
run: dotnet test ./src/${{ inputs.module-namespace }}.${{ inputs.module-name }}.Tests/ --no-build -f net472
shell: pwsh
- name: 🧪 test ${{ matrix.package_module }} in net48
run: dotnet test ./src/${{ inputs.module-namespace }}.${{ inputs.module-name }}.Tests/ --no-build -f net48
shell: pwsh
- name: 📤 upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ inputs.codecov-token }}
files: ${{ steps.module-code-coverage.outputs.FILE }}
files: ${{ steps.test-and-collect-code-coverage.outputs.FILE }}
directory: ${{ inputs.coverage-directory }}
flags: unittests
47 changes: 38 additions & 9 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,19 @@ jobs:
uses: gittools/actions/gitversion/execute@v0
with:
useConfigFile: true
build:
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) }}
package-module: ${{ fromJSON(needs.init.outputs.matrix) }}
target-framework: [net7.0, net472, net48]
include:
- target-framework: net7.0
collect-code-coverage: true
if: ${{ needs.init.outputs.matrix != '' }}
steps:
- name: 📥 checkout
Expand All @@ -101,26 +105,51 @@ jobs:
with:
signing-key-value: ${{ secrets.SIGNING_KEY }}
- name: 🏗️ build
run: dotnet build ./src/${{ env.Namespace }}.${{ matrix.package_module }}.sln
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 net472
if: ${{ matrix.collect-code-coverage != true }}
run: dotnet test ./src/${{ env.Namespace }}.${{ matrix.package-module }}.Tests/ --no-build -f ${{ matrix.target-framework }}
- name: 🧪 test
if: ${{ matrix.collect-code-coverage == true }}
uses: ./.github/actions/test-module
with:
module-name: ${{ matrix.package_module }}
module-namespace: ${{ env.Namespace }}
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: 📦 pack
if: ${{ startsWith(matrix.package_module, 'Auto' ) }}
run: dotnet pack ./src/${{ env.Namespace }}.${{ matrix.package_module }} --no-restore
if: ${{ startsWith(matrix.package-module, 'Auto' ) }}
run: dotnet pack ./src/${{ env.Namespace }}.${{ matrix.package-module }} --no-restore
env:
CI: true
StrongNameKey: ${{ secrets.SIGNING_KEY }}
StrongNameKeyPath: ${{ steps.signing-key.outputs.file-path }}
- name: 🔼 upload packages
if: ${{ startsWith(matrix.package_module, 'Auto' ) }}
if: ${{ startsWith(matrix.package-module, 'Auto' ) }}
uses: actions/upload-artifact@v3
with:
name: packages
Expand All @@ -130,7 +159,7 @@ jobs:
publish:
runs-on: ubuntu-latest
timeout-minutes: 15
needs: [build]
needs: [pack]
environment: ${{ inputs.environment }}
if: ${{ inputs.environment != null }}
steps:
Expand Down

0 comments on commit 5cefebc

Please sign in to comment.