Skip to content

Additional path experimentation #16

Additional path experimentation

Additional path experimentation #16

name: Generate Documentation
on:
push:
branches: [main]
pull_request:
branches: [main]
release:
types: [published]
workflow_dispatch:
jobs:
build_docs:
name: Build Documentation
runs-on: ubuntu-latest
permissions:
contents: write # Grants permission to push to the repository
pull-requests: write # Grants permission to create and manage pull requests
env:
BRANCH_NAME: docs-temp-${{ github.run_id }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout Documentation Repo
uses: actions/checkout@v4
- name: Checkout Stochtree Repository
uses: actions/checkout@v4
with:
repository: 'StochasticTree/stochtree'
path: 'stochtree-repo'
submodules: 'recursive'
# Build Python Documentation
- name: Setup Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'pip'
- name: Install Python Package with Relevant Dependencies
working-directory: stochtree-repo
run: |
pip install --upgrade pip
pip install -r python_docs/requirements.txt
pip install .
- name: Build Python HTML Documentation
working-directory: stochtree-repo
run: |
sphinx-build -M html python_docs/source/ python_docs/_build/
- name: Copy Python Documentation to Docs Directory
run: |
# Ensure the target directory exists
mkdir -p docs/python-documentation
# Clear existing content, if present
rm -rf docs/python-documentation/*
# Copy the built documentation
cp -r stochtree-repo/python_docs/_build/html/* docs/python-documentation/
# Build R Documentation
- name: Setup Pandoc
uses: r-lib/actions/setup-pandoc@v2
- name: Setup R
uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
- name: Install R Dependencies
working-directory: stochtree-repo
run: |
Rscript -e 'install.packages(c("remotes", "pkgdown", "ggplot2", "latex2exp", "decor"))'
- name: Create stochtree_cran Directory and Copy Files
working-directory: stochtree-repo
run: |
mkdir -p stochtree_cran/src
cp src/Makevars stochtree_cran/src/Makevars
cp DESCRIPTION stochtree_cran/
cp _pkgdown.yml stochtree_cran/
cp R_README.md stochtree_cran/README.md
- name: List Contents of stochtree_cran/src
working-directory: stochtree-repo
run: |
ls -la stochtree_cran/src
- name: List Contents of stochtree_cran
working-directory: stochtree-repo
run: |
ls -la stochtree_cran
- name: Run cran-bootstrap.R
working-directory: stochtree-repo
run: |
Rscript cran-bootstrap.R
- name: Install Package Dependencies
working-directory: stochtree-repo/stochtree_cran
run: |
Rscript -e 'remotes::install_deps(dependencies = TRUE)'
- name: Build R Documentation Site
working-directory: stochtree-repo/stochtree_cran
run: |
Rscript -e 'pkgdown::build_site(override = list(destination = "../docs/r-documentation"), install = TRUE)'
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
# Commit and Push Changes
- name: Commit and Push Documentation Changes
id: commit_and_push
run: |
# Configure Git
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
# Check for changes
if [ -n "$(git status --porcelain)" ]; then
# Create and switch to new branch
git checkout -b $BRANCH_NAME
# Add changes
git add docs/python-documentation docs/r-documentation
git commit -m "Updated the Python and R documentation"
# Push changes to new branch
git push origin $BRANCH_NAME
echo "changes=true" >> $GITHUB_OUTPUT
else
echo "No changes to commit."
echo "changes=false" >> $GITHUB_OUTPUT
fi
- name: Merge Temporary Branch into Main
if: steps.commit_and_push.outputs.changes == 'true'
run: |
# Configure Git
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
# Fetch the latest main
git fetch origin main
# Checkout main
git checkout main
# Merge the temporary branch
git merge --no-ff $BRANCH_NAME -m "Merge updated documentation"
# Push changes to main
git push origin main
- name: Delete Temporary Branch
if: steps.commit_and_push.outputs.changes == 'true'
run: |
# Delete the temporary branch locally and remotely
git branch -D $BRANCH_NAME
git push origin --delete $BRANCH_NAME