Added requirements.txt #1
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: Convert Jupyter notebooks to markdown files | |
on: | |
pull_request: | |
types: [opened] | |
jobs: | |
convert_to_markdown: | |
name: Convert Jupyter Notebooks to Markdown | |
runs-on: ubuntu-latest | |
outputs: | |
generated_markdown_files: ${{steps.convert_notebooks.outputs.generated_markdown_files}} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Install Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
- name: Install Python dependencies | |
run: pip install -r requirements.txt | |
- name: Find Modified Jupyter Notebooks | |
id: find_notebooks | |
run: | | |
# Get notebooks that were modified | |
NOTEBOOK_FILES=$(git diff --name-only --diff-filter=AMR HEAD^ HEAD | grep -E "\.ipynb$" | tr '\n' ' ') | |
# Pass the list to the next step | |
echo "NOTEBOOK_FILES=$NOTEBOOK_FILES" >> $GITHUB_ENV | |
- name: Convert Jupyter Notebooks to Markdown | |
if: $NOTEBOOK_FILES != '' | |
id: convert_notebooks | |
run: | | |
# Retrieve notebook file names from previous step | |
for notebook_file in $NOTEBOOK_FILES; do | |
jupyter nbconvert --to markdown "$notebook_file" | |
# Check if conversion was successful | |
if [ $? -ne 0 ]; then | |
echo "Error: Conversion of $notebook_file to Markdown failed." | |
exit 1 | |
fi | |
done | |
# Get the list of generated markdown files | |
GENERATED_MARKDOWN_FILES=$(echo "$NOTEBOOK_FILES" | grep -E "\.md$" | tr '\n' ' ') | |
# Pass the list to the next step | |
echo "GENERATED_MARKDOWN_FILES=$GENERATED_MARKDOWN_FILES" >> $GITHUB_OUTPUT | |
post_process_markdown: | |
name: Post-process Markdown Files | |
needs: convert_to_markdown | |
runs-on: ubuntu-latest | |
steps: | |
- env: | |
GENERATED_MARKDOWN_FILES: ${{needs.convert_to_markdown.outputs.generated_markdown_files}} | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Install Python | |
uses: actions/setup-python@v3 | |
with: | |
python-version: '3.10' | |
- name: Post-process Markdown Files | |
id: post_process_markdown | |
if: $GENERATED_MARKDOWN_FILES != '' | |
run: | | |
# Retrieve generated markdown file names | |
PROCESSED_MARKDOWN=$(python post_process_notebook.py $GENERATED_MARKDOWN_FILES) | |
echo "PROCESSED_MARKDOWN=$PROCESSED_MARKDOWN" >> $GITHUB_ENV | |
- name: Rename markdown Files | |
if: $PROCESSED_MARKDOWN != '' | |
run: python rename_notebook.py $PROCESSED_MARKDOWN |