forked from libsbmlsim/libsbmlsim
-
Notifications
You must be signed in to change notification settings - Fork 0
242 lines (215 loc) · 10.4 KB
/
Copy pathreleaseToBioSimulators.yml
File metadata and controls
242 lines (215 loc) · 10.4 KB
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
name: Build test BioSimulators interface and release to BioSimulators registry
on:
push:
jobs:
buildTestDeploy:
name: Build, test, and deploy BioSimulators interface
runs-on: ubuntu-latest
steps:
#############################################
## Checkout repository
#############################################
- name: Clone repository
run: |
git clone https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} .
- id: get-main-branch
name: Determine main branch
run: |
mainBranch=$(git symbolic-ref refs/remotes/origin/HEAD | cut -d '/' -f 4)
mainBranchHeadRevision=$(git rev-parse refs/remotes/origin/${mainBranch})
echo "::set-output name=mainBranch::$mainBranch"
echo "::set-output name=mainBranchRef::refs/heads/$mainBranch"
echo "::set-output name=mainBranchHeadRevision::$mainBranchHeadRevision"
- name: Checkout ref
run: |
if [[ "${{ github.ref }}" =~ ^refs/heads/ ]]; then
branch=$(echo "${{ github.ref }}" | cut -d'/' -f 3-)
git checkout ${branch}
else
git checkout ${{ github.ref }}
fi
#############################################
## Install package and its dependencies
#############################################
- name: Install Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: Setup pip cache
uses: actions/cache@v2
with:
path: /opt/hostedtoolcache/Python
key: ${{ runner.os }}-pip-${{ hashFiles('biosimulators/requirements.txt') }}-${{ hashFiles('biosimulators/requirements.optional.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install pip and setuptools
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
#############################################
## Lint
#############################################
- name: Install flake8
run: python -m pip install flake8
- name: Lint the package
working-directory: biosimulators
run: python -m flake8
#############################################
## Get and sync version number
#############################################
- id: get-version-number
name: Get version number
run: |
SIMULATOR_VERSION=$(cat src/libsbmlsim/version.h | grep LIBSBMLSIM_DOTTED_VERSION | cut -d '"' -f 2)
echo "::set-output name=simulatorVersion::$SIMULATOR_VERSION"
VERSION=$(cat biosimulators/biosimulators_libsbmlsim/_version.py | grep __version__ | cut -d "'" -f 2)
echo "::set-output name=version::$VERSION"
#############################################
## Build Docker image
#############################################
- name: Build Docker image
run: |
REVISION=$(git rev-parse HEAD)
CREATED=$(date --rfc-3339=seconds | sed 's/ /T/')
docker build \
--label org.opencontainers.image.source=https://github.com/${{ github.repository }} \
--label org.opencontainers.image.revision=${REVISION} \
--label org.opencontainers.image.created=${CREATED} \
--build-arg VERSION=${{ steps.get-version-number.outputs.version }} \
--build-arg SIMULATOR_VERSION=${{ steps.get-version-number.outputs.simulatorVersion }} \
--tag ghcr.io/biosimulators/biosimulators_libsbmlsim/libsbmlsim:${{ steps.get-version-number.outputs.simulatorVersion }} \
--tag ghcr.io/biosimulators/biosimulators_libsbmlsim/libsbmlsim:latest \
-f biosimulators/Dockerfile \
.
#############################################
## Test
#############################################
- name: Run the tests
run: |
cwd=$(pwd)
docker run \
--rm \
--entrypoint bash \
--mount type=bind,source=${cwd},target=/root/Biosimulators_LibSBMLSim \
--workdir /root/Biosimulators_LibSBMLSim/biosimulators \
ghcr.io/biosimulators/biosimulators_libsbmlsim/libsbmlsim:latest \
-c "
pip install pytest pytest-cov \
&& pip install -r tests/requirements.txt \
&& python -m pytest tests/ --cov biosimulators_libsbmlsim --cov-report=xml
"
sudo chown ${UID} ./biosimulators/coverage.xml
- name: Upload the coverage report to Codecov
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: unittests
file: ./biosimulators/coverage.xml
#############################################
## Compile documentation
#############################################
- name: Compile documentation
run: |
cwd=$(pwd)
docker run \
--rm \
--entrypoint bash \
--mount type=bind,source=${cwd},target=/root/Biosimulators_LibSBMLSim \
--workdir /root/Biosimulators_LibSBMLSim/biosimulators \
ghcr.io/biosimulators/biosimulators_libsbmlsim/libsbmlsim:1.4.0 \
-c "
pip install -r docs-src/requirements.txt \
&& sphinx-apidoc . setup.py --output-dir docs-src/source --force --module-first --no-toc \
&& mkdir -p docs-src/_static \
&& sphinx-build docs-src ../docs
"
sudo chown ${UID} -R docs
sudo chown ${UID} -R biosimulators/docs-src
#############################################
## Release
#############################################
# If new tag, commit and push documentation
- id: commit-docs
name: Commit the compiled documentation
if: startsWith(github.ref, 'refs/tags/')
run: |
git config --local user.email "biosimulators.daemon@gmail.com"
git config --local user.name "biosimulatorsdaemon"
git config pull.rebase false
git stash
git checkout ${{ steps.get-main-branch.outputs.mainBranch }}
git pull
set +e
git stash pop
git add docs
git commit -m "Updating compiled documentation"
git checkout .
git clean -f -d
if [[ $? = 0 ]]; then
docsChanged=1
else
docsChanged=0
fi
echo "::set-output name=docsChanged::$docsChanged"
- name: Push the compiled documentation
if: startsWith(github.ref, 'refs/tags/') && steps.commit-docs.outputs.docsChanged == '1'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ steps.get-main-branch.outputs.mainBranch }}
# Create GitHub release
- name: Create GitHub release
if: startsWith(github.ref, 'refs/tags/')
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get-version-number.outputs.version }}
release_name: Release ${{ steps.get-version-number.outputs.version }}
# Create PyPI release
- name: Create PyPI release
if: startsWith(github.ref, 'refs/tags/')
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
working-directory: biosimulators
run: |
# Install pandoc
sudo apt-get update -y
sudo apt-get install -y --no-install-recommends wget
wget https://github.com/jgm/pandoc/releases -O /tmp/pandocVersions.html
urlPart=`grep "\.deb" /tmp/pandocVersions.html | head -n 1 | cut -d'/' -f2-7 | cut -d'"' -f1`
wget "https://github.com/$urlPart" -O /tmp/pandoc.deb
sudo dpkg -i /tmp/pandoc.deb
rm /tmp/pandocVersions.html
rm /tmp/pandoc.deb
# Convert README to .rst format
pandoc --from=gfm --output=README.rst --to=rst README.md
# Install twine
python -m pip install wheel twine
# Create packages to upload to PyPI
python setup.py sdist
python setup.py bdist_wheel
# Upload packages to PyPI
twine upload dist/*
# build Docker image and push to GitHub Container Registry
- name: Push Docker image
if: startsWith(github.ref, 'refs/tags/')
run: |
docker login ghcr.io \
--username ${{ secrets.GHCR_USERNAME }} \
--password ${{ secrets.GHCR_TOKEN }}
docker push ghcr.io/biosimulators/biosimulators_libsbmlsim/libsbmlsim:${{ steps.get-version-number.outputs.simulatorVersion }}
docker push ghcr.io/biosimulators/biosimulators_libsbmlsim/libsbmlsim:latest
# Submit to BioSimulators registry
- name: Submit to BioSimulators registry
if: startsWith(github.ref, 'refs/tags/')
run: |
REVISION=$(git rev-parse HEAD)
IMAGE_DIGEST=$(docker image inspect ghcr.io/biosimulators/biosimulators_libsbmlsim/libsbmlsim:${{ steps.get-version-number.outputs.simulatorVersion }} | jq -r '.[0].RepoDigests[0]' | cut -d "@" -f 2-)
curl \
-X POST \
-u ${{ secrets.BIOSIMULATORS_GH_USERNAME }}:${{ secrets.BIOSIMULATORS_GH_TOKEN }} \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/biosimulators/Biosimulators/issues \
-d "{\"labels\": [\"Validate/submit simulator\"], \"title\": \"Submit LibSBMLsim ${{ steps.get-version-number.outputs.simulatorVersion }}\", \"body\": \"---\nid: libsbmlsim\nversion: ${{ steps.get-version-number.outputs.simulatorVersion }}\nspecificationsUrl: https://raw.githubusercontent.com/${{ github.repository }}/${REVISION}/biosimulators.json\nspecificationsPatch:\n version: ${{ steps.get-version-number.outputs.simulatorVersion }}\n image:\n url: ghcr.io/biosimulators/biosimulators_libsbmlsim/libsbmlsim:${{ steps.get-version-number.outputs.simulatorVersion }}\n digest: \\\"${IMAGE_DIGEST}\\\"\nvalidateImage: true\ncommitSimulator: true\n\n---\"}"