-
Notifications
You must be signed in to change notification settings - Fork 0
301 lines (263 loc) · 9.06 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
name: CI-CD
on:
workflow_dispatch:
inputs:
freeze_linux:
type: boolean
default: true
description: Freeze linux
freeze_windows:
type: boolean
default: false
description: Freeze windows
force_release:
type: boolean
default: false
description: Force to push a release now
push:
branches:
- "main"
pull_request:
branches:
- "main"
schedule:
- cron: "0 1 * * 1-5"
env:
MAIN_PYTHON_VERSION: '3.10'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
style:
name: Code style
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools tox
- name: Test with tox
run: tox -e style
tests:
name: Tests and coverage
needs: [freeze]
runs-on: ${{ matrix.os }}
strategy:
# max-parallel: 1
matrix:
os: [ubuntu-latest]
cfg:
- {python-version: "3.10", toxenv: "py310"}
fail-fast: false
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.cfg.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.cfg.python-version }}
- uses: extractions/netrc@v1
with:
machine: github.com
username: pyansys-ci-bot
password: ${{ secrets.PYANSYS_CI_BOT_TOKEN }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools tox tox-gh-actions
- name: Test with tox
run: tox -e ${{ matrix.cfg.toxenv }}-coverage
# env:
- name: Publish Test Report
uses: mikepenz/action-junit-report@v3
if: always()
with:
report_paths: '**/test*.xml'
check_name: Test Report ${{ matrix.os }}:${{ matrix.cfg.python-version }}
wheels:
name: Wheels
runs-on: ubuntu-latest
outputs:
version: ${{ steps.wheels.outputs.version }}
steps:
- uses: actions/checkout@v3
- name: Set up python
uses: actions/setup-python@v3
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}
- uses: extractions/netrc@v1
with:
machine: github.com
username: pyansys-ci-bot
password: ${{ secrets.PYANSYS_CI_BOT_TOKEN }}
- name: Install dependencies and build the library
id: wheels
run: |
python -m pip install --upgrade pip setuptools
python -m pip install -r requirements/requirements_build.txt
python build.py dev
python build.py wheels
python -m twine check dist/*
version=$(ls dist/ | grep template | grep -E -o "[0-9]+.[0-9]+.[0-9]+")
echo "version=$version" >> $GITHUB_OUTPUT
echo "Version: $version"
# - name: Version
# run: |
# ver=$(dev_env/bin/pip show ansys-rep-common | grep Version | awk '{print $2}')
# echo "version=$ver" >> $GITHUB_OUTPUT
# id: version
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: ansys-rep-repo-template-package
path: |
dist/*.whl
retention-days: 5
freeze:
name: Freeze
runs-on:
group: "Default Larger Runners"
labels: ubuntu-latest-16-cores
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.freeze_linux == 'true' }}
needs: [wheels, style]
strategy:
matrix:
image: [default]
fail-fast: false
steps:
- uses: actions/checkout@v3
- name: ccache
uses: hendrikmuhs/[email protected]
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
registry: ghcr.io/ansys
username: pyansys-ci-bot
password: ${{ secrets.PYANSYS_CI_BOT_TOKEN }}
- name: Create .netrc
run: |
printf "machine github.com\n\
login pyansys-ci-bot\n\
password ${{ secrets.PYANSYS_CI_BOT_TOKEN }}\n"\ >> ./.netrc
chmod 600 ./.netrc
- name: Image and docker properties
id: props
run: |
echo "image=rep-repo-template-${{ matrix.image }}:${{github.run_id}}" >> $GITHUB_OUTPUT
echo "container=rep-repo-template-${{ matrix.image }}-${{github.run_id}}" >> $GITHUB_OUTPUT
echo "revision=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
echo "short_revision=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Build image
uses: docker/build-push-action@v3
with:
push: false
context: .
tags: ${{ steps.props.outputs.image }}
file: docker/Dockerfile.${{ matrix.image }}
secret-files: |
"netrc=./.netrc"
outputs: type=docker,dest=/tmp/rep-repo-template-${{ matrix.image }}-image.tar
cache-from: type=gha
cache-to: type=gha,mode=max
secrets: |
GIT_AUTH_TOKEN=${{ secrets.PYANSYS_CI_BOT_TOKEN }}
build-args: |
branch=${{github.ref_name}}
revision=${{steps.props.outputs.revision}}
short_revision=${{steps.props.outputs.short_revision}}
- name: Load images
run: |
docker load --input /tmp/rep-repo-template-${{ matrix.image }}-image.tar
- name: Get binary
id: get-binary
run: |
docker image ls
docker run -d --name ${{ steps.props.outputs.container }} ${{ steps.props.outputs.image }}
docker cp ${{ steps.props.outputs.container }}:/app/rep-repo-template ./rep-repo-template-${{ matrix.image }}
chmod +x ./rep-repo-template-${{ matrix.image }}
- name: Test binary
run: |
version=$(docker exec ${{ steps.props.outputs.container }} /app/rep-repo-template)
echo "$version"
echo "$version" >> $GITHUB_STEP_SUMMARY
- name: Stop container
if: ${{ always() }}
run: |
docker container stop ${{steps.props.outputs.container}}
# - name: Upload image
# uses: actions/upload-artifact@v3
# with:
# name: rep-repo-template-${{ matrix.image }}-image
# path: /tmp/rep-repo-template-${{ matrix.image }}-image.tar
# retention-days: 1
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: rep-repo-template-${{matrix.image}}
path: rep-repo-template-${{matrix.image}}
freeze-windows:
name: Freeze (windows)
runs-on:
group: "Default Larger Runners"
labels: windows-latest-8-cores
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.freeze_windows == 'true' }}
needs: [wheels, style]
steps:
- uses: actions/checkout@v3
- name: ccache
uses: hendrikmuhs/[email protected]
- name: Set up python
uses: actions/setup-python@v4
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}
cache: 'pip'
cache-dependency-path: |
requirements/requirements_*.txt
**/setup.py
- uses: extractions/netrc@v1
with:
machine: github.com
username: pyansys-ci-bot
password: ${{ secrets.PYANSYS_CI_BOT_TOKEN }}
- name: Prepare venv
run: |
python -m venv dev_env
dev_env\Scripts\python build.py dev
- name: Freeze
run: |
dev_env\Scripts\python build.py dist
# - name: Test binary
# run: |
# ./freeze/build/rep-repo-template.exe --version
# $version = (./freeze/build/rep-repo-template.exe --version) | Out-String
# echo "$version"
# echo "$version" >> $env:GITHUB_STEP_SUMMARY
# - name: Setup tmate session
# if: ${{ failure() && github.event_name == 'workflow_dispatch' && inputs.ssh_enabled }}
# uses: mxschmitt/action-tmate@v3
# with:
# ## limits ssh access and adds the ssh public key for the user which triggered the workflow
# limit-access-to-actor: true
# ## limits ssh access and adds the ssh public keys of the listed GitHub users
# # limit-access-to-users: [username]
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: rep-repo-template-windows
path: freeze/build/rep-repo-template.exe
release:
name: Create release
uses: ansys-internal/rep-job-management/.github/workflows/release.yml@main
needs: ['freeze','wheels','tests']
secrets: inherit
with:
tag: v${{ needs.wheels.outputs.version }}
force_release: ${{ github.event.inputs.force_release == 'true' }}
artifact: .*rep-launcher-service.*
files: |
/tmp/bin/*/*.whl
/tmp/bin/*/rep-launcher-service-*