run publish workflow after successful sync
authorxangelo <me@xangelo.ca>
Mon, 21 Jul 2025 19:16:20 +0000 (15:16 -0400)
committerxangelo <me@xangelo.ca>
Mon, 21 Jul 2025 19:19:37 +0000 (15:19 -0400)
.github/workflows/medium-sync.yml

index 7a7d966aaec47abd28af7fb1b9440f949bf15d3a..07ad8308363a3fdb3f12f90e59e2ea46f8395784 100644 (file)
@@ -8,6 +8,8 @@ on:
 jobs:
   sync:
     runs-on: ubuntu-latest
+    outputs:
+      changed_files: ${{ steps.commit.outputs.changed_files }}
     steps:
       - name: Checkout repo
         uses: actions/checkout@v4
@@ -24,9 +26,28 @@ jobs:
         run: python .github/scripts/medium_to_hugo.py
 
       - name: Commit and push changes
+        id: commit
         run: |
           git config user.name "Medium Sync Bot"
           git config user.email "actions@github.com"
           git add content/posts/
-          git diff --quiet && git diff --staged --quiet || git commit -m "Sync new Medium posts"
-          git push
+
+          # Check if there are any changes to commit
+          if git diff --quiet && git diff --staged --quiet; then
+            echo "No changes to commit"
+            echo "changed_files=0" >> $GITHUB_OUTPUT
+          else
+            # Count the number of changed files
+            changed_count=$(git diff --name-only --diff-filter=ACMR HEAD | wc -l)
+            git commit -m "Sync new Medium posts"
+            git push
+            echo "changed_files=$changed_count" >> $GITHUB_OUTPUT
+          fi
+
+  publish:
+    runs-on: ubuntu-latest
+    needs: sync
+    if: needs.sync.outputs.changed_files > 0
+    steps:
+      - name: Run hugo workflow
+        uses: ./.github/workflows/hugo.yml