-
Notifications
You must be signed in to change notification settings - Fork 26
194 lines (175 loc) · 6.86 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
name: Build and Deploy
on:
workflow_dispatch:
inputs:
upload_anaconda:
description: 'Upload build to anaconda'
required: false
default: 'skip'
type: choice
options:
- 'pre-release'
- 'main'
- 'skip'
upload_pypi:
description: 'Upload build to pypi'
required: false
default: false
type: boolean
deploy_docs:
description: 'Deploy docs to github pages'
required: false
default: false
type: boolean
env:
PACKAGE_NAME: pymer4
DEPLOY_PY_VER: 3.8 # only this job runner deploys docs and pypi package
DEPLOY_OS: ubuntu-latest
CONDA_BLD_PATH: /tmp/ci_conda_bld
defaults:
run:
# login shell to source the conda hook in .bash_profile
shell:
bash -l {0}
jobs:
ci:
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: true
matrix:
py_ver: [3.8, 3.9, '3.10', 3.11]
os: [ubuntu-latest, macos-latest]
experimental: [true]
outputs:
# tarballs are py3X job-specific
conda-tarball: ${{ steps.conda-bld.outputs.conda-tarball }}
steps:
# ------------------------------------------------------------
# 0. Print some basic github action info
- name: diagnostic info
run: |
echo "OS: ${{ matrix.os }}"
echo "Python: ${{ matrix.py_ver }}"
echo "Conda build path: $CONDA_BLD_PATH"
echo "Deploy OS: $DEPLOY_OS"
echo "Deploy Python: $DEPLOY_PY_VER"
echo "GA event name: ${{ github.event_name }}"
echo "GA ref: ${{ github.ref }}"
# ------------------------------------------------------------
# Step up miniconda
- name: Download Miniconda
uses: conda-incubator/setup-miniconda@059455a698430d8b68fa317268fa2e3da3492a98
with:
miniconda-version: "latest"
python-version: ${{ matrix.py_ver }}
# ------------------------------------------------------------
# Get code
- name: Checkout code
uses: actions/checkout@v2
# ------------------------------------------------------------
# Setup conda build environment and build package
# env defined here are just for convenience when writing bash commands
- name: Setup and build package
env:
OS: ${{ runner.os }}
PY_VER: ${{ matrix.py_ver }}
run: |
conda config --set always_yes yes --set changeps1 no
conda config --set bld_path $CONDA_BLD_PATH
conda install -n base -q conda-build
conda deactivate
echo "# ----------------BUILDING---------------------------------"
conda config --show | grep bld_path
conda info
conda-build ./conda/ --python=$PY_VER -c https://conda.anaconda.org/conda-forge/ --verify
tarball=$(conda-build --python=$PY_VER conda --output | tail -1)
echo "conda build tarball" $tarball
if [[ $OS == "Linux" ]]; then \
conda convert -p win-64 -o $CONDA_BLD_PATH $tarball; \
fi
echo "{conda-tarball}={$tarball}" >> $GITHUB_OUTPUT
# ------------------------------------------------------------
# Create new conda env and install package locally
# Test installation worked
# Get black and pytest from pip because black version on conda lags behind
- name: Test installation
env:
PY_VER: ${{ matrix.py_ver }}
run: |
conda create -n env_$PY_VER python=$PY_VER $PACKAGE_NAME -c $CONDA_BLD_PATH -c conda-forge -c defaults
conda activate env_$PY_VER
conda info | grep active
pip install -r requirements-dev.txt
python -c "from pymer4.test_install import test_install; test_install()"
# 4. Run code tests
- name: Run Test Suite
env:
PY_VER: ${{ matrix.py_ver }}
run: |
conda activate env_$PY_VER
conda info | grep active
black --version
black --check --verbose .
pytest pymer4/tests
# 5a. Build docs (only for 3.8 which handles deployment)
# Will also run on PRs which serves as another layer of testing
- name: Build docs
env:
PY_VER: ${{ matrix.py_ver }}
if: ${{ matrix.py_ver == env.DEPLOY_PY_VER && matrix.os == env.DEPLOY_OS }}
run: |
conda activate env_$PY_VER
conda info | grep active
conda install sphinx sphinx_bootstrap_theme sphinx-gallery -c conda-forge
cd docs && make clean && make html
touch _build/html/.nojekyll
# 5b. Deploy docs
# Only runs on the 3.8 runner when there's a release
- name: Deploy docs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: ${{ (matrix.py_ver == env.DEPLOY_PY_VER && matrix.os == env.DEPLOY_OS) && (github.event_name == 'release' || inputs.deploy_docs)}}
uses: crazy-max/ghaction-github-pages@v2
with:
target_branch: gh-pages
build_dir: docs/_build/html
# 6. Build package for PyPi
# Only runs on the 3.8 runner
- name: Build for Pypi
env:
PY_VER: ${{ matrix.py_ver }}
if: ${{ matrix.py_ver == env.DEPLOY_PY_VER && matrix.os == env.DEPLOY_OS }}
run: |
conda activate env_$PY_VER
conda info | grep active
pip install build
python -m build --sdist --wheel --outdir dist/
# 7. Deploy package to Pypi
# Only runs on the 3.8 runner when there's a release
- name: PyPi deploy
if: ${{ (matrix.py_ver == env.DEPLOY_PY_VER && matrix.os == env.DEPLOY_OS) && (github.event_name == 'release' || inputs.upload_pypi)}}
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
# 8a. Deploy package to main conda main channel
# Runs when a github release is created, but can also be triggered manually
- name: Conda main deploy
if: ${{ (github.event_name == 'release') || (inputs.upload_anaconda == 'main') }}
env:
ANACONDA_TOKEN: ${{ secrets.ANACONDA_TOKEN }}
run: |
echo 'Conda release on main channel'
conda install anaconda-client
anaconda -t "$ANACONDA_TOKEN" upload $CONDA_BLD_PATH/**/${PACKAGE_NAME}*.tar.bz2 -l "main"
# OR -----
# 8b. Deploy package to pre-release conda channel
# Only runs when triggered manually
- name: Conda pre-release deploy
if: ${{ inputs.upload_anaconda == 'pre-release' }}
env:
ANACONDA_TOKEN: ${{ secrets.ANACONDA_TOKEN }}
run: |
echo 'Conda release on pre-release channel'
conda install anaconda-client
anaconda -t "$ANACONDA_TOKEN" upload $CONDA_BLD_PATH/**/${PACKAGE_NAME}*.tar.bz2 -l "pre-release"