From e754682dffd6e47c1c9c0ce4a5957772f1ecdd37 Mon Sep 17 00:00:00 2001
From: Stefan Agner <stefan@agner.ch>
Date: Fri, 26 Apr 2024 10:24:52 +0200
Subject: [PATCH 1/4] Add workflow to bump Matter SDK dependency

---
 .github/workflows/dependency-update.yaml | 58 ++++++++++++++++++++++++
 .gitmodules                              |  1 +
 2 files changed, 59 insertions(+)
 create mode 100644 .github/workflows/dependency-update.yaml

diff --git a/.github/workflows/dependency-update.yaml b/.github/workflows/dependency-update.yaml
new file mode 100644
index 0000000..d01a683
--- /dev/null
+++ b/.github/workflows/dependency-update.yaml
@@ -0,0 +1,58 @@
+name: Update Matter SDK submodule
+
+on:
+  schedule:
+    # Runs at 04:30 UTC every day
+    - cron: '30 04 * * *'
+  workflow_dispatch:
+
+permissions:
+  contents: write
+  pull-requests: write
+
+jobs:
+  update-connectedhomeip-submodule:
+    runs-on: ubuntu-latest
+    name: Update Matter SDK submodule
+
+    steps:
+      # Checkout the repository
+      - name: Checkout Repository
+        uses: actions/checkout@v4
+        with:
+          submodules: false
+
+      # Update submodule (not recursive)
+      - name: Update Submodule
+        id: update-submodule
+        run: |
+          git submodule update --init connectedhomeip/
+          short_hash_before=$(cd connectedhomeip && git rev-parse --short HEAD)
+          echo "short_hash_before=${short_hash_before}" >> $GITHUB_OUTPUT
+          git submodule update --remote connectedhomeip/
+          git add connectedhomeip/
+          if git diff-index --quiet HEAD; then
+              echo "empty=true" >> $GITHUB_OUTPUT
+              exit 0
+          fi
+          short_hash=$(cd connectedhomeip && git rev-parse --short HEAD)
+          echo "short_hash=${short_hash}" >> $GITHUB_OUTPUT
+
+      # Create Pull Request only if there were changes
+      - name: Create Pull Request
+        if: ${{ steps.update-submodule.outputs.empty != true }}
+        uses: peter-evans/create-pull-request@v6
+        with:
+          commit-message: Update Matter SDK to `${{steps.update-submodule.outputs.short_hash}}`
+          title: Update Matter SDK to `${{steps.update-submodule.outputs.short_hash}}`
+          body: >
+            Bumps [connectedhomeip](https://github.com/project-chip/connectedhomeip)
+            from `${{ steps.update-submodule.outputs.short_hash_before }}` to
+            `${{ steps.update-submodule.outputs.short_hash }}`.
+
+
+            See full diff at
+            https://github.com/project-chip/connectedhomeip/compare/${{ steps.update-submodule.outputs.short_hash_before }}...${{ steps.update-submodule.outputs.short_hash }}.
+          branch: update-connectedhomeip-submodule-to-${{ steps.update-submodule.outputs.short_hash }}
+          delete-branch: true
+
diff --git a/.gitmodules b/.gitmodules
index c51b07a..eab72d6 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -3,3 +3,4 @@
 	url = https://github.com/project-chip/connectedhomeip.git
 	branch = master
 	fetchRecurseSubmodules = false
+	depth = 1

From e9fbfe3e43dafd333c76bd6560143efecda2cff1 Mon Sep 17 00:00:00 2001
From: Stefan Agner <stefan@agner.ch>
Date: Fri, 26 Apr 2024 11:13:56 +0200
Subject: [PATCH 2/4] Make Dependabot to ignore connectedhomeip

It seems Dependabot can't handle submodules with recursive submodules
well: It fetches them recursively and ultimately runs out of space.

See also: https://github.com/dependabot/dependabot-core/issues/9376
---
 .github/dependabot.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index dcc2e6b..9e0ad98 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -2,7 +2,7 @@ version: 2
 updates:
   - package-ecosystem: "gitsubmodule"
     directory: "/"
-    allow:
+    ignore:
       - dependency-name: "connectedhomeip"
     schedule:
       interval: "daily"

From a925a373715ba4deaf7d68ba47dd87ff9600ed5f Mon Sep 17 00:00:00 2001
From: Stefan Agner <stefan@agner.ch>
Date: Fri, 26 Apr 2024 14:29:33 +0200
Subject: [PATCH 3/4] Apply suggestions from code review
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: Jan Čermák <sairon@users.noreply.github.com>
---
 .github/workflows/dependency-update.yaml | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/.github/workflows/dependency-update.yaml b/.github/workflows/dependency-update.yaml
index d01a683..cfcb50b 100644
--- a/.github/workflows/dependency-update.yaml
+++ b/.github/workflows/dependency-update.yaml
@@ -40,11 +40,11 @@ jobs:
 
       # Create Pull Request only if there were changes
       - name: Create Pull Request
-        if: ${{ steps.update-submodule.outputs.empty != true }}
+        if: ${{ steps.update-submodule.outputs.empty != "true" }}
         uses: peter-evans/create-pull-request@v6
         with:
-          commit-message: Update Matter SDK to `${{steps.update-submodule.outputs.short_hash}}`
-          title: Update Matter SDK to `${{steps.update-submodule.outputs.short_hash}}`
+          commit-message: Update Matter SDK to `${{ steps.update-submodule.outputs.short_hash }}`
+          title: Update Matter SDK to `${{ steps.update-submodule.outputs.short_hash }}`
           body: >
             Bumps [connectedhomeip](https://github.com/project-chip/connectedhomeip)
             from `${{ steps.update-submodule.outputs.short_hash_before }}` to

From aec52d9eb31618403f48954ca222f7b859e5c1fd Mon Sep 17 00:00:00 2001
From: Stefan Agner <stefan@agner.ch>
Date: Fri, 26 Apr 2024 14:30:12 +0200
Subject: [PATCH 4/4] Apply suggestions from code review

---
 .github/workflows/dependency-update.yaml | 1 -
 1 file changed, 1 deletion(-)

diff --git a/.github/workflows/dependency-update.yaml b/.github/workflows/dependency-update.yaml
index cfcb50b..32bfe22 100644
--- a/.github/workflows/dependency-update.yaml
+++ b/.github/workflows/dependency-update.yaml
@@ -54,5 +54,4 @@ jobs:
             See full diff at
             https://github.com/project-chip/connectedhomeip/compare/${{ steps.update-submodule.outputs.short_hash_before }}...${{ steps.update-submodule.outputs.short_hash }}.
           branch: update-connectedhomeip-submodule-to-${{ steps.update-submodule.outputs.short_hash }}
-          delete-branch: true