-
Notifications
You must be signed in to change notification settings - Fork 0
123 lines (111 loc) · 3.56 KB
/
dotnet-workflow-common.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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