Skip to content

chore(ZCH-126): added caching for dotnet and node #6

chore(ZCH-126): added caching for dotnet and node

chore(ZCH-126): added caching for dotnet and node #6

name: .NET common
on:
workflow_call:
inputs:
WORKING_DIRECTORY:
required: true
type: string
DOTNET_IMAGE:
required: true
type: string
RUN_ON:
required: false
type: string
default: "zupit-agents"
RUNNERS_CONTAINER_GROUP:
required: false
type: string
default: "Container"
DOTNET_IMAGE_ENV_VARIABLES:
required: false
type: string
default: "{}"
CSHARPIER_VERSION:
required: false
type: string
default: ""
RUN_LINT:
required: false
type: boolean
default: true
RUN_TESTS:
required: false
type: boolean
default: true
CHECK_WORKDIR_CHANGES:
required: true
type: boolean
default: false
CHECK_CUSTOM_DIR:
required: false
type: string
default: ""
CHECK_CHANGES_BY_JOBS:
required: false
type: string
default: "all"
env:
CHECK_DIR: ${{ inputs.WORKING_DIRECTORY }}
jobs:
workdir-has-changes:
runs-on: ubuntu-latest
outputs:
changes-detected: ${{ steps.filter.outputs.changes-detected }}
steps:
- name: Set CHECK_DIR to custom directory if provided
if: ${{ inputs.CHECK_CUSTOM_DIR != '' }}
run: echo "CHECK_DIR=${{ inputs.CHECK_CUSTOM_DIR }}" >> $GITHUB_ENV
- name: Set default CHECK_DIR
if: ${{ inputs.CHECK_CUSTOM_DIR == '' }}
run: echo "CHECK_DIR=${{ inputs.WORKING_DIRECTORY }}" >> $GITHUB_ENV
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
changes-detected:
- "${{ env.CHECK_DIR }}/**"
dotnet-common:
needs: workdir-has-changes
name: Run .NET build, check formatting and test
if: ${{ !inputs.CHECK_WORKDIR_CHANGES || (needs.workdir-has-changes.outputs.changes-detected == 'true' && (inputs.CHECK_CHANGES_BY_JOBS == 'all' || contains(fromJson(inputs.CHECK_CHANGES_BY_JOBS), github.job)))}}
runs-on:
labels: ${{ inputs.RUN_ON }}
group: ${{ inputs.RUNNERS_CONTAINER_GROUP }}
container:
image: ${{ inputs.DOTNET_IMAGE }}
env: ${{ fromJson(inputs.DOTNET_IMAGE_ENV_VARIABLES) }}
defaults:
run:
working-directory: ${{ inputs.WORKING_DIRECTORY }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check code formatting
uses: zupit-it/pipeline-templates/.github/actions/dotnet/[email protected]
with:
WORKING_DIRECTORY: ${{ inputs.WORKING_DIRECTORY }}
CSHARPIER_VERSION: ${{ inputs.CSHARPIER_VERSION }}
- name: Build
uses: zupit-it/pipeline-templates/.github/actions/dotnet/build
with:
WORKING_DIRECTORY: ${{ inputs.WORKING_DIRECTORY }}
BUILD_CONFIG: "Debug"
- name: Lint
uses: zupit-it/pipeline-templates/.github/actions/dotnet/[email protected]
if: ${{ inputs.RUN_LINT == 'true' }}
with:
WORKING_DIRECTORY: ${{ inputs.WORKING_DIRECTORY }}
- name: Run tests
uses: zupit-it/pipeline-templates/.github/actions/dotnet/[email protected]
if: ${{ inputs.RUN_TESTS == 'true' }}
with:
WORKING_DIRECTORY: ${{ inputs.WORKING_DIRECTORY }}
GENERATE_CODE_COVERAGE: false
jobs-succeded:
needs: dotnet-common
runs-on: ubuntu-latest
if: ${{ always()}}
steps:
- name: "Jobs: dotnet-common didn't fail."
run: if [ "${{ needs.dotnet-common.result }}" == "failure" ]; then exit 1; fi