Skip to content

Commit e322699

Browse files
committed
Use PRs in docs workflow due to branch protection
1 parent 3bfaf7d commit e322699

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

.github/workflows/build-docs.yml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616

1717
permissions:
1818
contents: write
19+
pull-requests: write # Grant permissions to create and manage pull requests
1920

2021
steps:
2122
- name: Checkout Stochtree Monorepo
@@ -51,15 +52,42 @@ jobs:
5152
run: |
5253
cp -r python_docs/_build/html/* docs/python-documentation/
5354
54-
- name: Commit and Push Documentation
55+
- name: Commit and Push Documentation to New Branch
5556
run: |
5657
# Configure Git to use the GitHub actor for commits
5758
git config --global user.name "${{ github.actor }}"
5859
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
5960
61+
# Create a new branch for the documentation update
62+
git checkout -b update-python-docs
63+
6064
# Add the generated documentation, commit, and push
6165
git add docs/python-documentation
6266
git commit -m "Updated the Python documentation"
63-
git push
67+
git push -u origin update-python-docs
6468
env:
6569
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
70+
71+
- name: Create Pull Request Using GitHub CLI
72+
run: |
73+
gh pr create --title "Updated the Python documentation" --body "This PR updates the Python documentation." --base main --head update-python-docs
74+
env:
75+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76+
77+
- name: Enable Auto-Merge on the PR
78+
run: |
79+
# Get the pull request number and enable auto-merge
80+
PR_NUMBER=$(gh pr list --head update-python-docs --json number --jq '.[0].number')
81+
gh pr merge $PR_NUMBER --auto --merge
82+
env:
83+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84+
85+
- name: Delete Branch After Merge
86+
if: success() # Only delete if previous steps were successful
87+
run: |
88+
# Delete the branch after the PR has been merged
89+
gh api repos/:owner/:repo/git/refs/heads/update-python-docs -X DELETE
90+
env:
91+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
92+
owner: ${{ github.repository_owner }}
93+
repo: ${{ github.event.repository.name }}

0 commit comments

Comments
 (0)