-
Notifications
You must be signed in to change notification settings - Fork 0
201 lines (163 loc) · 6.17 KB
/
ci-cd.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
name: ci-cd
on:
push:
branches: [main]
pull_request:
branches: [main]
release:
types:
- created
concurrency:
group: ci-cd-${{ github.ref }}
cancel-in-progress: true
env:
PROJECT_NAME: DrifterApps Seeds
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
check_changes:
uses: patmoreau/workflow-config/.github/workflows/check-changes-action.yml@main
with:
file_patterns: ${{ vars.CICD_CODE_FILE_PATTERNS }}
set-version:
runs-on: ubuntu-latest
needs: check_changes
if: >
(needs.check_changes.outputs.code_was_changed == 'true') ||
(github.event_name == 'release' && github.event.action == 'created')
outputs:
version: ${{ steps.gitversion.outputs.majorMinorPatch }}
assembly-version: ${{ steps.gitversion.outputs.AssemblySemFileVer }}
nuget-version: ${{ steps.gitversion.outputs.NuGetVersionV2 }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Disable workflow commands
run: |
echo "::stop-commands::`echo -n ${{ github.token }} | sha256sum | head -c 64`"
- name: Ensure .NET Installed
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v1.1.1
with:
versionSpec: "5.x"
- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/execute@v1.1.1
with:
useConfigFile: true
configFilePath: GitVersion.yml
- name: Display GitVersion outputs
run: |
echo "MajorMinorPatch: ${{ steps.gitversion.outputs.MajorMinorPatch }}"
echo "AssemblySemFileVer: ${{ steps.gitversion.outputs.AssemblySemFileVer }}"
echo "NuGetVersionV2: ${{ steps.gitversion.outputs.NuGetVersionV2 }}"
- name: Enable workflow commands
run: |
echo "::`echo -n ${{ github.token }} | sha256sum | head -c 64`::"
build:
runs-on: ubuntu-latest
needs: set-version
env:
VERSION: ${{ needs.set-version.outputs.version }}
ASSEMBLY_VERSION: ${{ needs.set-version.outputs.assembly-version }}
NUGET_VERSION: ${{ needs.set-version.outputs.nuget-version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
env:
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
- run: echo '${{ steps.stepid.outputs.dotnet-version }}'
- name: Restore packages
run: dotnet restore
- name: Build
run: dotnet build --no-restore --configuration Release /property:Version=${{ env.ASSEMBLY_VERSION }}
- name: Tests
run: dotnet test --no-restore --no-build --configuration Release --logger 'trx;verbosity=normal' --results-directory ./tests-results --collect 'XPlat Code Coverage'
- name: Test Report
uses: dorny/test-reporter@v1
id: test-results
if: always()
with:
name: .Net Tests
path: ./tests-results/**/*.trx
reporter: dotnet-trx
- name: Set badge color
shell: bash
run: |
case ${{ steps.test-results.outputs.conclusion }} in
success)
echo "BADGE_COLOR=31c653" >> $GITHUB_ENV
;;
failure)
echo "BADGE_COLOR=800000" >> $GITHUB_ENV
;;
esac
- name: Create badge
uses: emibcn/badge-action@v2.0.3
with:
label: Tests
status: "${{ steps.test-results.outputs.passed }} passed, ${{ steps.test-results.outputs.failed }} failed, ${{ steps.test-results.outputs.skipped }} skipped: ${{ steps.test-results.outputs.conclusion }}"
color: ${{ env.BADGE_COLOR }}
path: seeds-tests-badge.svg
- name: Upload badge to artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: Test Results Badge
path: |
seeds-tests-badge.svg
- name: Upload badge to Gist
if: >
(github.event_name == 'workflow_run' && github.event.workflow_run.head_branch == 'main') ||
(github.event_name != 'workflow_run' && github.ref == 'refs/heads/main')
uses: exuanbo/actions-deploy-gist@v1
with:
token: ${{ secrets.GIST_TOKEN }}
gist_id: 51a2fc9fd8b7ed500ed3b6aabe0fc2d6
file_path: seeds-tests-badge.svg
file_type: text
tagging:
needs: [set-version, build]
uses: patmoreau/workflow-config/.github/workflows/tag-version.yml@main
with:
version: ${{ needs.set-version.outputs.version }}
publish:
needs: [set-version, tagging]
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'created'
env:
VERSION: ${{ needs.set-version.outputs.version }}
ASSEMBLY_VERSION: ${{ needs.set-version.outputs.assembly-version }}
NUGET_VERSION: ${{ needs.set-version.outputs.nuget-version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
env:
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Restore packages
run: dotnet restore
- name: Build
run: dotnet build --no-restore --configuration Release /property:Version=${{ env.ASSEMBLY_VERSION }}
- name: Pack NuGet packages
run: dotnet pack /property:Version=${{ env.NUGET_VERSION }} --no-build --include-symbols --configuration Release -o ./nuget-packages
- name: Publish Package
run: dotnet nuget push ./nuget-packages/*.nupkg --source "https://api.nuget.org/v3/index.json" --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate
create_check:
needs: [check_changes, build]
uses: patmoreau/workflow-config/.github/workflows/create-check.yml@main
if: always() && needs.check_changes.result == 'success'
with:
code_was_changed: ${{ needs.check_changes.outputs.code_was_changed }}
check_name: 'build-completed'
check_result: ${{ needs.build.result }}