Skip to content

Commit

Permalink
Reusable workflow for build and test
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrzajac committed Oct 21, 2023
1 parent f8ac4e8 commit 7526e2f
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 46 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Build & test
on:
workflow_call:
inputs:
version:
description: Assembly and package version
required: true
type: string
package-module:
description: Name of the module
required: true
type: string
namespace:
description: Name of the module namespace
required: true
type: string
target-framework:
description: Compiles for a specific framework
required: true
type: string
skip-target-framework-on-build:
required: false
type: boolean
default: false
collect-code-coverage:
required: false
type: boolean
default: false
secrets:
signing-key-value:
description: Value of the signing key
required: true
env:
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
Version: ${{ inputs.version }}
jobs:
build-and-test:
runs-on: windows-latest # We are using windows instead of ubuntu becaus it provides support for net472 & net48.
timeout-minutes: 15
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-value }}
- 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
if: ${{ inputs.skip-target-framework-on-build == true }}
run: dotnet build ./src/${{ inputs.namespace }}.${{ inputs.package-module }}.sln${{ inputs.skip-target-framework-on-build == true && '' || format('-f {0}', inputs.target-framework)}}
env:
CI: true
StrongNameKey: ${{ secrets.SIGNING_KEY }}
StrongNameKeyPath: ${{ steps.signing-key.outputs.file-path }}
- name: 🧪 test ${{ inputs.package-module }} in ${{ inputs.target-framework }}
if: ${{ inputs.collect-code-coverage != true }}
run: dotnet test ./src/${{ inputs.namespace }}.${{ inputs.package-module }}.Tests/ --no-build -f ${{ inputs.target-framework }}
- name: 🧪 test ${{ inputs.package-module }} in ${{ inputs.target-framework }} & collect coverage
if: ${{ inputs.collect-code-coverage == true }}
uses: ./.github/actions/test-module
with:
codecov-token: ${{ secrets.CODECOV_TOKEN }}
module-name: ${{ inputs.package-module }}
module-namespace: ${{ inputs.namespace }}
target-framework: ${{ inputs.target-framework }}
56 changes: 10 additions & 46 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ jobs:
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) }}
Expand All @@ -96,48 +92,16 @@ jobs:
collect-code-coverage: true
skip-target-framework-on-build: 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 for ${{ matrix.target-framework }}
if: ${{ matrix.skip-target-framework-on-build != true }}
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: 🏗️ build
if: ${{ matrix.skip-target-framework-on-build == true }}
run: dotnet build ./src/${{ env.Namespace }}.${{ matrix.package-module }}.sln
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 }}
uses: ./.github/workflows/build-and-test.yml
with:
version: ${{ needs.init.outputs.Version }}
package-module: ${{ matrix.package-module }}
namespace: Objectivity.AutoFixture.XUnit2
target-framework: ${{ matrix.target-framework }}
skip-target-framework-on-build: ${{ matrix.skip-target-framework-on-build }}
collect-code-coverage: ${{ matrix.collect-code-coverage }}
secrets:
signing-key-value: ${{ secrets.SIGNING_KEY }}
pack:
needs: [init, build-and-test]
strategy:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ on:
type: string
secrets:
signing-key-value:
description: Value of the signing key
required: true
env:
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
Expand Down

0 comments on commit 7526e2f

Please sign in to comment.