From b7a1b50c32b043f4d61c3540185dd4e1c01eb910 Mon Sep 17 00:00:00 2001 From: moritzlaurer Date: Tue, 29 Oct 2024 17:59:24 +0100 Subject: [PATCH] chore: make docs only redeploy if relevant files were changed --- .github/workflows/docs.yml | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 7d60fb1..643add4 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -3,10 +3,52 @@ on: push: branches: - main + paths: + - 'docs/**' # Documentation content + - 'mkdocs.yml' # MkDocs configuration + - '.github/workflows/docs.yml' # This workflow file + - 'pyproject.toml' # For doc dependencies + # Add any Python files that generate docs + - 'hf_hub_prompts/**/*.py' # Source files (for docstrings) + + # Optional: Allow manual triggers + workflow_dispatch: + permissions: contents: write + jobs: + check_changes: + runs-on: ubuntu-latest + outputs: + should_deploy: ${{ steps.check.outputs.should_deploy }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Fetch all history for checking changes + + - name: Check for documentation changes + id: check + run: | + # Check if this is a manual trigger + if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then + echo "should_deploy=true" >> $GITHUB_OUTPUT + exit 0 + fi + + # Check for changes in relevant files + git diff --name-only ${{ github.event.before }} ${{ github.event.after }} > changed_files.txt + + # Look for changes in docs, mkdocs.yml, or Python files + if grep -q -E '^docs/|^mkdocs.yml|\.py$' changed_files.txt; then + echo "should_deploy=true" >> $GITHUB_OUTPUT + else + echo "should_deploy=false" >> $GITHUB_OUTPUT + fi + deploy: + needs: check_changes + if: needs.check_changes.outputs.should_deploy == 'true' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4