documentation #35
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
name: documentation | |
on: | |
# Triggers the workflow on push but only for the main branch | |
push: | |
branches: [ main ] | |
paths: | |
- src/specsanalyzer/**/* | |
- src/specsscan/**/* | |
- tutorial/** | |
- .github/workflows/documentation.yml | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
env: | |
UV_SYSTEM_PYTHON: true | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# Check out repo and set up Python | |
- uses: actions/checkout@v4 | |
# see https://stackoverflow.com/questions/57612428/cloning-private-github-repository-within-organisation-in-actions and https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#generating-a-new-ssh-key | |
- name: Fetch test data | |
run: | | |
eval `ssh-agent -s` | |
ssh-add - <<< '${{ secrets.TEST_DATA_ACCESS_KEY }}' | |
git submodule sync --recursive | |
git submodule update --init --recursive --jobs=4 | |
# Setup python | |
- name: Set up Python 3.10 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.10" | |
- name: Install dependencies | |
run: | | |
curl -LsSf https://astral.sh/uv/install.sh | sh | |
- name: Install package | |
run: | | |
uv pip install ".[docs,notebook]" | |
- name: Install pandoc | |
run: | | |
sudo wget https://github.com/jgm/pandoc/releases/download/3.1.8/pandoc-3.1.8-1-amd64.deb | |
sudo dpkg -i pandoc-3.1.8-1-amd64.deb | |
# rm because hextof_workflow notebook can not run outside maxwell | |
- name: copy tutorial files to docs | |
run: | | |
cp -r $GITHUB_WORKSPACE/tutorial $GITHUB_WORKSPACE/docs/ | |
mkdir $GITHUB_WORKSPACE/docs/tests | |
cp -r $GITHUB_WORKSPACE/tests/data $GITHUB_WORKSPACE/docs/tests/ | |
- name: Change version for develop build | |
if: startsWith(github.ref, 'refs/heads/') && github.ref != 'refs/heads/main' | |
run: | | |
VERSION=`sed -n 's/^version = "\(.*\)".*/\1/p' $GITHUB_WORKSPACE/pyproject.toml` | |
MOD_VERSION=$VERSION".dev0" | |
echo $MOD_VERSION | |
sed -i "s/^version = \"$VERSION\"/version = \"$MOD_VERSION\"/" $GITHUB_WORKSPACE/pyproject.toml | |
- name: Change version for release build | |
if: startsWith(github.ref, 'refs/tags/') | |
run: | | |
OLD_VERSION=`sed -n 's/^version = "\(.*\)".*/\1/p' $GITHUB_WORKSPACE/pyproject.toml` | |
NEW_VERSION=`echo ${GITHUB_REF#refs/tags/} | sed -n 's/^v\(.*\)/\1/p'` | |
echo $NEW_VERSION | |
sed -i "s/^version = \"$OLD_VERSION\"/version = \"$NEW_VERSION\"/" $GITHUB_WORKSPACE/pyproject.toml | |
- name: build Sphinx docs | |
run: sphinx-build -b html $GITHUB_WORKSPACE/docs $GITHUB_WORKSPACE/_build | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: sphinx-docs | |
path: _build | |
# this job pushes the built documentation to the docs repository | |
push: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Checkout docs repo | |
uses: actions/checkout@v2 | |
with: | |
repository: ${{ github.repository_owner }}/docs | |
token: ${{ secrets.GITHUB_TOKEN }} | |
path: 'docs-repo' | |
- name: Set up Python 3.10 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.10 | |
- name: Setup SSH | |
uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.SSH_DOCS_DEPLOY_KEY }} | |
- name: Download artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: sphinx-docs | |
path: sphinx-docs | |
- name: Determine version folder | |
id: version-folder | |
run: | | |
if [[ $GITHUB_REF == refs/tags/* ]]; then | |
VERSION=${GITHUB_REF#refs/tags/} | |
echo "folder=specsanalyzer/$VERSION" >> $GITHUB_OUTPUT | |
rm docs-repo/specsanalyzer/stable | |
ln -s -r docs-repo/specsanalyzer/$VERSION docs-repo/specsanalyzer/stable | |
elif [[ $GITHUB_REF == refs/heads/main ]]; then | |
echo "folder=specsanalyzer/latest" >> $GITHUB_OUTPUT | |
else | |
echo "folder=specsanalyzer/develop" >> $GITHUB_OUTPUT | |
fi | |
- name: Update switcher.json | |
run: | | |
VERSION=`grep "<title>Specsanalyzer documentation." sphinx-docs/index.html | sed -n 's/.*SED \(.*\) documentation.*/\1/p'` | |
echo "python docs-repo/specsanalyzer/update_switcher.py docs-repo/specsanalyzer/switcher.json $GITHUB_REF $VERSION" | |
python docs-repo/specsanalyzer/update_switcher.py docs-repo/specsanalyzer/switcher.json $GITHUB_REF $VERSION | |
- name: Copy documentation to the right version folder | |
run: | | |
mkdir -p docs-repo/${{ steps.version-folder.outputs.folder }} | |
cp -r sphinx-docs/* docs-repo/${{ steps.version-folder.outputs.folder }} | |
rm -rf docs-repo/${{ steps.version-folder.outputs.folder }}/.doctrees | |
rm -rf docs-repo/${{ steps.version-folder.outputs.folder }}/tutorial/*.ipynb | |
- name: Push changes | |
run: | | |
cd docs-repo | |
git config user.name github-actions | |
git config user.email [email protected] | |
git add . | |
git commit -m "Update documentation" | |
git push |