docs: use major & minor version for docs subdir #51
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# adapted from https://github.com/rstudio/vetiver-python/blob/main/.github/workflows/docs.yml | |
name: "docs" | |
on: | |
workflow_dispatch: | |
push: | |
branches: ["main"] | |
pull_request: | |
release: | |
types: [published] | |
jobs: | |
docs: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: 3.11 | |
cache: "pip" | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install -e .[docs] | |
- name: Set up Quarto | |
uses: quarto-dev/quarto-actions/setup@v2 | |
- name: git config | |
shell: bash | |
run: | | |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "41898282+github-actions[bot]" | |
- name: build docs | |
working-directory: docs | |
run: | | |
python -m quartodoc build --verbose | |
python -m quartodoc interlinks | |
quarto render | |
- name: save docs | |
uses: actions/upload-artifact@v3 | |
with: | |
name: docs-html | |
path: docs/_site | |
- name: Configure pull release name | |
if: ${{github.event_name == 'pull_request'}} | |
run: | | |
echo "RELEASE_NAME=pr-${PR_NUMBER}" >> $GITHUB_ENV | |
env: | |
PR_NUMBER: ${{ github.event.number }} | |
- name: Configure branch release name | |
if: ${{github.event_name != 'pull_request'}} | |
run: | | |
# use branch name, but replace slashes. E.g. feat/a -> feat-a | |
echo "RELEASE_NAME=${GITHUB_REF_NAME/\//-}" >> $GITHUB_ENV | |
- name: set major & minor version | |
if: github.ref_type == 'tag' && startswith(github.ref, 'refs/tags/v') | |
id: version | |
shell: python {0} | |
run: from ccbr_actions.versions import get_major_minor_version | |
from ccbr_actions.actions import set_output | |
set_output('VERSION_SHORT', get_major_minor_version("${{ github.ref_name }}".lstrip("v"))) | |
- name: publish dev docs | |
if: github.ref_name == 'main' && github.ref_type == 'branch' | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: docs/_site | |
publish_branch: gh-pages | |
destination_dir: dev | |
- name: publish stable docs | |
if: github.ref_type == 'tag' && startswith(github.ref, 'refs/tags/v') | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: docs/_site | |
publish_branch: gh-pages | |
destination_dir: ${{ steps.version.outputs.VERSION_SHORT }} | |
- name: create symlink stable to new version | |
if: github.ref_type == 'tag' && startswith(github.ref, 'refs/tags/v') | |
run: | | |
rm -if latest | |
ln -s ${{ steps.version.outputs.VERSION_SHORT }} latest | |
ls -la | |
git add latest | |
git commit -m 'chore: link latest docs from ${{ github.ref_name }} (${{ steps.version.outputs.VERSION_SHORT }})' && git push || echo 'no changes to commit' |