-
-
Notifications
You must be signed in to change notification settings - Fork 43
212 lines (183 loc) · 6.59 KB
/
build-pipeline.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
name: Build Pipeline
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
jobs:
analyse:
name: Static Analysis
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: true
matrix:
language: ["csharp"]
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4
- name: Initialize
id: initialize
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
- name: Build
id: build
uses: github/codeql-action/autobuild@v2
- name: Analysis
id: analysis
uses: github/codeql-action/analyze@v2
pipeline:
name: Build, Test and Publish
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
language: ["csharp"]
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4
- name: Initialize
id: initialize
run: |
NAME=$(echo ${GITHUB_REPOSITORY} | tr '[:upper:]' '[:lower:]')
VERSION_PREFIX=$(date +'%Y.%m.%d').${GITHUB_RUN_NUMBER}
BRANCH_CURRENT=${GITHUB_REF#refs/*/}
BRANCH_CURRENT=${BRANCH_CURRENT//[^a-zA-Z0-9]/-}
if [[ ${GITHUB_EVENT_NAME} == 'pull_request' ]]; then
BRANCH_BASE=${GITHUB_BASE_REF#refs/*/}
BRANCH_BASE=${BRANCH_BASE/[^a-zA-Z0-9]//-}
BRANCH_COMPARE=${GITHUB_HEAD_REF#refs/*/}
BRANCH_COMPARE=${BRANCH_COMPARE//[^a-zA-Z0-9]/-}
VERSION_SUFFIX="merge-${BRANCH_BASE}-${BRANCH_COMPARE}"
elif [[ ${GITHUB_EVENT_NAME} == ${{ github.event.repository.default_branch }} ]]; then
VERSION_SUFFIX="${BRANCH_CURRENT}"
fi
if [[ $VERSION_SUFFIX == '' ]]; then
DOCKER_TAG=$VERSION_PREFIX
else
DOCKER_TAG=$VERSION_PREFIX-$VERSION_SUFFIX
fi
echo "name=$(eval printf "%s" "$NAME")" >> $GITHUB_OUTPUT
echo "version_prefix=$(eval printf "%s" "$VERSION_PREFIX")" >> $GITHUB_OUTPUT
echo "version_suffix=$(eval printf "%s" "$VERSION_SUFFIX")" >> $GITHUB_OUTPUT
echo "docker_tag=$(eval printf "%s" "$DOCKER_TAG")" >> $GITHUB_OUTPUT
echo "branch=$(eval printf "%s" "$BRANCH_CURRENT")" >> $GITHUB_OUTPUT
shell: bash
- name: Build
id: build
run: docker build .
--target coverage
--output type=local,dest=out
--tag $NAME:$DOCKER_TAG
--tag $NAME:latest
--build-arg VERSION_PREFIX=$VERSION_PREFIX
--build-arg VERSION_SUFFIX=$VERSION_SUFFIX
env:
DOCKER_BUILDKIT: 1
NAME: ${{ steps.initialize.outputs.name }}
VERSION_PREFIX: ${{ steps.initialize.outputs.version_prefix }}
VERSION_SUFFIX: ${{ steps.initialize.outputs.version_suffix }}
DOCKER_TAG: ${{ steps.initialize.outputs.docker_tag }}
- name: Analysis
id: analysis
uses: codecov/codecov-action@v3
with:
files: ./out/coverage.opencover.xml
token: ${{ secrets.CODECOV_TOKEN }}
- name: Publish
id: publish
run: docker build .
--target run
--tag $NAME:$DOCKER_TAG
--tag $NAME:latest
--build-arg VERSION_PREFIX=$VERSION_PREFIX
--build-arg VERSION_SUFFIX=$VERSION_SUFFIX
env:
DOCKER_BUILDKIT: 1
NAME: ${{ steps.initialize.outputs.name }}
VERSION_PREFIX: ${{ steps.initialize.outputs.version_prefix }}
VERSION_SUFFIX: ${{ steps.initialize.outputs.version_suffix }}
DOCKER_TAG: ${{ steps.initialize.outputs.docker_tag }}
- name: Docker Login
id: login
if: ${{ github.ref == 'refs/heads/main' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_LOGIN }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Docker Push
id: push
if: ${{ github.ref == 'refs/heads/main' }}
run: docker push $NAME --all-tags
env:
NAME: ${{ steps.initialize.outputs.name }}
template:
name: Nuget Template
runs-on: ubuntu-latest
needs: pipeline
strategy:
fail-fast: true
matrix:
language: ["csharp"]
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4
- name: Initialize
id: initialize
run: |
NAME=$(echo ${GITHUB_REPOSITORY} | tr '[:upper:]' '[:lower:]')
VERSION_PREFIX=$(date +'%Y.%m.%d').${GITHUB_RUN_NUMBER}
BRANCH_CURRENT=${GITHUB_REF#refs/*/}
BRANCH_CURRENT=${BRANCH_CURRENT//[^a-zA-Z0-9]/-}
if [[ ${GITHUB_EVENT_NAME} == 'pull_request' ]]; then
BRANCH_BASE=${GITHUB_BASE_REF#refs/*/}
BRANCH_BASE=${BRANCH_BASE/[^a-zA-Z0-9]//-}
BRANCH_COMPARE=${GITHUB_HEAD_REF#refs/*/}
BRANCH_COMPARE=${BRANCH_COMPARE//[^a-zA-Z0-9]/-}
VERSION_SUFFIX="merge-${BRANCH_BASE}-${BRANCH_COMPARE}"
elif [[ ${GITHUB_EVENT_NAME} == ${{ github.event.repository.default_branch }} ]]; then
VERSION_SUFFIX="${BRANCH_CURRENT}"
fi
if [[ $VERSION_SUFFIX == '' ]]; then
DOCKER_TAG=$VERSION_PREFIX
else
DOCKER_TAG=$VERSION_PREFIX-$VERSION_SUFFIX
fi
echo "name=$(eval printf "%s" "$NAME")" >> $GITHUB_OUTPUT
echo "version_prefix=$(eval printf "%s" "$VERSION_PREFIX")" >> $GITHUB_OUTPUT
echo "version_suffix=$(eval printf "%s" "$VERSION_SUFFIX")" >> $GITHUB_OUTPUT
echo "docker_tag=$(eval printf "%s" "$DOCKER_TAG")" >> $GITHUB_OUTPUT
echo "branch=$(eval printf "%s" "$BRANCH_CURRENT")" >> $GITHUB_OUTPUT
shell: bash
- name: Setup
id: setup
uses: nuget/setup-nuget@v1
with:
nuget-api-key: ${{ secrets.NUGET_API_KEY }}
- name: Pack
id: pack
run: |
if ([string]::IsNullOrEmpty(${Env:SUFFIX}))
{
nuget pack template.nuspec -NoDefaultExcludes -Version ${Env:VERSION}
}
else
{
nuget pack template.nuspec -NoDefaultExcludes -Version ${Env:VERSION} -Suffix ${Env:SUFFIX}
}
env:
VERSION: ${{ steps.initialize.outputs.version_prefix }}
SUFFIX: ${{ steps.initialize.outputs.version_suffix }}
shell: pwsh
- name: Publish
id: publish
if: ${{ github.ref == 'refs/heads/main' }}
run: nuget push *.nupkg -src https://api.nuget.org/v3/index.json