From e215b883d300a75fa23dc2de7b444c35ba249c8d Mon Sep 17 00:00:00 2001 From: Alex Dewar Date: Tue, 6 Aug 2024 11:32:48 +0100 Subject: [PATCH] Add GitHub workflow for deploying docs --- hooks/post_gen_project.py | 1 + .../.github/workflows/docs.yml | 61 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 {{ cookiecutter.project_slug }}/.github/workflows/docs.yml diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 7e4d643..ddd7bcb 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -10,6 +10,7 @@ "{% if cookiecutter.packaging != 'pip-tools' %}dev-requirements.txt{% endif %}", "{% if cookiecutter.packaging != 'pip-tools' or not cookiecutter.mkdocs %}doc-requirements.txt{% endif %}", "{% if not cookiecutter.mkdocs %}docs{% endif %}", + "{% if not cookiecutter.mkdocs %}.github/workflows/docs.yml{% endif %}", "README.*.jinja", ) diff --git a/{{ cookiecutter.project_slug }}/.github/workflows/docs.yml b/{{ cookiecutter.project_slug }}/.github/workflows/docs.yml new file mode 100644 index 0000000..ebc3c1d --- /dev/null +++ b/{{ cookiecutter.project_slug }}/.github/workflows/docs.yml @@ -0,0 +1,61 @@ +name: Deploy to GitHub Pages + +on: + push: + branches: [main] + workflow_dispatch: + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: pages + cancel-in-progress: false + +jobs: + # Single deploy job since we're just deploying + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 +{%- if cookiecutter.packaging == 'poetry' %} + - name: Install Poetry + uses: abatilo/actions-poetry@v3.0.0 + with: + poetry-version: 1.8.3 + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + cache: poetry + - name: Install dependencies + run: poetry install + - name: Build docs with MkDocs + run: poetry run mkdocs build +{%- elif cookiecutter.packaging == 'pip-tools' %} + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + cache: pip + - name: Install dependencies + run: pip install .[doc] + - name: Build docs with MkDocs + run: mkdocs build +{%- endif %} + - name: Setup Pages + uses: actions/configure-pages@v5 + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: site + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4