From 4f68eb95ff16c765ab224aa4c5f5256af2c70d7f Mon Sep 17 00:00:00 2001
From: Emanuel Palm <emanuel+github@pipe.how>
Date: Fri, 5 Jan 2024 18:10:37 +0100
Subject: [PATCH] create and merge pr as github action

---
 .github/workflows/PublishReleaseAndModule.yml | 29 ++++++++++++++++---
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/PublishReleaseAndModule.yml b/.github/workflows/PublishReleaseAndModule.yml
index e65a2b3..9d2c7de 100644
--- a/.github/workflows/PublishReleaseAndModule.yml
+++ b/.github/workflows/PublishReleaseAndModule.yml
@@ -9,6 +9,9 @@ on:
 
 jobs:
   release:
+    permissions:
+      contents: write
+      pull-requests: write
     runs-on: ubuntu-latest
 
     steps:
@@ -38,9 +41,27 @@ jobs:
 
     - name: Push changelog
       run: |
-        git config --global user.name "$(git --no-pager log --format=format:'%an' -n 1)"
-        git config --global user.email "$(git --no-pager log --format=format:'%ae' -n 1)"
+        # Configure git with github-actions bot to make commits more pretty
+        git config user.name "github-actions[bot]"
+        git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
 
         git add CHANGELOG.md
-        git commit -m "docs: Update changelog for ${{ github.ref_name }}"
-        git push origin main
\ No newline at end of file
+        git commit -m "docs: update changelog for ${{ github.ref_name }}"
+        git push
+
+    - name: Create Pull Request
+      id: create-pull-request
+      uses: peter-evans/create-pull-request@v5
+      with:
+        token: ${{ secrets.GITHUB_TOKEN }}
+        commit-message: "docs: update changelog for ${{ github.ref_name }}"
+        title: Update changelog for ${{ github.ref_name }}
+        body: Automatic update of changelog for release ${{ github.ref_name }}.
+        branch: changelog/${{ github.ref_name }}
+        labels: documentation
+    
+    - name: Merge Pull Request
+      uses: juliangruber/merge-pull-request-action@v1
+      with:
+        github-token: ${{ secrets.GITHUB_TOKEN }}
+        number: ${{ steps.create-pull-request.outputs.pull-request-number }}
\ No newline at end of file