Skip to content

Commit

Permalink
Addressing issue with merging the temp branch
Browse files Browse the repository at this point in the history
  • Loading branch information
silicontwin committed Sep 26, 2024
1 parent ed0cfb0 commit c2c8858
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions .github/workflows/generated-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ jobs:
runs-on: ubuntu-latest

permissions:
contents: write
pull-requests: write
contents: write # Grants permission to push to the repository
pull-requests: write # Grants permission to create and manage pull requests

env:
BRANCH_NAME: python-docs-temp-${{ github.run_id }}
Expand Down Expand Up @@ -60,6 +60,7 @@ jobs:
cp -r stochtree-repo/python_docs/_build/html/* docs/python-documentation/
- name: Commit and Push Documentation Changes
id: commit_and_push
run: |
# Configure Git
git config user.name "${{ github.actor }}"
Expand All @@ -73,30 +74,30 @@ jobs:
git commit -m "Updated the Python documentation"
# Push changes to new branch
git push origin $BRANCH_NAME
echo "::set-output name=changes::true"
else
echo "No changes to commit."
echo "::set-output name=changes::false"
fi
- name: Create Pull Request in Documentation Repo
if: ${{ steps.commit_and_push.outcome == 'success' }}
- name: Merge Temporary Branch into Main
if: steps.commit_and_push.outputs.changes == 'true'
run: |
gh pr create --title "Updated the Python documentation" --body "This PR updates the Python documentation." --base main --head $BRANCH_NAME
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Enable Auto-Merge on the PR
if: ${{ steps.commit_and_push.outcome == 'success' }}
run: |
PR_NUMBER=$(gh pr list --head $BRANCH_NAME --json number --jq '.[0].number')
gh pr merge $PR_NUMBER --auto --merge
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Configure Git
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
# Fetch the latest main
git fetch origin main
# Checkout main
git checkout main
# Merge the temporary branch
git merge --no-ff $BRANCH_NAME -m "Merge updated documentation"
# Push changes to main
git push origin main
- name: Delete Branch After Merge
if: ${{ steps.commit_and_push.outcome == 'success' }}
- name: Delete Temporary Branch
if: steps.commit_and_push.outputs.changes == 'true'
run: |
gh api repos/:owner/:repo/git/refs/heads/$BRANCH_NAME -X DELETE
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
owner: ${{ github.repository_owner }}
repo: ${{ github.event.repository.name }}
# Delete the temporary branch locally and remotely
git branch -D $BRANCH_NAME
git push origin --delete $BRANCH_NAME

0 comments on commit c2c8858

Please sign in to comment.