From caf0c36835fec922219587288a4793e7e54a159a Mon Sep 17 00:00:00 2001 From: Yeqi Huang Date: Mon, 27 Jan 2025 16:32:23 +0000 Subject: [PATCH] Dev (#12) * Update GitHub Actions workflows to use Python 3.8 and improve package installation steps * Refactor GitHub Actions workflows to streamline Conda channel configuration by removing defaults and ensuring conda-forge is prioritized for package installations. * Refactor GitHub Actions workflows to enhance Conda environment setup and streamline package installation for D2l Test and Update Docs workflows. * Refactor GitHub Actions workflows to improve Conda environment initialization and package installation steps, ensuring proper activation and configuration for Python 3.8 and pandoc. Update documentation build process to copy generated HTML files correctly. * Refactor GitHub Actions workflow to replace Conda setup with Python 3.8 virtual environment. Update dependency installation steps and streamline documentation build process for improved clarity and efficiency. * Refactor GitHub Actions workflow to simplify event triggers and maintain documentation build process. Consolidate push, pull_request, and workflow_dispatch events for improved clarity. * Update GitHub Actions workflow to install the latest version of pandoc, removing the specific version constraint for improved compatibility and maintenance. * Update GitHub Actions workflow for D2l Test: rename workflow, add caching for Python packages, ensure specific version of pandoc is installed, and enforce installation of recommonmark dependency. * Update GitHub Actions workflow to install the latest version of pandoc by removing the specific version constraint for improved compatibility. * Update GitHub Actions workflow to install sphinxcontrib-bibtex dependency alongside recommonmark for enhanced documentation generation. * Refactor GitHub Actions workflow to remove specific version installations of recommonmark and sphinxcontrib-bibtex, enhancing flexibility in dependency management. Ensure virtual environment is activated before package installations for improved reliability. * Refactor GitHub Actions workflow to streamline the installation process by moving the d2l-book cloning and installation steps to occur after the virtual environment activation. This change enhances the clarity and reliability of the setup process. * Refactor GitHub Actions workflow to enhance documentation build process by replacing Conda setup with a Python 3.8 virtual environment. Introduce caching for Python packages, streamline dependency installation, and ensure proper cloning and installation of the d2l-book repository. Improve commit and push logic for updated documentation, ensuring changes are only committed if there are modifications. * Enhance GitHub Actions workflow by adding push event trigger for the main branch and ensuring pull request events are limited to the main branch. This improves the clarity of event handling for documentation updates. * Refactor GitHub Actions workflow to simplify event triggers by consolidating push and pull_request events, and adding workflow_dispatch for manual execution. This enhances the clarity and flexibility of the documentation update process. * Refactor GitHub Actions workflow to simplify event triggers by consolidating push, pull_request, and adding workflow_dispatch for manual execution. This enhances clarity and flexibility in the documentation update process. * Refactor GitHub Actions workflow to streamline the installation and documentation build process. Consolidate Python dependency installation and d2l-book setup into a single step, ensuring the virtual environment is activated beforehand. Update the copying of built HTML documentation to improve clarity and efficiency. * Add D2l Test workflow for automated documentation build - Introduced a new GitHub Actions workflow for D2l Test that triggers on push, pull_request, and manual execution. - Set up Python 3.8 environment and caching for Python packages to optimize dependency installation. - Streamlined the installation process for d2l-book and added steps to install pandoc. - Enhanced the documentation build process by ensuring proper activation of the virtual environment before building HTML documentation. * Refactor GitHub Actions workflow for documentation updates: streamline cloning and copying of HTML files, improve commit logic to ensure documentation is only updated when changes are present. * Update GitHub Actions workflow for documentation updates: configure Git user details for automated commits and adjust push command to ensure proper branch tracking. * Update GitHub Actions workflow to change default branch from 'master' to 'main' for documentation updates, ensuring proper branch tracking during automated commits. * Update GitHub Actions workflow to change commit author details for documentation updates, replacing the default GitHub Actions bot with specific user information. * Update GitHub Actions workflow to use GitHub token for cloning and pushing documentation updates, enhancing security and ensuring proper authentication during automated commits. * Simplify GitHub Actions workflow for documentation updates - Remove Python package caching step - Streamline workflow steps by removing redundant names - Modify GitHub token usage for cloning and pushing documentation - Improve overall workflow readability and efficiency * Fix GitHub Actions documentation update workflow push command - Remove hardcoded repository URL from git push command - Simplify push operation to use default remote repository * Remove hardcoded Git user configuration in documentation update workflow * Add explicit Git user configuration in documentation update workflow - Configure Git user name and email before committing - Ensure proper user attribution for automated documentation updates * Add PAT token environment variable to documentation update workflow - Include PAT_TOKEN as an environment variable in the GitHub Actions workflow - Prepare for potential authentication or access requirements in the documentation update process * Refactor documentation update workflow PAT token placement - Move PAT_TOKEN environment variable to the appropriate step - Ensure correct environment variable scoping for Git push operation * Refactor documentation update workflow authentication and push mechanism - Update Git remote URL configuration to use GitHub token - Simplify authentication and push process for documentation updates - Remove redundant environment variable and push command * Streamline documentation update workflow authentication - Use PAT token directly in Git clone and push commands - Remove redundant remote URL configuration steps - Simplify authentication mechanism for documentation updates * Improve GitHub Actions documentation update workflow authentication - Use 'x-access-token:' prefix for PAT token authentication - Consolidate clone and push steps into a single named step - Enhance security and clarity of Git authentication process * Update GitHub Actions documentation workflow authentication - Replace PAT_TOKEN with GH_TOKEN for authentication - Update Git user configuration to use GitHub Actions Bot identity - Simplify authentication and user configuration for documentation updates * Refactor and enhance documentation update GitHub Actions workflow - Update workflow to use more robust and secure configuration - Add environment variables for better maintainability - Improve Python dependency and build process - Enhance deployment logic with conditional checks and detailed commit messages - Update to latest GitHub Actions checkout and setup actions --- .github/workflows/update_docs.yml | 104 ++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 34 deletions(-) diff --git a/.github/workflows/update_docs.yml b/.github/workflows/update_docs.yml index 3792b18..c7c1094 100644 --- a/.github/workflows/update_docs.yml +++ b/.github/workflows/update_docs.yml @@ -1,63 +1,99 @@ name: Update Docs on: - - push - - pull_request - - workflow_dispatch + push: + branches: + - main # specify branches if needed + pull_request: + workflow_dispatch: + +env: + PYTHON_VERSION: '3.8' + DEST_REPO: 'openmlsys/html-en' + GIT_USER_NAME: 'GitHub Actions Bot' + GIT_USER_EMAIL: 'github-actions[bot]@users.noreply.github.com' jobs: - build: + build-and-deploy: runs-on: ubuntu-20.04 - + steps: - # Checkout the repository - name: Checkout repository - uses: actions/checkout@v2 - - # Set up Python 3.8 - - name: Set up Python 3.8 - uses: actions/setup-python@v4 + uses: actions/checkout@v3 # Updated to v3 with: - python-version: '3.8' + fetch-depth: 0 # Fetch all history for better versioning - # Cache Python packages to speed up builds - - name: Cache Python packages - uses: actions/cache@v3 + - name: Setup Python + uses: actions/setup-python@v4 with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} - restore-keys: | - ${{ runner.os }}-pip- - + python-version: ${{ env.PYTHON_VERSION }} + cache: 'pip' # Enable pip caching - # Install Pandoc using apt-get - - name: Install Pandoc + - name: Install system dependencies run: | sudo apt-get update sudo apt-get install -y pandoc - - # Install Python dependencies and build the HTML documentation - - name: Install dependencies + + - name: Setup Python virtual environment run: | python -m venv venv source venv/bin/activate pip install --upgrade pip + + - name: Install Python dependencies + run: | + source venv/bin/activate pip install -r requirements.txt pip install sphinx-mathjax-offline + + - name: Install d2l-book + run: | + source venv/bin/activate git clone https://github.com/openmlsys/d2l-book.git cd d2l-book pip install . cd .. + + - name: Build documentation + run: | + source venv/bin/activate sh build_html.sh - # Clone the html-en repository - - name: Clone html-en Repository + - name: Deploy to html-en repository + if: github.event_name != 'pull_request' # Don't deploy on PRs + env: + GH_TOKEN: ${{ secrets.GH_TOKEN }} run: | - git clone https://github.com/openmlsys/html-en.git - cp -rf _build/html/* html-en/ + # Clone the destination repository + git clone https://${GH_TOKEN}@github.com/${DEST_REPO}.git + + # Copy built documentation + cp -r _build/html/* html-en/ + + # Configure git cd html-en - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - git add . - git diff --quiet || git commit -m 'Update English docs' - git push || echo "No changes to push" + git config user.name "${GIT_USER_NAME}" + git config user.email "${GIT_USER_EMAIL}" + + # Check if there are changes to commit + if [[ -n $(git status -s) ]]; then + git add . + git commit -m "docs: update documentation + + Automated update by GitHub Actions + Workflow: ${{ github.workflow }} + Run ID: ${{ github.run_id }} + Triggered by: ${{ github.event_name }}" + + # Push changes + git push origin main + else + echo "No changes to commit" + fi + + - name: Clean up + if: always() + run: | + rm -rf venv + rm -rf html-en + rm -rf d2l-book