From 7526e2f564e6e21a5106b450461e4a307ef1854b Mon Sep 17 00:00:00 2001 From: Piotr Zajac Date: Sat, 21 Oct 2023 17:37:07 +0200 Subject: [PATCH] Reusable workflow for build and test --- .github/workflows/build-and-test.yml | 74 ++++++++++++++++++++++++++++ .github/workflows/cicd.yml | 56 ++++----------------- .github/workflows/pack.yml | 1 + 3 files changed, 85 insertions(+), 46 deletions(-) create mode 100644 .github/workflows/build-and-test.yml diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 00000000..c4c71c7e --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -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 }} \ No newline at end of file diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 7c79c704..b4177c10 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -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) }} @@ -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: diff --git a/.github/workflows/pack.yml b/.github/workflows/pack.yml index 079c4279..d9ad5f4f 100644 --- a/.github/workflows/pack.yml +++ b/.github/workflows/pack.yml @@ -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