-
Notifications
You must be signed in to change notification settings - Fork 1
423 lines (392 loc) · 15.4 KB
/
build.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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
name: Build workflow-testing
on:
push:
branches:
- "**"
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
pull_request:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
trigger:
# store trigger reason
runs-on: ubuntu-latest
outputs:
is_release: ${{ steps.reason.outputs.is_release }}
is_push_on_default_branch: ${{ steps.reason.outputs.is_push_on_default_branch }}
steps:
- id: reason
run: |
echo "is_release=${{ startsWith(github.ref, 'refs/tags/v') }}" >> $GITHUB_OUTPUT
echo "is_push_on_default_branch=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}" >> $GITHUB_OUTPUT
only-on-master:
needs: [trigger]
runs-on: ubuntu-latest
if: needs.trigger.outputs.is_push_on_default_branch == 'true'
outputs:
notebooks-branch: ${{ steps.write-output.outputs.notebooks_branch }}
steps:
- id: write-output
run: |
echo "yo"
echo "notebooks_branch=toto" >> $GITHUB_OUTPUT
on-all-branches:
needs: only-on-master
runs-on: ubuntu-latest
if: always()
steps:
- run: echo yo ${{ needs.only-on-master.outputs.notebooks-branch }}
testing-file-existence:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
minizinc_prerequisites_cmdline: [""]
steps:
- name: prerequisites
run: |
${{ matrix.minizinc_prerequisites_cmdline }}
- name: Check if coverage report exists
id: check-cov
run: |
if [ -f coverage.xml ]; then
coverage_exists=true
else
coverage_exists=false
fi
echo ${coverage_exists}
echo "coverage_exists=${coverage_exists}" >> $GITHUB_OUTPUT
- name: test output previous step
run: |
echo ${{ steps.check-cov.outputs.coverage_exists }}
echo ${{ steps.check-cov.outputs.coverage_exists == 'true' }}
- name: Export coverage report (if existing)
if: steps.check-coverage-report.ouputs.coverage_exists == 'true'
run: echo "exporting"
- name: Check if coverage report exists II
id: check-coverage-report
run: |
touch coverage.xml
if [ -f coverage.xml ]; then
coverage_exists=true
else
coverage_exists=false
fi
echo ${coverage_exists}
echo "coverage_exists=${coverage_exists}" >> $GITHUB_OUTPUT
- name: test output previous step
run: |
echo ${{ steps.check-coverage-report.outputs.coverage_exists }}
echo ${{ steps.check-coverage-report.outputs.coverage_exists == 'true' }}
- name: Export coverage report (if existing) II
if: steps.check-coverage-report.outputs.coverage_exists == 'true'
run: echo "exporting"
pwd:
runs-on: ubuntu-latest
steps:
- run: |
pwd
echo $HOME
build:
runs-on: ubuntu-latest
needs: [trigger]
outputs:
do_version: ${{ steps.get_wheel_version.outputs.version }}
steps:
- name: get wheel version and save it
id: get_wheel_version
run: |
if ${{ needs.trigger.outputs.is_release }}; then
version=${GITHUB_REF/refs\/tags\/v/} # stripping "refs/tags/v"
else
version="0.0.0"
fi
echo "version=$version"
echo "version=$version" >> $GITHUB_OUTPUT
deploy-master-doc:
# for default branch
needs: [trigger]
if: needs.trigger.outputs.is_push_on_default_branch == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Deploy documentation in a version subfolder on GH pages
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages # The branch the action should deploy to.
folder: docs # The folder the action should deploy.
target-folder: /${{ github.event.repository.default_branch }} # The folder the action should deploy to.
commit-message: publish documentation for ${{ github.event.repository.default_branch }}
single-commit: true
deploy-release-doc:
# for release tags
needs: [trigger, build]
if: needs.trigger.outputs.is_release == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Deploy documentation in a version subfolder on GH pages
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages # The branch the action should deploy to.
folder: docs # The folder the action should deploy.
target-folder: /${{ needs.build.outputs.do_version }} # The folder the action should deploy to.
commit-message: publish documentation for ${{ needs.build.outputs.do_version }}
single-commit: true
create-binder-env:
runs-on: ubuntu-latest
needs: [trigger, build]
env:
BINDER_ENV_REF: binder # default reference: binder branch
outputs:
binder_env_ref: ${{ steps.get_binder_env_ref.outputs.binder_env_ref }}
steps:
- name: Checkout binder branch
if: |
(needs.trigger.outputs.is_push_on_default_branch == 'true')
|| (needs.trigger.outputs.is_release == 'true')
uses: actions/checkout@v3
with:
ref: binder
- name: Update environment.yml
if: |
(needs.trigger.outputs.is_push_on_default_branch == 'true')
|| (needs.trigger.outputs.is_release == 'true')
run: |
if ${{ needs.trigger.outputs.is_release == 'true' }}; then
# RELEASE MODE
# Specify the proper discrete-optimization version
sed_replacement_pattern="\1- discrete-optimization==${{ needs.build.outputs.do_version }}"
if ${{ github.repository != 'airbus/discrete-optimization' && secrets.TEST_PYPI_API_TOKEN != '' }} == 'true'; then
# release to be deployed on TestPyPI
sed_replacement_pattern="${sed_replacement_pattern}\n\1- --extra-index-url https://test.pypi.org/simple/"
fi
sed_command="s|\(\s*\)-.*egg=discrete-optimization$|${sed_replacement_pattern}|"
echo $sed_command
sed -i -e "$sed_command" environment.yml
cat environment.yml
# Commit new environment
git config user.name "Actions"
git config user.email "actions@github.com"
git commit environment.yml -m "Specify binder environment for release ${{ needs.build.outputs.do_version }}"
# Get sha1 to be used by binder for the environment, update the binder env reference
echo "BINDER_ENV_REF=$(git rev-parse --verify HEAD)" >> $GITHUB_ENV
# Revert for the default branch binder env
git revert HEAD -n
git commit -m "Revert to binder environment for master branch"
else
# DEFAULT BRANCH MODE
# Specify the proper discrete-optimization version (current master sha1)
pip_spec="git+${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}@${GITHUB_SHA}#egg=discrete-optimization"
echo $pip_spec
sed -i -e "s|\(\s*\)-.*egg=discrete-optimization$|\1- ${pip_spec}|" environment.yml
cat environment.yml
# Commit new environment
git config user.name "Actions"
git config user.email "actions@github.com"
git commit environment.yml -m "Update binder environment for default branch"
fi
# Push binder branch with the updated environment
git push origin binder
- name: Checkout triggering branch to get the script pre-building the binder env
if: |
(needs.trigger.outputs.is_push_on_default_branch == 'true')
|| (needs.trigger.outputs.is_release == 'true')
uses: actions/checkout@v3
- name: Trigger a build on each BinderHub deployments in the mybinder.org federation
if: |
(needs.trigger.outputs.is_push_on_default_branch == 'true')
|| (needs.trigger.outputs.is_release == 'true')
run: |
echo Triggering binder environment build for ${GITHUB_REPOSITORY}/${BINDER_ENV_REF}
bash scripts/trigger_binder.sh https://gke.mybinder.org/build/gh/${GITHUB_REPOSITORY}/${BINDER_ENV_REF}
bash scripts/trigger_binder.sh https://ovh.mybinder.org/build/gh/${GITHUB_REPOSITORY}/${BINDER_ENV_REF}
bash scripts/trigger_binder.sh https://turing.mybinder.org/build/gh/${GITHUB_REPOSITORY}/${BINDER_ENV_REF}
bash scripts/trigger_binder.sh https://gesis.mybinder.org/build/gh/${GITHUB_REPOSITORY}/${BINDER_ENV_REF}
- name: Store binder env reference
id: get_binder_env_ref
run: |
echo "binder_env_ref=$BINDER_ENV_REF"
echo "binder_env_ref=$BINDER_ENV_REF" >> $GITHUB_OUTPUT
build-doc:
runs-on: ubuntu-latest
needs: create-binder-env
steps:
- name: Set env variables for github+binder links in doc
run: |
# binder environment repo and branch
AUTODOC_BINDER_ENV_GH_REPO_NAME="${GITHUB_REPOSITORY}"
AUTODOC_BINDER_ENV_GH_BRANCH="${{ needs.create-binder-env.outputs.binder_env_ref }}"
# notebooks source repo and branch depending if it is a commit push or a PR
if [[ $GITHUB_REF == refs/pull* ]];
then
AUTODOC_NOTEBOOKS_REPO_URL="${GITHUB_SERVER_URL}/${{ github.event.pull_request.head.repo.full_name }}"
AUTODOC_NOTEBOOKS_BRANCH=${GITHUB_HEAD_REF}
elif [[ $GITHUB_REF == refs/heads* ]];
then
AUTODOC_NOTEBOOKS_REPO_URL=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}
AUTODOC_NOTEBOOKS_BRANCH=${GITHUB_REF/refs\/heads\//}
fi
# export in GITHUB_ENV for next steps
echo "AUTODOC_BINDER_ENV_GH_REPO_NAME=${AUTODOC_BINDER_ENV_GH_REPO_NAME}" >> $GITHUB_ENV
echo "AUTODOC_BINDER_ENV_GH_BRANCH=${AUTODOC_BINDER_ENV_GH_BRANCH}" >> $GITHUB_ENV
echo "AUTODOC_NOTEBOOKS_REPO_URL=${AUTODOC_NOTEBOOKS_REPO_URL}" >> $GITHUB_ENV
echo "AUTODOC_NOTEBOOKS_BRANCH=${AUTODOC_NOTEBOOKS_BRANCH}" >> $GITHUB_ENV
# check computed variables
echo "Binder env: ${AUTODOC_BINDER_ENV_GH_REPO_NAME}/${AUTODOC_BINDER_ENV_GH_BRANCH}"
echo "Notebooks source: ${AUTODOC_NOTEBOOKS_REPO_URL}/tree/${AUTODOC_NOTEBOOKS_BRANCH}"
job_see_trigger:
runs-on: ubuntu-latest
needs: trigger
steps:
- run: |
echo ${{ needs.trigger.outputs.is_release }}
echo ${{ needs.trigger.outputs.is_push_on_default_branch }}
if ${{ needs.trigger.outputs.is_release }}; then echo this is a release; fi
if ${{ needs.trigger.outputs.is_push_on_default_branch }}; then echo this is a push on default branch; fi
job_only_release:
runs-on: ubuntu-latest
needs: trigger
if: needs.trigger.outputs.is_release == 'true'
steps:
- run: |
echo this is a release
job_only_default_branch:
runs-on: ubuntu-latest
needs: trigger
if: needs.trigger.outputs.is_push_on_default_branch == 'true'
steps:
- run: |
echo this is a push on default branch
job_only_default_branch_or_release:
runs-on: ubuntu-latest
needs: trigger
if: |
(needs.trigger.outputs.is_push_on_default_branch == 'true')
|| (needs.trigger.outputs.is_release == 'true')
steps:
- run: |
if ${{ needs.trigger.outputs.is_release }}; then echo this is a release; fi
if ${{ needs.trigger.outputs.is_push_on_default_branch }}; then echo this is a push on default branch; fi
job0:
if: true
runs-on: ubuntu-latest
steps:
- run: echo called
job1:
if: false
needs: job0
runs-on: ubuntu-latest
steps:
- run: echo never called
job2:
if: true
runs-on: ubuntu-latest
steps:
- run: echo never called
job12:
needs: [job1, job2]
if: |
always()
&& (
(needs.job1.result == 'success')
|| (needs.job2.result == 'success')
)
runs-on: ubuntu-latest
steps:
- run: |
echo ${{ needs.job1.result }}
echo ${{ needs.job2.result }}
echo ${{ contains(needs.*.result, 'success') }}
job_for_tags_and_default:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v') || github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
steps:
- name: Get doc version name
run: |
if [ ${GITHUB_REF} = refs/heads/${{ github.event.repository.default_branch }} ]; then
VERSION=${{ github.event.repository.default_branch }}
else
VERSION=${GITHUB_REF/refs\/tags\/v/} # stripping "refs/tags/v"
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: test it
run: echo $VERSION
job_depending_on_skipped_test:
runs-on: ubuntu-latest
steps:
- run: echo should not run
job_only_on_default1:
runs-on: ubuntu-latest
if: $${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
steps:
- run: echo should work only on default
job_only_on_default2:
runs-on: ubuntu-latest
if: ${{ github.ref }} == refs/heads/${{ github.event.repository.default_branch }}
steps:
- run: echo should work only on default 2
job_only_on_default3:
runs-on: ubuntu-latest
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
steps:
- run: echo should work only on default
build2:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v2
- name: Install build dependencies
run: pip install -U setuptools wheel
- name: Update version number according to pushed tag
if: startsWith(github.ref, 'refs/tags/v')
run: |
TAG_NAME=${GITHUB_REF/refs\/tags\//} # stripping "refs/tags/"
VERSION=${TAG_NAME/v/} # stripping "v"
echo $VERSION
# Replace in-place version number in package __init__.py, also used by setup.py
sed -i -e "s/^__version__\s*=.*$/__version__ = \"${VERSION}\"/g" workflow_testing/__init__.py
cat workflow_testing/__init__.py
- name: Build workflow_testing wheel
run: python setup.py bdist_wheel
- name: Upload as build artifacts
uses: actions/upload-artifact@v2
with:
name: wheels
path: dist/*.whl
test:
runs-on: windows-2022
needs: [build2]
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.8"
- name: Download wheels artifact
uses: actions/download-artifact@v1.0.0
with:
name: wheels
- name: install the library
run: |
python -m pip install wheels/workflow_testing*.whl
- run: |
chmod +x bin/hello
cd ..
minizinc_path=$(python -c "import workflow_testing, os; print(os.path.abspath(workflow_testing.__path__[0]))")
cd -
echo $minizinc_path
cygpath --unix $minizinc_path
minizinc_path=$(cygpath --unix $minizinc_path)
echo $minizinc_path
mv bin/hello $minizinc_path
ls $minizinc_path
export PATH=$minizinc_path:$PATH
echo $PATH
hello