Skip to content

Commit

Permalink
getting tellurium working again, updating to tellurium 2.2.0, startin…
Browse files Browse the repository at this point in the history
…g to modularize code
  • Loading branch information
jonrkarr committed Jan 5, 2021
1 parent bb1bd45 commit ce6a7fb
Show file tree
Hide file tree
Showing 16 changed files with 608 additions and 228 deletions.
333 changes: 333 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,333 @@
name: Continuous integration

on:
push:
workflow_dispatch:
inputs:
simulatorVersion:
description: New version of the underlying simulation tool (e.g., '1.5.6')
required: true
simulatorVersionLatest:
description: Is this version the latest version of the underlying simulation tool ("true" or "false")?
required: false

jobs:
continuousIntegration:
name: Update simulator version, lint, test, compile documentation, and release
runs-on: ubuntu-latest
outputs:
mainBranch: ${{ steps.get-main-branch.outputs.mainBranch }}
mainBranchRef: ${{ steps.get-main-branch.outputs.mainBranchRef }}
mainBranchHeadRevision: ${{ steps.get-main-branch.outputs.mainBranchHeadRevision }}
version: ${{ steps.get-version-number.outputs.version }}
simulatorId: ${{ steps.get-docker-image-tag.outputs.simulatorId }}
simulatorVersion: ${{ steps.get-docker-image-tag.outputs.simulatorVersion }}
simulatorName: ${{ steps.get-docker-image-tag.outputs.simulatorName }}
dockerImageBaseUrl: ${{ steps.get-docker-image-tag.outputs.dockerImageBaseUrl }}
dockerRegistry: ${{ steps.get-docker-image-tag.outputs.dockerRegistry }}
release: ${{ steps.determine-if-release-needed.outputs.release }}
docsChanged: ${{ steps.commit-docs.outputs.docsChanged }}
steps:
- 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
#############################################
## Update the version of the simulator
#############################################
- name: Update the version of the simulator
if: github.event.inputs.simulatorVersion
run: |
sudo apt-get update -y
sudo apt-get install -y --no-install-recommends jq moreutils
IMAGE_BASE_URL=$(jq -r '.image.url' biosimulators.json | cut -d : -f 1)
jq ".version = \"${{ github.event.inputs.simulatorVersion }}\"" biosimulators.json | sponge biosimulators.json
jq ".image.url = \"${IMAGE_BASE_URL}:${{ github.event.inputs.simulatorVersion }}\"" biosimulators.json | sponge biosimulators.json
sed -i -E \
"s/SIMULATOR_VERSION=([^ \n]+|\".*?\")/SIMULATOR_VERSION=\"${{ github.event.inputs.simulatorVersion }}\"/" \
Dockerfile
#############################################
## Install package and its dependencies
#############################################
- name: Install Python
uses: actions/setup-python@v2
with:
python-version: '3.7'

- name: Setup pip cache
uses: actions/cache@v2
with:
path: /opt/hostedtoolcache/Python
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}-${{ hashFiles('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
- name: Install libXML2
run: |
sudo apt-get update -y
sudo apt-get install -y -no-install-recommends libxml2
# install package
- name: Install the package
run: python -m pip install .[all]

#############################################
## Lint
#############################################
- name: Install flake8
run: python -m pip install flake8

- name: Lint the package
run: python -m flake8

#############################################
## Build Docker image
#############################################
- id: get-version-number
name: Get version number
env:
TAG: ${{ github.ref }}
run: |
if [[ "${TAG}" =~ ^refs/tags/ ]]; then
version="${TAG/refs\/tags\//}"
else
versionFileDir=$(find -name _version.py | rev | cut -d / -f 2- | rev)
version=$(PYTHONPATH=$versionFileDir python -c "import _version; print(_version.__version__)")
fi
echo "::set-output name=version::$version"
- id: get-docker-image-tag
name: Determine Docker image tag
run: |
sudo apt-get update -y
sudo apt-get install -y --no-install-recommends jq
SIMULATOR_ID=$(jq -r '.id' biosimulators.json)
SIMULATOR_VERSION=$(jq -r '.version' biosimulators.json)
SIMULATOR_NAME=$(jq -r '.name' biosimulators.json)
IMAGE_BASE_URL=$(jq -r '.image.url' biosimulators.json | cut -d : -f 1)
DOCKER_REGISTRY=$(echo $IMAGE_BASE_URL | cut -d / -f 1)
echo "::set-output name=simulatorId::${SIMULATOR_ID}"
echo "::set-output name=simulatorVersion::${SIMULATOR_VERSION}"
echo "::set-output name=simulatorName::${SIMULATOR_NAME}"
echo "::set-output name=dockerImageBaseUrl::${IMAGE_BASE_URL}"
echo "::set-output name=dockerRegistry::${DOCKER_REGISTRY}"
- 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-docker-image-tag.outputs.simulatorVersion }} \
--tag ${{ steps.get-docker-image-tag.outputs.dockerImageBaseUrl }}:${{ steps.get-docker-image-tag.outputs.simulatorVersion }} \
--tag ${{ steps.get-docker-image-tag.outputs.dockerImageBaseUrl }}:latest \
.
#############################################
## Test and upload coverage report to Codecov
#############################################
- name: Install pytest
run: python -m pip install pytest pytest-cov

- name: Install the requirements for the tests
run: python -m pip install .[tests]

- name: Run the tests
run: python -m pytest tests/ --cov=./ --cov-report=xml

- name: Upload the coverage report to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: unittests
file: ./coverage.xml

#############################################
## Compile documentation
#############################################
- name: Install the requirements for compiling the documentation
run: python -m pip install -r docs-src/requirements.txt

- name: Compile the documentation
run: |
sphinx-apidoc . setup.py --output-dir docs-src/source --force --module-first --no-toc
mkdir -p docs-src/_static
sphinx-build docs-src docs
#############################################
## Commit and push new version of simulator
#############################################
# If new version of simulator, commit and push the new version
- name: Commit the revised version of the simulator
if: github.event.inputs.simulatorVersion && github.event.inputs.simulatorVersionLatest == 'true'
run: |
git config --local user.email "[email protected]"
git config --local user.name "biosimulatorsdaemon"
git config pull.rebase false
git stash -- biosimulators.json Dockerfile
git clean -f -d
git checkout .
git pull
git stash pop
git add biosimulators.json Dockerfile
git commit -m "Updating version of simulator"
- name: Push the revised version of the simulator
if: github.event.inputs.simulatorVersion && github.event.inputs.simulatorVersionLatest == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}

#############################################
## Release
#############################################

- id: determine-if-release-needed
name: Determine if a release should be made
run: |
release="0"
if [ ! -z "${{ github.event.inputs.simulatorVersion }}" ]; then
if [ "${{ github.ref }}" == "${{ steps.get-main-branch.outputs.mainBranchRef }}" ]; then
release="1"
fi
fi
if [[ "${{ github.ref }}" =~ ^refs/tags/ ]]; then
tag_hash=$(git rev-parse "${{ github.ref }}")
if [ "$tag_hash" == "${{ steps.get-main-branch.outputs.mainBranchHeadRevision }}" ]; then
release="1"
fi
fi
echo "::set-output name=release::$release"
# If new tag, commit and push documentation
- id: commit-docs
name: Commit the compiled documentation
if: startsWith(github.ref, 'refs/tags/') && steps.determine-if-release-needed.outputs.release == '1'
run: |
git config --local user.email "[email protected]"
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.determine-if-release-needed.outputs.release == '1' && 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/') && steps.determine-if-release-needed.outputs.release == '1'
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/') && steps.determine-if-release-needed.outputs.release == '1'
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
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: steps.determine-if-release-needed.outputs.release == '1'
run: |
docker login ${{ steps.get-docker-image-tag.outputs.dockerRegistry }} \
--username ${{ secrets.DOCKER_REGISTRY_USERNAME }} \
--password ${{ secrets.DOCKER_REGISTRY_TOKEN }}
docker push ${{ steps.get-docker-image-tag.outputs.dockerImageBaseUrl }}:${{ steps.get-docker-image-tag.outputs.simulatorVersion }}
if [[ "${{ github.ref }}" =~ ^refs/tags/ ]] || [ "${{ github.event.inputs.simulatorVersionLatest }}" == "true" ]; then
docker push ${{ steps.get-docker-image-tag.outputs.dockerImageBaseUrl }}:latest
fi
# Submit to BioSimulators registry
- name: Submit to BioSimulators registry
if: steps.determine-if-release-needed.outputs.release == '1'
run: |
REVISION=$(git rev-parse HEAD)
curl \
-X POST \
-u ${{ secrets.GH_ISSUE_USERNAME }}:${{ secrets.GH_ISSUE_TOKEN }} \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/biosimulators/Biosimulators/issues \
-d "{\"labels\": [\"Validate/submit simulator\"], \"title\": \"Submit ${{ steps.get-docker-image-tag.outputs.simulatorName }} ${{ steps.get-docker-image-tag.outputs.simulatorVersion }}\", \"body\": \"---\nid: ${{ steps.get-docker-image-tag.outputs.simulatorId }}\nversion: ${{ steps.get-docker-image-tag.outputs.simulatorVersion }}\nspecificationsUrl: https://raw.githubusercontent.com/${{ github.repository }}/${REVISION}/biosimulators.json\nspecificationsPatch:\n version: ${{ steps.get-docker-image-tag.outputs.simulatorVersion }}\n image:\n url: ${{ steps.get-docker-image-tag.outputs.dockerImageBaseUrl }}:${{ steps.get-docker-image-tag.outputs.simulatorVersion }}\nvalidateImage: true\ncommitSimulator: true\n\n---\"}"
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ sphinx-apidoc . setup.py --output-dir docs-src/source --force --module-first --n
sphinx-build docs-src docs
```

## Submitting changes
## Submitting changes

Please use GitHub pull requests to submit changes. Each request should include a brief description of the new and/or modified features.

Expand Down Expand Up @@ -88,7 +88,7 @@ Below are instructions for releasing a new version:
## Reporting issues

Please use [GitHub issues](https://github.com/biosimulators/Biosimulators_tellurium/issues) to report any issues to the development community.

## Getting help

Please use [GitHub issues](https://github.com/biosimulators/Biosimulators_tellurium/issues) to post questions or contact the lead developers at [[email protected]](mailto:[email protected]).
9 changes: 7 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
FROM python:3.7.9-slim-buster

ARG VERSION="0.0.1"
ARG SIMULATOR_VERSION="2.1.6"
ARG SIMULATOR_VERSION="2.2.0"

# metadata
LABEL \
Expand All @@ -30,7 +30,7 @@ LABEL \
org.opencontainers.image.licenses="Apache-2.0" \
\
base_image="python:3.7.9-slim-buster" \
version="${VERSION}" \
version="${VERSION}" \
software="tellurium" \
software.version="${SIMULATOR_VERSION}" \
about.summary="Python-based environment for model building, simulation, and analysis that facilitates reproducibility of models in systems and synthetic biology" \
Expand All @@ -45,12 +45,17 @@ LABEL \
RUN apt-get update -y \
&& apt-get install -y --no-install-recommends \
libxml2 \
libncurses5 \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/*

# Copy code for command-line interface into image and install it
COPY . /root/Biosimulators_tellurium
RUN pip install /root/Biosimulators_tellurium \
&& mkdir -p /.cache/matplotlib \
&& mkdir -p /.config/matplotlib \
&& chmod ugo+rw /.config/matplotlib \
&& chmod ugo+rw /.cache/matplotlib \
&& rm -rf /root/Biosimulators_tellurium
RUN pip install tellurium==${SIMULATOR_VERSION}

Expand Down
Loading

0 comments on commit ce6a7fb

Please sign in to comment.