|
| 1 | +# TOPST SCHOOL's GitHub Pages Dev Branch Publishing Workflow |
| 2 | +# ========================================================== |
| 3 | +# |
| 4 | +# Author: Akshay Mestry <xa@mes3.dev> |
| 5 | +# Created on: Sunday, September 01 2024 |
| 6 | +# Last updated on: Sunday, September 01 2024 |
| 7 | + |
| 8 | +# Workflow name displayed in TOPST SCHOOL's "Actions" tab. |
| 9 | +name: DEV | Build and Deploy Documents |
| 10 | + |
| 11 | +# A workflow with the following "on" value will run when a "push" is made |
| 12 | +# to the "dev" branch in the workflow's repository. For example, the "push" |
| 13 | +# event has a branches filter that causes this workflow to run only when |
| 14 | +# a push to a branch that matches the branches filter occurs, in this |
| 15 | +# case, the "dev" branch. |
| 16 | +on: |
| 17 | + push: |
| 18 | + branches: |
| 19 | + - dev |
| 20 | + |
| 21 | +# We're using permissions to modify the default permissions granted to |
| 22 | +# the ``GITHUB_TOKEN``, adding or removing access as required, so that we |
| 23 | +# only allow the minimum required access. |
| 24 | +permissions: |
| 25 | + contents: write # Only write permissions to the repository contents are needed for deployment. |
| 26 | + |
| 27 | +# A map of variables that are available to the steps of all jobs in the workflow. |
| 28 | +env: |
| 29 | + OUTPUT_DIR: docs/build/ # Directory where Sphinx will output the built HTML files. |
| 30 | + SOURCE_DIR: docs/source/ # Directory containing the Sphinx source files (rST or MD). |
| 31 | + PUBLISH_BRANCH: gh-pages # Branch where the static site will be published. |
| 32 | + PY_BUILD: 3.12.1 # Python version to be used for building the documentation. |
| 33 | + |
| 34 | +# We're using concurrency to ensure that only a single job or workflow |
| 35 | +# using the same concurrency group will run at a time. |
| 36 | +concurrency: |
| 37 | + group: ${{ github.ref }} # Groups by branch, so jobs in the same branch won't overlap. |
| 38 | + cancel-in-progress: true # Cancels any currently running jobs in the same group if a new one starts. |
| 39 | + |
| 40 | +# A workflow run is made up of one or more jobs, which run in parallel by default. |
| 41 | +# The ``ubuntu-latest`` label currently uses the Ubuntu 22.04 runner image. |
| 42 | +jobs: |
| 43 | + build: |
| 44 | + runs-on: ubuntu-latest # Runs the job on the latest available Ubuntu runner. |
| 45 | + steps: |
| 46 | + # Step 1: Check out the code from the repository to the runner. |
| 47 | + - name: Checkout TOPST SCHOOL Code (Dev) |
| 48 | + uses: actions/checkout@v4 # Checks out the repository code into the runner for the workflow to use. |
| 49 | + with: |
| 50 | + fetch-depth: 1 # Fetch only the latest commit for faster checkouts. |
| 51 | + |
| 52 | + # Step 2: Set up the specified Python version and cache pip dependencies for faster builds. |
| 53 | + - name: Set Up Python ${{ env.PY_BUILD }} |
| 54 | + uses: actions/setup-python@v5 |
| 55 | + with: |
| 56 | + python-version: ${{ env.PY_BUILD }} # Sets up the Python version specified in the environment variables. |
| 57 | + cache: 'pip' # Caches pip dependencies to speed up subsequent builds. |
| 58 | + |
| 59 | + # Step 3: Install the project's Python dependencies. |
| 60 | + - name: Install Python Dependencies |
| 61 | + run: | |
| 62 | + echo "Installing Coeus..." |
| 63 | + python -m pip install --upgrade pip |
| 64 | + pip install -U git+https://github.com/xames3/coeus-sphinx-theme.git#egg=coeus-sphinx-theme |
| 65 | +
|
| 66 | + # Step 4: Build the Sphinx documentation into HTML format. |
| 67 | + - name: Build Sphinx Documentation |
| 68 | + # -E: Rebuild all files, not just those that have changed. |
| 69 | + # -W: Treat warnings as errors. |
| 70 | + # -a: Write all output files (default only writes new and changed files). |
| 71 | + # -q: Run in quiet mode, with minimal output. |
| 72 | + run: | |
| 73 | + echo "Building Sphinx documentation..." |
| 74 | + sphinx-build -EWaq -b html ${{ env.SOURCE_DIR }} ${{ env.OUTPUT_DIR }} |
| 75 | +
|
| 76 | + # Step 5: Deploy the built HTML files to the specified branch (GitHub Pages). |
| 77 | + - name: DEV | Deploy to GitHub Pages |
| 78 | + uses: peaceiris/actions-gh-pages@v4 |
| 79 | + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} |
| 80 | + with: |
| 81 | + github_token: ${{ secrets.GITHUB_TOKEN }} # Deploys to the gh-pages branch. |
| 82 | + publish_branch: ${{ env.PUBLISH_BRANCH }} # Uses the GitHub token for authentication. |
| 83 | + publish_dir: ${{ env.OUTPUT_DIR }} # Directory to publish (the output of the Sphinx build). |
| 84 | + force_orphan: false # Do not force an orphan commit, preserving commit history. |
| 85 | + enable_jekyll: false # Disables Jekyll processing on GitHub Pages, which is unnecessary for Sphinx-generated HTML. |
| 86 | + user_email: "github-actions[bot]@users.noreply.github.com" # Email to associate with the commit. |
| 87 | + user_name: "github-actions[bot]" # Name to associate with the commit. |
| 88 | + full_commit_message: ${{ github.event.head_commit.message }} # Use the commit message from the push event. |
| 89 | + |
| 90 | + # Step 6: Provide response after deployment. |
| 91 | + - name: Notify Success |
| 92 | + if: success() |
| 93 | + run: echo "✅ Documentation successfully built and deployed to GitHub Pages (Dev)." |
| 94 | + - name: Notify Failure |
| 95 | + if: failure() |
| 96 | + run: echo "❌ Failed to build or deploy the documentation from the dev branch. Please check the logs." |
0 commit comments