Skip to content

Mewu/fix issues (#2) #16

Mewu/fix issues (#2)

Mewu/fix issues (#2) #16

Workflow file for this run

name: Render Quarto Files and Deploy to GitHub Pages
on:
push:
branches:
- main
paths-ignore:
- '.devcontainer/**'
workflow_dispatch: # Manual trigger
jobs:
render_quarto:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
# - name: Build Docker image
# run: |
# docker build -t demo-quarto-image .
- name: Create gallery directory on the host
run: |
echo 'Creating gallery directory...'
mkdir -p gallery && chmod -R 777 gallery
echo 'gallery directory created.'
- name: Run Quarto in Docker container
run: |
docker run --rm -v ${{ github.workspace }}:/workspace -w /workspace mewu/data_access:latest bash -c "
source /opt/venv/bin/activate
echo 'activated virtualenv.'
chmod +x /workspace/r/install_quarto_extensions.expect
/workspace/r/install_quarto_extensions.expect
quarto list extensions
echo 'Check Quarto status:'
quarto check
echo 'Check R script path:'
which Rscript
FOLDERS=(python r)
echo 'Folders to process: \${FOLDERS[@]}'
for FOLDER in \"\${FOLDERS[@]}\"; do
echo \"Searching for .qmd and .ipynb files in /workspace/\$FOLDER...\"
find \"/workspace/\$FOLDER\" \( -name '*.qmd' -o -name '*.ipynb' \) | while read -r file; do
echo \"Processing file: \$file\"
# Remove the /workspace prefix from the file path
relative_dir=\$(dirname \"\${file#'/workspace/'}\")
# Install extension to the folder directly
pushd \$relative_dir
/workspace/r/install_quarto_extensions.expect
popd
target_dir=\"/workspace/gallery/\$relative_dir\"
echo \"Creating target directory: \$target_dir\"
mkdir -p \"\$target_dir\" && echo \"Directory \$target_dir created.\"
echo \"Attempting to render \$file with execution...\"
if quarto render \"\$file\" --to html --output-dir \"\$target_dir\"; then
echo \"Successfully rendered \$file with execution.\"
else
echo \"Failed to render \$file with execution. Rendering without execution...\"
if quarto render \"\$file\" --to html --no-execute --output-dir \"\$target_dir\"; then
echo \"Successfully rendered \$file without execution.\"
else
echo \"Rendering failed for \$file, even without execution.\"
fi
fi
done
done"
- name: Generate Index HTML
run: |
ls -laR gallery
echo "<html><body><h1>Gallery Index</h1><ul>" > gallery/index.html
find gallery -name "*.html" -not -name "index.html" | while read -r file; do
# Remove the 'gallery/' prefix from the file path
relative_path="${file#gallery/}"
file_name=$(basename "$file")
echo "<li><a href=\"./$relative_path\">$relative_path</a></li>" >> gallery/index.html
done
echo "</ul></body></html>" >> gallery/index.html
- name: Upload HTML output
uses: actions/upload-artifact@v4
with:
name: gallery
path: gallery/
- name: Set up Git user
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./gallery # Path to the folder that you want to publish (the gallery folder)
publish_branch: docs # The branch used for GitHub Pages