|
| 1 | +name: Continuous integration |
| 2 | + |
| 3 | +on: |
| 4 | + - push |
| 5 | + |
| 6 | +jobs: |
| 7 | + getVersionNumber: |
| 8 | + name: Get version number |
| 9 | + if: startsWith(github.ref, 'refs/tags/') |
| 10 | + runs-on: ubuntu-latest |
| 11 | + outputs: |
| 12 | + version: ${{ steps.get-version-number.outputs.version }} |
| 13 | + steps: |
| 14 | + - id: get-version-number |
| 15 | + name: Get version number |
| 16 | + env: |
| 17 | + TAG: ${{ github.ref }} |
| 18 | + run: | |
| 19 | + version="${TAG/refs\/tags\//}" |
| 20 | + echo "::set-output name=version::$version" |
| 21 | +
|
| 22 | + build: |
| 23 | + name: Lint, test, and compile documentation |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - name: Checkout repository |
| 27 | + uses: actions/checkout@v2 |
| 28 | + with: |
| 29 | + fetch-depth: 1 |
| 30 | + |
| 31 | + - name: Install Python |
| 32 | + uses: actions/setup-python@v2 |
| 33 | + with: |
| 34 | + python-version: '3.7' |
| 35 | + |
| 36 | + - name: Setup pip cache |
| 37 | + uses: actions/cache@v2 |
| 38 | + with: |
| 39 | + path: /opt/hostedtoolcache/Python |
| 40 | + key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}-${{ hashFiles('requirements.optional.txt') }} |
| 41 | + restore-keys: | |
| 42 | + ${{ runner.os }}-pip- |
| 43 | +
|
| 44 | + - name: Install pip and setuptools |
| 45 | + run: | |
| 46 | + python -m pip install --upgrade pip |
| 47 | + python -m pip install --upgrade setuptools |
| 48 | +
|
| 49 | + # install package |
| 50 | + - name: Install the package |
| 51 | + run: python -m pip install .[all] |
| 52 | + |
| 53 | + # lint |
| 54 | + - name: Install flake8 |
| 55 | + run: python -m pip install flake8 |
| 56 | + |
| 57 | + - name: Lint the package |
| 58 | + run: python -m flake8 |
| 59 | + |
| 60 | + # test and upload coverage report to Codecov |
| 61 | + - name: Install pytest |
| 62 | + run: python -m pip install pytest pytest-cov |
| 63 | + |
| 64 | + - name: Install the requirements for the tests |
| 65 | + run: python -m pip install .[tests] |
| 66 | + |
| 67 | + - name: Run the tests |
| 68 | + run: python -m pytest tests/ --cov=./biosimulators_test_suite --cov-report=xml |
| 69 | + |
| 70 | + - name: Upload the coverage report to Codecov |
| 71 | + |
| 72 | + with: |
| 73 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 74 | + flags: unittests |
| 75 | + file: ./coverage.xml |
| 76 | + |
| 77 | + # compile documentation |
| 78 | + - name: Install the requirements for compiling the documentation |
| 79 | + run: python -m pip install -r docs-src/requirements.txt |
| 80 | + |
| 81 | + - name: Compile the documentation |
| 82 | + run: | |
| 83 | + sphinx-apidoc . setup.py --output-dir docs-src/source --force --module-first --no-toc |
| 84 | + mkdir -p docs-src/_static |
| 85 | + sphinx-build docs-src docs |
| 86 | +
|
| 87 | + release: |
| 88 | + name: Release a new version |
| 89 | + needs: [getVersionNumber, build] |
| 90 | + runs-on: ubuntu-latest |
| 91 | + outputs: |
| 92 | + docsChanged: ${{ steps.commit-docs.outputs.docsChanged }} |
| 93 | + steps: |
| 94 | + - name: Checkout code |
| 95 | + uses: actions/checkout@v2 |
| 96 | + with: |
| 97 | + fetch-depth: 1 |
| 98 | + ref: dev |
| 99 | + |
| 100 | + - name: Install Python |
| 101 | + uses: actions/setup-python@v2 |
| 102 | + with: |
| 103 | + python-version: '3.7' |
| 104 | + |
| 105 | + - name: Setup pip cache |
| 106 | + uses: actions/cache@v2 |
| 107 | + with: |
| 108 | + path: /opt/hostedtoolcache/Python |
| 109 | + key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}-${{ hashFiles('requirements.optional.txt') }} |
| 110 | + restore-keys: | |
| 111 | + ${{ runner.os }}-pip- |
| 112 | +
|
| 113 | + - name: Install pip and setuptools |
| 114 | + run: | |
| 115 | + python -m pip install --upgrade pip |
| 116 | + python -m pip install --upgrade setuptools |
| 117 | +
|
| 118 | + # install package |
| 119 | + - name: Install the package |
| 120 | + run: python -m pip install .[all] |
| 121 | + |
| 122 | + # compile and push documentation |
| 123 | + - name: Install the requirements for compiling the documentation |
| 124 | + run: python -m pip install -r docs-src/requirements.txt |
| 125 | + |
| 126 | + - name: Compile the documentation |
| 127 | + run: | |
| 128 | + sphinx-apidoc . setup.py --output-dir docs-src/source --force --module-first --no-toc |
| 129 | + mkdir -p docs-src/_static |
| 130 | + sphinx-build docs-src docs |
| 131 | +
|
| 132 | + - id: commit-docs |
| 133 | + name: Commit the compiled documentation |
| 134 | + run: | |
| 135 | + git config --local user.email "[email protected]" |
| 136 | + git config --local user.name "biosimulatorsdaemon" |
| 137 | + git config pull.rebase false |
| 138 | + git stash |
| 139 | + git pull |
| 140 | + git stash pop |
| 141 | + git add docs |
| 142 | + set +e |
| 143 | + git commit -m "Updating compiled documentation" |
| 144 | + if [[ $? = 0 ]]; then |
| 145 | + docsChanged=1 |
| 146 | + else |
| 147 | + docsChanged=0 |
| 148 | + fi |
| 149 | + echo "::set-output name=docsChanged::$docsChanged" |
| 150 | +
|
| 151 | + - name: Push the compiled documentation |
| 152 | + if: steps.commit-docs.outputs.docsChanged == '1' |
| 153 | + uses: ad-m/github-push-action@master |
| 154 | + with: |
| 155 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 156 | + branch: dev |
| 157 | + |
| 158 | + # Create GitHub release |
| 159 | + - name: Create GitHub release |
| 160 | + uses: actions/create-release@v1 |
| 161 | + env: |
| 162 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 163 | + with: |
| 164 | + tag_name: ${{ needs.getVersionNumber.outputs.version }} |
| 165 | + release_name: Release ${{ needs.getVersionNumber.outputs.version }} |
| 166 | + |
| 167 | + # Create PyPI release |
| 168 | + - name: Install pandoc |
| 169 | + run: | |
| 170 | + sudo apt-get update -y |
| 171 | + sudo apt-get install -y --no-install-recommends wget |
| 172 | +
|
| 173 | + wget https://github.com/jgm/pandoc/releases -O /tmp/pandocVersions.html |
| 174 | + urlPart=`grep "\.deb" /tmp/pandocVersions.html | head -n 1 | cut -d'/' -f2-7 | cut -d'"' -f1` |
| 175 | + wget "https://github.com/$urlPart" -O /tmp/pandoc.deb |
| 176 | + sudo dpkg -i /tmp/pandoc.deb |
| 177 | + rm /tmp/pandocVersions.html |
| 178 | + rm /tmp/pandoc.deb |
| 179 | +
|
| 180 | + - name: Convert README to .rst format |
| 181 | + run: pandoc --from=gfm --output=README.rst --to=rst README.md |
| 182 | + |
| 183 | + - name: Install twine |
| 184 | + run: | |
| 185 | + python -m pip install wheel twine |
| 186 | +
|
| 187 | + - name: Create packages to upload to PyPI |
| 188 | + run: | |
| 189 | + python setup.py sdist |
| 190 | + python setup.py bdist_wheel |
| 191 | +
|
| 192 | + - name: Upload packages to PyPI |
| 193 | + env: |
| 194 | + TWINE_USERNAME: __token__ |
| 195 | + TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} |
| 196 | + run: | |
| 197 | + twine upload dist/* |
0 commit comments