From 7a7b92091009062bace189b7a09ad50b8332e29b Mon Sep 17 00:00:00 2001 From: ashley <90108886+ashmchiu@users.noreply.github.com> Date: Sat, 7 Sep 2024 14:16:05 -0700 Subject: [PATCH] [fix] github action opens PR instead of merging into main (#86) * [fix] github action opens PR instead of merging into main * prevent new PR being made after mergining in the new version of the textbook --- .github/workflows/generate-pdf.yml | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/.github/workflows/generate-pdf.yml b/.github/workflows/generate-pdf.yml index 240e501..c73cba5 100644 --- a/.github/workflows/generate-pdf.yml +++ b/.github/workflows/generate-pdf.yml @@ -140,13 +140,25 @@ jobs: name: textbook-full path: textbook_full.pdf - - name: Commit and push changes only on push - if: github.event_name == 'push' + - name: Commit changes to a new branch + if: github.event_name == 'push' && !contains(github.event.head_commit.message, 'Update PDF of textbook') run: | git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "GitHub Actions" + git checkout -b update-textbook-full-pdf-$(date +%s) git add textbook_full.pdf - git commit -m "Update full PDF of textbook on site" - git push + git commit -m "Update PDF of textbook on site after a merge to main" + git push origin HEAD env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Create a Pull Request + if: github.event_name == 'push' && !contains(github.event.head_commit.message, 'Update PDF of textbook') + uses: peter-evans/create-pull-request@v5 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: "Update PDF of textbook on site" + branch: update-textbook-full-pdf-$(date +%s) + title: "Update full PDF of textbook" + body: "This PR updates the full PDF of the textbook." + base: main