From 7bbc4692bafb27dfefa485507c9ac3541564232a Mon Sep 17 00:00:00 2001 From: Niko Sirmpilatze Date: Fri, 20 Oct 2023 18:35:39 +0100 Subject: [PATCH] Deploy website only when a release is made (#47) * added setuptools_scm as requirement * get version via setuptools_scm * enable deployment only on releases --- .github/workflows/docs_build_and_deploy.yml | 7 +++---- docs/requirements.txt | 1 + docs/source/conf.py | 11 +++++++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docs_build_and_deploy.yml b/.github/workflows/docs_build_and_deploy.yml index 85d3aae..7221172 100644 --- a/.github/workflows/docs_build_and_deploy.yml +++ b/.github/workflows/docs_build_and_deploy.yml @@ -2,9 +2,8 @@ name: Build Sphinx docs and deploy to GitHub Pages # Generate the documentation on all merges to main, all pull requests, or by # manual workflow dispatch. The build job can be used as a CI check that the -# docs still build successfully. The deploy job only runs when merging -# to main and actually moves the generated html to the gh-pages branch -# (which triggers a GitHub pages deployment). +# docs still build successfully. The deploy job only runs when a tag is pushed +# (so, when a new release is made). on: push: branches: @@ -38,7 +37,7 @@ jobs: needs: build_sphinx_docs permissions: contents: write - if: github.event_name == 'push' && github.ref_name == 'main' + if: github.event_name == 'push' && github.ref_type == 'tag' runs-on: ubuntu-latest steps: - uses: neuroinformatics-unit/actions/deploy_sphinx_docs@v2 diff --git a/docs/requirements.txt b/docs/requirements.txt index e6f6522..fc1fa78 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -3,5 +3,6 @@ myst-parser nbsphinx numpydoc pydata-sphinx-theme +setuptools-scm sphinx sphinx-design diff --git a/docs/source/conf.py b/docs/source/conf.py index fe89d09..6ff838d 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -16,13 +16,20 @@ # -- Project information ----------------------------------------------------- +import setuptools_scm project = 'NeuroBlueprint' copyright = '2022, UCL' author = 'Neuroinformatics Unit' -# The full version, including alpha/beta/rc tags -release = '0.1.0' +# Retrieve the version number from the package +try: + release = setuptools_scm.get_version(root="../..", relative_to=__file__) + release = release.split(".dev")[0] # remove dev tag and git hash +except LookupError: + # if git is not initialised, still allow local build + # with a dummy version + release = "0.0.0" # -- General configuration ---------------------------------------------------