WIP for en#81 template macros and page filtering #152 #246
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
on: [push] | |
jobs: | |
run_tests: | |
if: (github.repository == 'DavidLeoni/jupman') && ((github.ref == 'refs/heads/master') || (github.ref == 'refs/heads/dev') || (github.ref == 'refs/heads/themed')) | |
runs-on: ubuntu-20.04 | |
env: | |
SOURCE_BRANCH: ${{ github.head_ref || github.ref_name }} | |
name: Run tests | |
steps: | |
- name: Install test deps | |
run: | | |
sudo apt-get install pandoc | |
git clone --depth=1 --single-branch --branch ${SOURCE_BRANCH} https://github.com/${{ github.repository }}.git ${SOURCE_BRANCH} | |
cd ${SOURCE_BRANCH} | |
python3 -m pip install --user -r requirements-build.txt | |
python3 -m pip install --user -r _test/requirements-test.txt | |
- name: Run pytest | |
run: | | |
cd ${SOURCE_BRANCH} | |
python3 -m pytest _test/*_test.py | |
build_docs_job: | |
if: (github.repository == 'DavidLeoni/jupman') && (github.ref == 'refs/heads/master') | |
needs: run_tests | |
runs-on: ubuntu-20.04 | |
env: | |
SOURCE_BRANCH: ${{ github.head_ref || github.ref_name }} | |
WEB_BRANCH: gh-pages | |
name: Build docs | |
steps: | |
- name: Install deps | |
run: | | |
sudo apt-get install tree | |
- name: sets environment | |
run: | | |
echo "GIT_TAG=${GITHUB_REF##*/}" >> $GITHUB_ENV | |
echo "VERSION=${GITHUB_REF##*/}" >> $GITHUB_ENV | |
echo "LANGUAGE=en" >> $GITHUB_ENV | |
- name: apply docs version renaming | |
if: env.GIT_TAG == 'master' | |
run: echo "VERSION=latest" >> $GITHUB_ENV | |
- name: sets WEB_PATH | |
run: echo "WEB_PATH=${{env.LANGUAGE}}/${{env.VERSION}}" >> $GITHUB_ENV | |
- name: Run Sphinx in RTD docker | |
uses: DavidLeoni/[email protected] | |
with: | |
RTD_PRJ_NAME: jupman | |
GIT_URL: https://github.com/${{ github.repository }}.git | |
GIT_TAG: ${{ env.GIT_TAG }} | |
VERSION: ${{ env.VERSION }} | |
REQUIREMENTS: requirements-build.txt | |
LANGUAGE: ${{ env.LANGUAGE }} | |
RTD_HTML_SINGLE: false | |
RTD_HTML_EXT: false | |
GOOGLE_ANALYTICS: ${{ secrets.GOOGLE_ANALYTICS }} | |
- name: Show workspace output | |
run: | | |
tree -aC $GITHUB_WORKSPACE | |
- name: Commit documentation changes | |
run: | | |
git clone --depth=1 --single-branch --branch ${WEB_BRANCH} https://github.com/${{ github.repository }}.git ${WEB_BRANCH} | |
cd ${WEB_BRANCH} | |
if [ -d "${{ env.WEB_PATH }}" ] | |
then | |
git rm -r * ${{ env.WEB_PATH }} | |
fi | |
mkdir -p ${{ env.WEB_PATH }} | |
cp -r $GITHUB_WORKSPACE/html/* ${{ env.WEB_PATH }} | |
if compgen -G "$GITHUB_WORKSPACE/latex/*.pdf" > /dev/null; then | |
cp -r $GITHUB_WORKSPACE/latex/*.pdf ${{ env.WEB_PATH }} | |
else | |
echo "ERROR: NO PDF FILES WHERE GENERATED!" | |
fi | |
if compgen -G "$GITHUB_WORKSPACE/epub/*.epub" > /dev/null; then | |
cp -r $GITHUB_WORKSPACE/epub/*.epub ${{ env.WEB_PATH }} | |
else | |
echo "ERROR: NO EPUB FILES WHERE GENERATED!" | |
fi | |
# note: html zip is already provided by Github | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add . | |
touch .nojekyll | |
git add .nojekyll # explicit, otherwise is ignored | |
git commit -m "Update documentation" -a || true | |
# The above command will fail if no changes were present, so we ignore | |
# the return code. | |
- name: Push changes | |
uses: ad-m/[email protected] | |
with: | |
branch: ${{ env.WEB_BRANCH }} | |
directory: ${{ env.WEB_BRANCH }} | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
jupman_specific_stuff: | |
# custom stuff, you don't need this | |
if: (github.repository == 'DavidLeoni/jupman') && (github.ref == 'refs/heads/master') | |
needs: build_docs_job | |
runs-on: ubuntu-20.04 | |
env: | |
WEB_BRANCH: gh-pages | |
WEB_PATH: themed | |
name: Jupman-specific stuff (you don't need this) | |
steps: | |
- name: Generate html for softpython theme | |
run: | | |
git clone --depth=1 --single-branch --branch ${WEB_BRANCH} https://github.com/${{ github.repository }}.git ${WEB_BRANCH} | |
cd ${WEB_BRANCH} | |
if [ -d "${WEB_PATH}" ] | |
then | |
git rm -r * ${WEB_PATH} | |
fi | |
cp -r en/latest ${WEB_PATH} | |
sudo tee -a /tmp/jupman_html_script.py <<EOF | |
import os, fnmatch, re | |
def findReplace(directory, regex, replace, filePattern): | |
for path, dirs, files in os.walk(os.path.abspath(directory)): | |
for filename in fnmatch.filter(files, filePattern): | |
filepath = os.path.join(path, filename) | |
print('Replacing ', filepath) | |
with open(filepath) as f: | |
s = f.read() | |
s = re.sub(regex, replace, s) | |
with open(filepath, "w") as f: | |
f.write(s) | |
findReplace('${WEB_PATH}', | |
r'(<link rel="stylesheet" href="[\w\/\-\.]*)(/jupman-web.css)(" type="text/css" />\n)', | |
r'\1\2\3 \1/softpython-theme.css\3 \1/softpython-theme-textures.css\3', | |
"*.html") | |
print("Done replacing jupman html") | |
EOF | |
python3 /tmp/jupman_html_script.py | |
# note: html zip is already provided by Github | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add . | |
touch .nojekyll | |
git add .nojekyll # explicit, otherwise is ignored | |
git commit -m "Update documentation" -a || true | |
# The above command will fail if no changes were present, so we ignore | |
- name: Push changes for themes | |
uses: ad-m/[email protected] | |
with: | |
branch: ${{ env.WEB_BRANCH }} | |
directory: ${{ env.WEB_BRANCH }} | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
- name: deploy to custom server | |
run: | | |
# Custom deploy, you don't need this | |
if [ ! -z "${{ secrets.DAVAPI_URL }}" ]; then | |
curl --silent --digest --user ${{ secrets.DAVAPI_CREDENTIALS}} ${{ secrets.DAVAPI_URL }} | |
fi |