updating existing PR #31
This file contains hidden or 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: Documentation | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| - release/* | ||
| - feature/* | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| jobs: | ||
| build: | ||
| if: github.repository_owner == 'MetOffice' && !contains(github.event.head_commit.message, '[skip ci]') | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| # SETUP | ||
| ############################ | ||
| - name: Checkout code | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 | ||
| with: | ||
| ref: ${{ github.ref_name }} # Ensure branch is checked out, not detached state (so we can push a commit later) | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| persist-credentials: true # Ensure that the token is available for pushing changes | ||
| - name: Set up Python | ||
| uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 | ||
| with: | ||
| python-version: 3.x | ||
| - name: Add checkout directory to PYTHONPATH | ||
| run: echo "PYTHONPATH=$(pwd):$PYTHONPATH" >> $GITHUB_ENV | ||
| - name: Install dependencies | ||
| id: install-dependencies | ||
| run: | | ||
| pip install .[tests,dev] | ||
| pip uninstall dagrunner -y | ||
| # DOCUMENTATION | ||
| ############################ | ||
| - name: Build documentation | ||
| run: | | ||
| rm -rf ./docs/_build | ||
| mkdir -p ./docs/_build | ||
| ./docs/gen_docs dagrunner ./docs/_build | ||
| git add -f docs/_build/ | ||
| - name: Check if documentation has changed | ||
| id: check-docs | ||
| run: | | ||
| echo "changed=$(git diff --cached --quiet --exit-code || echo true)" | tee -a $GITHUB_OUTPUT | ||
| - name: Create PR | ||
| if: steps.check-docs.outputs.changed == 'true' | ||
| run: | | ||
| git config user.name github-actions[bot] | ||
| git config user.email 41898282+github-actions[bot]@users.noreply.github.com | ||
| source_branch="${{ github.ref_name }}" | ||
| DOCS_BRANCH="docs-update/${source_branch//\//-}" | ||
| short_sha="${{ github.sha::8 }}" | ||
| git switch -c "$DOCS_BRANCH" | ||
| git commit -m "Automated reference documentation update for $short_sha [skip ci]" | ||
| git push origin "$DOCS_BRANCH" --force | ||
| # Create a PR only if one is not already open for this branch | ||
| if ! gh pr list --head "$DOCS_BRANCH" --json number --jq '.[0].number' | grep -q .; then | ||
| gh pr create \ | ||
| --title "Automated reference documentation update for $source_branch" \ | ||
| --body "This PR was automatically generated by the documentation workflow for commit $short_sha." \ | ||
| --base "$source_branch" \ | ||
| --head "$DOCS_BRANCH" \ | ||
| --label "documentation" \ | ||
| --assignee ${{ github.actor }} | ||
| else | ||
| # comment on PR to say that we have pushed a new commit to the branch | ||
| pr_number=$(gh pr list --head "$DOCS_BRANCH" --json number --jq '.[0].number') | ||
| gh pr comment "$pr_number" --body "New documentation changes have been pushed to this branch for commit $short_sha." | ||
| fi | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| # # https://github.com/orgs/community/discussions/26560#discussioncomment-3531273 | ||
| # # This must be our very final step to ensure that it runs only on condition of | ||
| # # success of all previous steps. A pushed commit will not trigger the re-running | ||
| # # of this workflow. | ||
| # - name: Commit and push documentation changes | ||
| # if: steps.check-docs.outputs.changed == 'true' | ||
| # run: | | ||
| # git config user.name github-actions[bot] | ||
| # git config user.email 41898282+github-actions[bot]@users.noreply.github.com | ||
| # git add docs/. | ||
| # git commit -am "Automated reference documentation update for PR ${{ github.event.number }} [skip ci]" | ||
| # git push | ||
| # env: | ||
| # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||