-
Notifications
You must be signed in to change notification settings - Fork 5
355 lines (341 loc) · 13.7 KB
/
main.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
name: CI
on:
workflow_dispatch:
inputs:
incoming_ref:
description: >
The ref from Cantera/cantera to be built. Can be a tag, commit hash,
or branch name.
required: true
default: "main"
upload:
description: Attempt to upload to Anaconda
required: true
default: "false"
concurrency:
group: ${{ github.ref }}-${{ github.event.inputs.incoming_ref }}
cancel-in-progress: true
env:
MW_HEADERS_DIR: ${{ github.workspace }}/../mw_headers
MACOSX_DEPLOYMENT_TARGET: "10.15"
ACTION_URL: "https://github.com/Cantera/conda-recipes/actions/runs/${{ github.run_id }}"
INCOMING_REF: ${{ github.event.inputs.incoming_ref }}
jobs:
dump:
name: Dump the input parameters for the workflow
runs-on: ubuntu-22.04
steps:
- name: Dump Event Payload
run: jq . "$GITHUB_EVENT_PATH"
- name: Echo the incoming_ref
run: |
echo "${{ github.event.inputs.incoming_ref }}"
echo "${{ github.event.inputs.upload }}"
post-pending-status:
name: Post a pending workflow status to Cantera/cantera
runs-on: ubuntu-22.04
if: github.repository == 'Cantera/conda-recipes'
env:
GITHUB_TOKEN: ${{ secrets.CANTERA_REPO_STATUS }}
outputs:
incoming-sha: ${{ steps.get-incoming-sha.outputs.incoming-sha }}
tag-ref: ${{ steps.munge-incoming-ref.outputs.tag-ref }}
steps:
- name: Munge the incoming ref
id: munge-incoming-ref
run: |
import os
import re
from pathlib import Path
INCOMING_REF = "${{ github.event.inputs.incoming_ref }}"
INCOMING_SHA = ""
if INCOMING_REF.startswith("refs/"):
INCOMING_REF = INCOMING_REF.replace("refs/", "")
elif re.match(r"^v\d\.\d\.\d.*$", INCOMING_REF) is not None:
INCOMING_REF = f"tags/{INCOMING_REF}"
elif re.match(r"^[a-f0-9]{6,40}", INCOMING_REF) is not None:
INCOMING_SHA = INCOMING_REF
else:
INCOMING_REF = f"heads/{INCOMING_REF}"
TAG_REF = "false"
if INCOMING_REF.startswith("tags"):
TAG_REF = "true"
Path(os.environ["GITHUB_ENV"]).write_text(
f"INCOMING_REF={INCOMING_REF}\n"
f"TAG_REF={TAG_REF}\n"
f"INCOMING_SHA={INCOMING_SHA}"
)
with open(os.environ["GITHUB_OUTPUT"], "a") as gh_out:
gh_out.write(f"tag-ref={TAG_REF}\n")
shell: python
- name: Get the SHA associated with the incoming ref
id: get-incoming-sha
run: |
if [[ "${INCOMING_SHA}" == "" ]]; then
INCOMING_SHA=$(gh api repos/cantera/cantera/git/matching-refs/${INCOMING_REF} \
-H "Accept: application/vnd.github.v3+json" --jq ".[0].object.sha")
echo "INCOMING_SHA=${INCOMING_SHA}" >> $GITHUB_ENV
fi
# This needs to be in this step to be output to other jobs.
echo "incoming-sha=${INCOMING_SHA}" >> $GITHUB_OUTPUT
- name: Post the status to the upstream commit
id: set-the-status
if: env.TAG_REF == 'false'
run: |
gh api repos/cantera/cantera/statuses/${INCOMING_SHA} \
-H "Accept: application/vnd.github.v3+json" \
--field state='pending' \
--field target_url=$ACTION_URL \
--field context='Conda Package Build' \
--field description="Pending build" \
--silent
# build-libcantera-and-python:
# name: Lib and Python for ${{ matrix.os }}
# runs-on: ${{ matrix.os }}
# # Run this job even if post-pending-status was skipped
# if: always()
# needs:
# - "post-pending-status"
# strategy:
# matrix:
# os: [windows-2019, ubuntu-20.04, macos-13]
# fail-fast: false
# outputs:
# job-status: ${{ job.status }}
# defaults:
# run:
# shell: bash -l {0}
# steps:
# - name: Check out this repository
# uses: actions/checkout@v4
# - name: Set up macOS SDK
# id: setup-macos-sdk
# uses: ./.github/actions/setup_macos
# with:
# macos-sdk-version: ${{ env.MACOSX_DEPLOYMENT_TARGET }}
# if: runner.os == 'macOS'
# - name: Append to conda build config
# if: runner.os == 'macOS'
# run: |
# echo "" >> ./.ci_support/conda_build_config.yaml
# echo "CONDA_BUILD_SYSROOT:" >> ./.ci_support/conda_build_config.yaml
# echo "- ${CONDA_BUILD_SYSROOT}" >> ./.ci_support/conda_build_config.yaml
# echo "" >> ./.ci_support/conda_build_config.yaml
# env:
# CONDA_BUILD_SYSROOT: ${{ steps.setup-macos-sdk.outputs.conda-build-sysroot }}
# - name: Set Up Conda
# uses: conda-incubator/[email protected]
# with:
# auto-update-conda: true
# conda-build-version: '3.25'
# activate-environment: ''
# auto-activate-base: true
# # Released 2023-04-24
# miniconda-version: 'py310_23.3.1-0'
# - name: Install Conda dependencies
# run: conda install -q conda-verify\<4.0 ripgrep
# - name: Build the Python and libcantera recipe
# run: conda build --debug ./cantera -m ./.ci_support/conda_build_config.yaml
# - name: List package contents
# run: |
# find '${{ runner.os == 'Windows' && '/c/Miniconda3' || env.CONDA }}/conda-bld' -name \*cantera\*.tar.bz2 | while read -r file; do
# echo '*********************************************'
# echo Contents of $file:
# echo '*********************************************'
# tar -tvf $file || true
# done
# shell: bash
# - name: Archive the built packages
# uses: actions/upload-artifact@v3
# with:
# path: ${{ env.CONDA }}/conda-bld/*/*cantera*.tar.bz2
# name: conda-packages
build-matlab:
name: Matlab toolbox for ${{ matrix.os }}
runs-on: ${{ matrix.os }}
# Run this job even if post-pending-status was skipped
if: always()
needs:
- "post-pending-status"
strategy:
matrix:
os: [windows-2019, ubuntu-20.04, macos-13]
fail-fast: false
outputs:
job-status: ${{ job.status }}
defaults:
run:
shell: bash -l {0}
steps:
- name: Check out this repository
uses: actions/checkout@v4
- name: Set up macOS SDK
id: setup-macos-sdk
uses: ./.github/actions/setup_macos
with:
macos-sdk-version: ${{ env.MACOSX_DEPLOYMENT_TARGET }}
if: runner.os == 'macOS'
- name: Append to conda build config
if: runner.os == 'macOS'
run: |
echo "" >> ./.ci_support/conda_build_config.yaml
echo "CONDA_BUILD_SYSROOT:" >> ./.ci_support/conda_build_config.yaml
echo "- ${CONDA_BUILD_SYSROOT}" >> ./.ci_support/conda_build_config.yaml
echo "" >> ./.ci_support/conda_build_config.yaml
env:
CONDA_BUILD_SYSROOT: ${{ steps.setup-macos-sdk.outputs.conda-build-sysroot }}
- name: Set Up Conda
uses: conda-incubator/[email protected]
with:
auto-update-conda: true
conda-build-version: '3.25'
activate-environment: ''
auto-activate-base: true
# Released 2023-04-24
miniconda-version: 'py310_23.3.1-0'
channels: defaults,cantera
- name: Install Conda dependencies
run: conda install -q conda-verify\<4.0 ripgrep
# The known_hosts key is generated with `ssh-keygen -F cantera.org` from a
# machine that has previously logged in to cantera.org and trusts
# that it logged in to the right machine
- name: Set up SSH key and host for cloning MATLAB
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.CTDEPLOY_SSH_KEY }}
known_hosts: ${{ secrets.CTDEPLOY_KNOWN_HOSTS }}
# If the version of rsync is changed, the directories below have to be updated
- name: Install rsync on Windows
if: runner.os == 'Windows'
run: choco install rsync --version 6.2.4
# This seems like overkill, but rsync on Windows requires a POSIX-style path
- name: Munge the MW_HEADERS_DIR for Windows rsync
run: |
import os
from pathlib import Path, PurePosixPath
mw_headers_dir = Path(os.environ["MW_HEADERS_DIR"]).resolve()
mw_headers_dir = PurePosixPath(
"/cygdrive",
mw_headers_dir.drive[0],
PurePosixPath(*mw_headers_dir.parts[1:])
)
with Path(os.environ["GITHUB_ENV"]).open(mode="a") as gh_env:
gh_env.write(f"CYG_MW_HEADERS_DIR={mw_headers_dir}")
shell: python
if: runner.os == 'Windows'
# When I tried this a few times, it only worked when I used powershell and had the
# SSH options all in the single line with single quotes. Note that there is a
# separate SSH binary pre-installed on the Windows runners that comes before this
# one on the PATH, but it is linked with the wrong Cygwin DLL, so it will not work.
- name: Get the MATLAB headers
if: runner.os == 'Windows'
run: |
rsync -azvP -e `
'C:\ProgramData\chocolatey\lib\rsync\tools\cwrsync_6.2.4_x64_free\bin\ssh.exe -i C:\Users\runneradmin\.ssh\id_rsa -o UserKnownHostsFile=C:\Users\runneradmin\.ssh\known_hosts' `
[email protected]:. $Env:CYG_MW_HEADERS_DIR
shell: powershell
- name: Get the MATLAB headers
if: runner.os != 'Windows'
run: "rsync -azvP [email protected]:. ${MW_HEADERS_DIR}"
- name: Build the MATLAB recipe
run: conda build --debug ./cantera-matlab -m ./.ci_support/conda_build_config.yaml
- name: List package contents
run: |
find '${{ runner.os == 'Windows' && '/c/Miniconda3' || env.CONDA }}/conda-bld' -name \*cantera\*.tar.bz2 | while read -r file; do
echo '*********************************************'
echo Contents of $file:
echo '*********************************************'
tar -tvf $file || true
done
shell: bash
- name: Archive the built packages
uses: actions/upload-artifact@v3
with:
path: ${{ env.CONDA }}/conda-bld/*/*cantera*.tar.bz2
name: conda-packages
publish-files-to-anaconda:
name: Publish to the Anaconda channel
runs-on: ubuntu-20.04
outputs:
job-status: ${{ job.status }}
needs:
# - "build-libcantera-and-python"
- "build-matlab"
defaults:
run:
shell: bash -l {0}
if: github.repository == 'Cantera/conda-recipes' && github.event.inputs.upload == 'true'
steps:
- name: Download pre-built packages
uses: actions/download-artifact@v3
with:
path: dist/
name: conda-packages
- name: Set Up Conda
uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
activate-environment: ''
auto-activate-base: true
- name: Install Conda dependencies
run: conda install -q anaconda-client
- name: Upload package to anaconda.org
run: |
anaconda --token ${{ secrets.ANACONDA_TOKEN }} upload dist/*/*.tar.bz2
send_status_to_cantera:
name: Send jobs status to Cantera/cantera
runs-on: ubuntu-20.04
needs:
- "post-pending-status"
# - "build-libcantera-and-python"
- "build-matlab"
- "publish-files-to-anaconda"
if: always() && github.repository == 'Cantera/conda-recipes'
steps:
- name: Collect statuses
run: |
from collections import Counter
import os
statuses = {
"python": "${{ needs.build-libcantera-and-python.outputs.job-status }}",
"publish": "${{ needs.publish-files-to-anaconda.outputs.job-status }}",
}
# This is a deliberate comparison to the empty string.
if statuses["publish"] == "" and "${{ github.event.inputs.upload }}" == "false":
publish = statuses.pop("publish")
if all(v == "success" for v in statuses.values()):
overall_status = "success"
elif any(v in ("cancelled", "") for v in statuses.values()):
overall_status = "error"
elif any(v == "failure" for v in statuses.values()):
overall_status = "failure"
status_counts = Counter(statuses.values())
description = []
if overall_status in ("error", "failure"):
if status_counts.get("success") is not None:
description.append(f"{status_counts['success']} succeeded")
if status_counts.get("cancelled") is not None:
description.append(f"{status_counts['cancelled']} cancelled")
if status_counts.get("failure") is not None:
description.append(f"{status_counts['failure']} failed")
if status_counts.get("") is not None:
description.append(f"{status_counts['']} skipped")
description = ", ".join(description)
else:
description = "Successfully built Conda packages!"
with open(os.environ["GITHUB_ENV"], "a") as gh_env:
gh_env.write(f"OVERALL_STATUS={overall_status}\nDESCRIPTION={description}")
shell: python
- name: Post the status to the upstream commit
if: needs.post-pending-status.outputs.tag-ref == 'false'
run: |
INCOMING_SHA=${{ needs.post-pending-status.outputs.incoming-sha }}
gh api repos/cantera/cantera/statuses/${INCOMING_SHA} \
-H "Accept: application/vnd.github.v3+json" \
--field state="${OVERALL_STATUS}" \
--field target_url=$ACTION_URL \
--field context='Conda Package Build' \
--field description="${DESCRIPTION}" \
--silent
env:
GITHUB_TOKEN: ${{ secrets.CANTERA_REPO_STATUS }}