From b64284d6846da62e1ad78146c4fcb6e7ff0eb80c Mon Sep 17 00:00:00 2001
From: fabianegli <fabian.egli@protonmail.ch>
Date: Tue, 26 Nov 2024 09:41:46 +0100
Subject: [PATCH] restore correct attribution logic to before PR #55

---
 .github/workflows/ai_robots_update.yml | 16 ++++-------
 .github/workflows/main.yml             | 38 ++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 10 deletions(-)
 create mode 100644 .github/workflows/main.yml

diff --git a/.github/workflows/ai_robots_update.yml b/.github/workflows/ai_robots_update.yml
index b346e10..654b0b5 100644
--- a/.github/workflows/ai_robots_update.yml
+++ b/.github/workflows/ai_robots_update.yml
@@ -1,8 +1,5 @@
 name: Updates for AI robots files
 on:
-  push:
-    branches:
-    - "main"
   schedule:
     - cron: "0 0 * * *"
 
@@ -24,11 +21,10 @@ jobs:
           git --no-pager diff
           git add -A
           git diff --quiet && git diff --staged --quiet || (git commit -m "Update from Dark Visitors" && git push)
-          
-          echo "Updating robots.txt and table-of-bot-metrics.md if necessary ..."
-          python code/dark_visitors.py --convert
-          echo "... done."
-          git --no-pager diff
-          git add -A
-          git diff --quiet && git diff --staged --quiet || (git commit -m "Updated from new robots.json" && git push)
         shell: bash
+  call-main:
+    needs: dark-visitors
+    uses: ./.github/workflows/main.yml
+    secrets: inherit
+    with:
+      message: "Update from Dark Visitors"
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
new file mode 100644
index 0000000..a4c47d6
--- /dev/null
+++ b/.github/workflows/main.yml
@@ -0,0 +1,38 @@
+on:
+  workflow_call:
+    inputs:
+      message:
+        type: string
+        required: true
+        description: The message to commit
+  push:
+    paths:
+      - 'robots.json'
+    branches:
+      - "main"
+
+jobs:
+  ai-robots-txt:
+    runs-on: ubuntu-latest
+    name: ai-robots-txt
+    steps:
+      - uses: actions/checkout@v4
+        with:
+          fetch-depth: 2
+      - run: |
+          git config --global user.name "ai.robots.txt"
+          git config --global user.email "ai.robots.txt@users.noreply.github.com"
+          git log -1
+          git status
+          echo "Updating robots.txt and table-of-bot-metrics.md if necessary ..."
+          python code/dark_visitors.py --convert
+          echo "... done."
+          git --no-pager diff
+          git add -A
+          if [ -n "${{ inputs.message }}" ]; then
+            git commit -m "${{ inputs.message }}"
+          else
+            git commit -m "${{ github.event.head_commit.message }}"
+          fi
+          git push
+        shell: bash