-
Notifications
You must be signed in to change notification settings - Fork 33
219 lines (185 loc) · 6.15 KB
/
dotnet.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
name: .Net
on:
push:
branches:
- master
pull_request:
types:
- opened
- synchronize
- reopened
- closed
branches:
- master
env:
IS_RELEASE_CANDIDATE: >-
${{
(
github.event_name == 'pull_request' &&
startsWith(github.event.pull_request.title, 'RELEASES:') &&
contains(github.event.pull_request.labels.*.name, 'RELEASES')
)
||
(
github.event_name == 'push' &&
startsWith(github.event.head_commit.message, 'RELEASES:') &&
startsWith(github.ref_name, 'RELEASE')
)
}}
jobs:
check_pr_title:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Check PR Title
run: >-
PR_TITLE="${{ github.event.pull_request.title }}"
echo "PR Title: ${{ github.event.pull_request.title }}"
# Define the list of prefixes
PREFIXES=(
"ACCEPTANCE"
"AGGREGATION"
"BASE"
"BROKER"
"BUSINESS"
"CODE RUB"
"COMPONENT"
"CONFIG"
"CONTROLLER"
"COORDINATION"
"CLIENT"
"DATA"
"DESIGN"
"DOCUMENTATION"
"EXPOSER"
"FOUNDATION"
"INFRA"
"INTEGRATION"
"MAJORFIX"
"MANAGEMENT"
"MEDIUMFIX"
"MINORFIX"
"ORCHESTRATION"
"PAGE"
"PROCESSING"
"PROVISION"
"RELEASE"
"STANDARD"
"VIEW"
)
# Check if the PR title starts with any of the prefixes
PREFIX_MATCH=false
for PREFIX in "${PREFIXES[@]}"
do
if [[ "${PR_TITLE}" == "${PREFIX}"* ]]; then
PREFIX_MATCH=true
break
fi
done
# Fail the workflow if no prefix match is found
if [ "${PREFIX_MATCH}" == false ]; then
echo "error: The PR title must start with one of THE STANDARD specified prefixes. Current PR Title: '${{ github.event.pull_request.title }}'"
echo "See https://github.com/hassanhabib/The-Standard-Team/blob/main/4%20Practices/4%20Practices.md#4113-category-list for the complete category list"
echo ""
echo "Please update the PR Title to the correct category, then navigate to the Actions tab and click on the Re-run jobs button"
echo "P.S. if the job fails again with the wrong title, give it a few minutes to allow the PR Title Change event to propagate through the system."
exit 1
fi
build:
runs-on: ubuntu-latest
needs:
- check_pr_title
steps:
- name: Check out
uses: actions/checkout@v3
- name: Setup .Net
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.201
- name: Restore
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
add_tag:
runs-on: ubuntu-latest
needs:
- build
if: >-
needs.build.result == 'success' &&
github.event.pull_request.merged &&
github.event.pull_request.base.ref == 'master' &&
startsWith(github.event.pull_request.title, 'RELEASES:') &&
contains(github.event.pull_request.labels.*.name, 'RELEASES')
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
token: ${{ secrets.PAT_FOR_TAGGING }}
- name: Configure Git
run: >-
git config user.name "GitHub Action"
git config user.email "[email protected]"
- name: Extract Version
id: extract_version
run: >
# Running on Linux/Unix
sudo apt-get install xmlstarlet
version_number=$(xmlstarlet sel -t -v "//Version" -n ADotNet/ADotNet.csproj)
echo "$version_number"
echo "version_number<<EOF" >> $GITHUB_OUTPUT
echo "$version_number" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
shell: bash
- name: Display Version
run: 'echo "Version number: ${{ steps.extract_version.outputs.version_number }}"'
- name: Extract Package Release Notes
id: extract_package_release_notes
run: >
# Running on Linux/Unix
sudo apt-get install xmlstarlet
package_release_notes=$(xmlstarlet sel -t -v "//PackageReleaseNotes" -n ADotNet/ADotNet.csproj)
echo "$package_release_notes"
echo "package_release_notes<<EOF" >> $GITHUB_OUTPUT
echo "$package_release_notes" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
shell: bash
- name: Display Package Release Notes
run: 'echo "Package Release Notes: ${{ steps.extract_package_release_notes.outputs.package_release_notes }}"'
- name: Create GitHub Tag
run: >-
git tag -a "v${{ steps.extract_version.outputs.version_number }}" -m "Release - v${{ steps.extract_version.outputs.version_number }}"
git push origin --tags
- name: Create GitHub Release
uses: actions/create-release@v1
with:
tag_name: v${{ steps.extract_version.outputs.version_number }}
release_name: Release - v${{ steps.extract_version.outputs.version_number }}
body: >-
## Release - v${{ steps.extract_version.outputs.version_number }}
### Release Notes
${{ steps.extract_package_release_notes.outputs.package_release_notes }}
env:
GITHUB_TOKEN: ${{ secrets.PAT_FOR_TAGGING }}
publish:
runs-on: ubuntu-latest
needs:
- add_tag
if: needs.add_tag.result == 'success'
steps:
- name: Check out
uses: actions/checkout@v3
- name: Setup .Net
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.201
- name: Restore
run: dotnet restore
- name: Build
run: dotnet build --no-restore --configuration Release
- name: Pack NuGet Package
run: dotnet pack --configuration Release --include-symbols
- name: Push NuGet Package
run: dotnet nuget push **/bin/Release/**/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_ACCESS }} --skip-duplicate